Skip to content

Commit fcbc4f5

Browse files
committed
Added text clipping function for tk::Label
1 parent 12b6001 commit fcbc4f5

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*******************************************************************************
44

55
=== 1.0.29 ===
6+
* Added text clipping function for tk::Label.
67
* Implemented AudioEnvelope widget and it's integration into AudioSample.
78
* Implemented ws::IDisplay::get_file_descriptor method for obtaining event loop
89
descriptor for Unix-based systems that use X11 protocol

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace lsp
5858
prop::Font sFont; // Font parameters
5959
prop::Boolean sHover; // Hover enable
6060
prop::String sText; // Text to display
61+
prop::Boolean sTextClip; // Clip text
6162
prop::SizeConstraints sConstraints; // Size constraints
6263
prop::Padding sIPadding; // Internal padding
6364
LSP_TK_STYLE_DEF_END
@@ -108,6 +109,7 @@ namespace lsp
108109
prop::Font sFont; // Font parameters
109110
prop::Boolean sHover; // Hover enable
110111
prop::String sText; // Text to display
112+
prop::Boolean sTextClip; // Clip text
111113
prop::SizeConstraints sConstraints; // Size constraints
112114
prop::Padding sIPadding; // Internal padding
113115
prop::WidgetPtr<Menu> sPopup; // Popup menu
@@ -153,6 +155,7 @@ namespace lsp
153155
LSP_TK_PROPERTY(Color, inactive_hover_color, &vColors[LBL_3].sColor)
154156
LSP_TK_PROPERTY(Boolean, hover, &sHover)
155157
LSP_TK_PROPERTY(String, text, &sText)
158+
LSP_TK_PROPERTY(Boolean, text_clip, &sTextClip)
156159
LSP_TK_PROPERTY(SizeConstraints, constraints, &sConstraints)
157160
LSP_TK_PROPERTY(Padding, ipadding, &sIPadding)
158161
LSP_TK_PROPERTY(WidgetPtr<Menu>, popup, &sPopup)

src/main/widgets/simple/Label.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace lsp
5050

5151
sTextLayout.bind("text.layout", this);
5252
sTextAdjust.bind("text.adjust", this);
53+
sTextClip.bind("text.clip", this);
5354
sFont.bind("font", this);
5455
sHover.bind("text.hover", this);
5556
sConstraints.bind("size.constraints", this);
@@ -70,6 +71,7 @@ namespace lsp
7071

7172
sTextLayout.set(0.0f, 0.0f);
7273
sTextAdjust.set(TA_NONE);
74+
sTextClip.set(false);
7375
sFont.set_size(12.0f);
7476
sHover.set(false);
7577
sConstraints.set(-1, -1, -1, -1);
@@ -97,6 +99,7 @@ namespace lsp
9799
sFont(&sProperties),
98100
sHover(&sProperties),
99101
sText(&sProperties),
102+
sTextClip(&sProperties),
100103
sConstraints(&sProperties),
101104
sPopup(&sProperties)
102105
{
@@ -135,6 +138,7 @@ namespace lsp
135138
sFont.bind("font", &sStyle);
136139
sHover.bind("text.hover", &sStyle);
137140
sText.bind(&sStyle, pDisplay->dictionary());
141+
sTextClip.bind("text.clip", &sStyle);
138142
sConstraints.bind("size.constraints", &sStyle);
139143
sIPadding.bind("ipadding", &sStyle);
140144
sPopup.bind(NULL);
@@ -159,7 +163,7 @@ namespace lsp
159163
if (prop->one_of(sTextLayout, sHover))
160164
query_draw();
161165

162-
if (prop->one_of(sTextAdjust, sFont, sText, sConstraints, sIPadding))
166+
if (prop->one_of(sTextAdjust, sTextClip, sFont, sText, sConstraints, sIPadding))
163167
query_resize();
164168
}
165169

@@ -181,6 +185,22 @@ namespace lsp
181185
sFont.get_multitext_parameters(s, &tp, fscaling, &text);
182186
sIPadding.sub(&size, &sSize, scaling);
183187

188+
// Apply text clipping
189+
const bool clip = sTextClip.get();
190+
if (clip)
191+
{
192+
r.nLeft = 0;
193+
r.nTop = 0;
194+
r.nWidth = sSize.nWidth;
195+
r.nHeight = sSize.nHeight;
196+
sIPadding.enter(&r, scaling);
197+
s->clip_begin(&r);
198+
}
199+
lsp_finally {
200+
if (clip)
201+
s->clip_end();
202+
};
203+
184204
// Estimate drawing area
185205
tp.Height = lsp_max(tp.Height, fp.Height);
186206
if (tp.Width <= size.nWidth)
@@ -347,10 +367,15 @@ namespace lsp
347367
e.r = r;
348368
sFont.get_parameters(pDisplay, e.fscaling, &e.fp);
349369

350-
// Estimate the size of the label
351-
for (lltl::iterator<prop::String> it = vEstimations.values(); it; ++it)
352-
estimate_string_size(&e, it.get());
353-
estimate_string_size(&e, &sText);
370+
if (!sTextClip.get())
371+
{
372+
// Estimate the size of the label
373+
for (lltl::iterator<prop::String> it = vEstimations.values(); it; ++it)
374+
estimate_string_size(&e, it.get());
375+
estimate_string_size(&e, &sText);
376+
}
377+
else
378+
r->nMinHeight = e.fp.Height;
354379

355380
// Apply size constraints
356381
sConstraints.apply(r, e.scaling);

0 commit comments

Comments
 (0)