Skip to content

Commit e9e9a46

Browse files
committed
Added text alignment for clipping case
1 parent 7cfd617 commit e9e9a46

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/lsp-plug.in/tk/widgets/simple/Label.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace lsp
5454
LabelColors vColors[LABEL_TOTAL];
5555

5656
prop::TextLayout sTextLayout; // Text layout
57+
prop::TextLayout sClipTextLayout;// Text layout when clipping
5758
prop::TextAdjust sTextAdjust; // Text adjustment
5859
prop::Font sFont; // Font parameters
5960
prop::Boolean sHover; // Hover enable
@@ -105,6 +106,7 @@ namespace lsp
105106

106107
style::LabelColors vColors[style::LABEL_TOTAL];
107108
prop::TextLayout sTextLayout; // Text layout
109+
prop::TextLayout sClipTextLayout;// Text layout when clipping
108110
prop::TextAdjust sTextAdjust; // Text adjustment
109111
prop::Font sFont; // Font parameters
110112
prop::Boolean sHover; // Hover enable
@@ -147,6 +149,7 @@ namespace lsp
147149

148150
public:
149151
LSP_TK_PROPERTY(TextLayout, text_layout, &sTextLayout)
152+
LSP_TK_PROPERTY(TextLayout, clip_text_layout, &sClipTextLayout)
150153
LSP_TK_PROPERTY(TextAdjust, text_adjust, &sTextAdjust)
151154
LSP_TK_PROPERTY(Font, font, &sFont)
152155
LSP_TK_PROPERTY(Color, color, &vColors[LBL_0].sColor)

src/main/widgets/simple/Label.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace lsp
4949
c->sColor.bind("inactive.text.hover.color", this);
5050

5151
sTextLayout.bind("text.layout", this);
52+
sClipTextLayout.bind("text.clip.layout", this);
5253
sTextAdjust.bind("text.adjust", this);
5354
sTextClip.bind("text.clip", this);
5455
sFont.bind("font", this);
@@ -70,6 +71,7 @@ namespace lsp
7071
c->sColor.set_rgb24(0xcc0000);
7172

7273
sTextLayout.set(0.0f, 0.0f);
74+
sClipTextLayout.set(0.0f, 0.0f);
7375
sTextAdjust.set(TA_NONE);
7476
sTextClip.set(false);
7577
sFont.set_size(12.0f);
@@ -95,6 +97,7 @@ namespace lsp
9597
Label::Label(Display *dpy):
9698
Widget(dpy),
9799
sTextLayout(&sProperties),
100+
sClipTextLayout(&sProperties),
98101
sTextAdjust(&sProperties),
99102
sFont(&sProperties),
100103
sHover(&sProperties),
@@ -134,6 +137,7 @@ namespace lsp
134137
c->sColor.bind("inactive.text.hover.color", &sStyle);
135138

136139
sTextLayout.bind("text.layout", &sStyle);
140+
sClipTextLayout.bind("text.clip.layout", &sStyle);
137141
sTextAdjust.bind("text.adjust", &sStyle);
138142
sFont.bind("font", &sStyle);
139143
sHover.bind("text.hover", &sStyle);
@@ -160,7 +164,7 @@ namespace lsp
160164
if (colors->property_changed(prop))
161165
query_draw();
162166

163-
if (prop->one_of(sTextLayout, sHover))
167+
if (prop->one_of(sTextLayout, sClipTextLayout, sHover))
164168
query_draw();
165169

166170
if (prop->one_of(sTextAdjust, sTextClip, sFont, sText, sConstraints, sIPadding))
@@ -239,9 +243,12 @@ namespace lsp
239243
// Draw background
240244
s->clear(bg_color);
241245

246+
const bool exceeds = (tp.Width > r.nWidth) || (tp.Height > r.nHeight);
247+
const TextLayout *layout = (exceeds) ? &sClipTextLayout : &sTextLayout;
248+
242249
draw_multiline_text(s,
243250
&sFont, &r, f_color, &fp, &tp,
244-
sTextLayout.halign(), sTextLayout.valign(),
251+
layout->halign(), layout->valign(),
245252
fscaling, &text);
246253
}
247254

0 commit comments

Comments
 (0)