Skip to content

Commit 570a08f

Browse files
committed
Simplified hyperlink rendering code
1 parent 50bd731 commit 570a08f

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

src/main/widgets/simple/Hyperlink.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include <lsp-plug.in/tk/tk.h>
23+
#include <lsp-plug.in/tk/helpers/draw.h>
2324
#include <lsp-plug.in/common/debug.h>
2425
#include <lsp-plug.in/stdlib/math.h>
2526
#include <lsp-plug.in/ipc/Process.h>
@@ -288,39 +289,10 @@ namespace lsp
288289
// Draw background
289290
s->clear(bg_color);
290291

291-
float halign = lsp_limit(sTextLayout.halign() + 1.0f, 0.0f, 2.0f);
292-
float valign = lsp_limit(sTextLayout.valign() + 1.0f, 0.0f, 2.0f);
293-
float dy = (r.nHeight - tp.Height) * 0.5f;
294-
ssize_t y = r.nTop + dy * valign - fp.Descent;
295-
296-
// Estimate text size
297-
ssize_t last = 0, curr = 0, tail = 0, len = text.length();
298-
299-
while (curr < len)
300-
{
301-
// Get next line indexes
302-
curr = text.index_of(last, '\n');
303-
if (curr < 0)
304-
{
305-
curr = len;
306-
tail = len;
307-
}
308-
else
309-
{
310-
tail = curr;
311-
if ((tail > last) && (text.at(tail-1) == '\r'))
312-
--tail;
313-
}
314-
315-
// Calculate text location
316-
sFont.get_text_parameters(s, &tp, fscaling, &text, last, tail);
317-
float dx = (r.nWidth - tp.Width) * 0.5f;
318-
ssize_t x = r.nLeft + dx * halign - tp.XBearing;
319-
y += fp.Height;
320-
321-
sFont.draw(s, f_color, x, y, fscaling, &text, last, tail);
322-
last = curr + 1;
323-
}
292+
draw_multiline_text(s,
293+
&sFont, &r, f_color, &fp, &tp,
294+
sTextLayout.halign(), sTextLayout.valign(),
295+
fscaling, &text);
324296
}
325297

326298
status_t Hyperlink::create_default_menu()

0 commit comments

Comments
 (0)