Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>Modules</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2023-05-01 20:49:18 </i>
<i style="float:right;">Last updated 2023-05-03 21:59:22 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
41 changes: 40 additions & 1 deletion docs/modules/widget_text.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h1>polycore</h1>
<h2>Contents</h2>
<ul>
<li><a href="#Class_Text">Class Text </a></li>
<li><a href="#Class_ConkyText">Class ConkyText </a></li>
<li><a href="#Class_StaticText">Class StaticText </a></li>
<li><a href="#Class_TextLine">Class TextLine </a></li>
</ul>
Expand Down Expand Up @@ -70,6 +71,13 @@ <h2><a href="#Class_Text">Class Text </a></h2>
<td class="summary"></td>
</tr>
</table>
<h2><a href="#Class_ConkyText">Class ConkyText </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#ConkyText:init">ConkyText:init(args)</a></td>
<td class="summary"></td>
</tr>
</table>
<h2><a href="#Class_StaticText">Class StaticText </a></h2>
<table class="function_list">
<tr>
Expand Down Expand Up @@ -146,6 +154,37 @@ <h3>Parameters:</h3>



</dd>
</dl>
<h2 class="section-header has-description"><a name="Class_ConkyText"></a>Class ConkyText </h2>

<div class="section-description">
Draw text substuting in Conky variables.
Text line will be updated on each cycle as per Conky's text
Section, some variables such as formatting and positioning
may not be honored.
</div>
<dl class="function">
<dt>
<a name = "ConkyText:init"></a>
<strong>ConkyText:init(args)</strong>
</dt>
<dd>



<h3>Parameters:</h3>
<ul>
<li><span class="parameter">args</span>
<span class="types"><span class="type">table</span></span>
table of options, see <a href="../modules/widget_text.html#Text:init">Text:init</a>
</li>
</ul>





</dd>
</dl>
<h2 class="section-header has-description"><a name="Class_StaticText"></a>Class StaticText </h2>
Expand Down Expand Up @@ -237,7 +276,7 @@ <h3>Parameters:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2023-05-01 20:49:18 </i>
<i style="float:right;">Last updated 2023-05-03 21:59:22 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
29 changes: 29 additions & 0 deletions src/widgets/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ function Text:layout(width)
end
end

--- Draw text substuting in Conky variables.
-- Text line will be updated on each cycle as per Conky's text
-- Section, some variables such as formatting and positioning
-- may not be honored.
-- @type ConkyText
local ConkyText = util.class(Text)
w.ConkyText = ConkyText

--- @string text Text to be displayed, can include conky variables.
--- @tparam table args table of options, see `Text:init`
function ConkyText:init(text, args)
Text.init(self, args)

self._lines = {}
local _, line_count = text:gsub("[^\n]*", function(line)
table.insert(self._lines, line)
end)
self.height = line_count * self._line_height
end

function ConkyText:render(cr)
ch.set_font(cr, self._font_family, self._font_size, self._font_slant,
self._font_weight)
cairo_set_source_rgba(cr, unpack(self._color))
for i, line in ipairs(self._lines) do
local y = self._baseline_offset + (i - 1) * self._line_height
self._write_fn(cr, self._x, y, conky_parse(line))

@philer philer May 6, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A while ago conky_parse was very slow, see this issue. I don't know if that has since been fixed or if it is still relevant. At the time I implemented the eager loader in data.lua to centralize retrieving data from conky_parse.

Have you tried using this in an example with many instances? It would be interesting to observe if there is any slowdown/lag compared to plain conky text.

Edit: Maybe renaming this widget to ConkyParse would make it more obvious what it does?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like that issue has been marked as resolved, so far i've really only played with a CPU Top example, which is using 10 calls which seemed fine performance wise, I can make that name change tomorrow.

end
end

--- Draw some unchangeable text.
-- Use this widget for text that will never be updated.Text
Expand Down