1
1
/*
2
- * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3
- * (C) 2023 Vladimir Sadovnikov <[email protected] >
2
+ * Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
3
+ * (C) 2024 Vladimir Sadovnikov <[email protected] >
4
4
*
5
5
* This file is part of lsp-tk-lib
6
6
* Created on: 6 июл. 2017 г.
19
19
* along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
20
20
*/
21
21
22
- #include < lsp-plug.in/tk/tk .h>
22
+ #include < lsp-plug.in/common/debug .h>
23
23
#include < lsp-plug.in/stdlib/math.h>
24
+ #include < lsp-plug.in/stdlib/stdio.h>
25
+ #include < lsp-plug.in/tk/tk.h>
26
+
24
27
#include < private/tk/style/BuiltinStyle.h>
25
- #include < lsp-plug.in/common/debug.h>
26
28
27
29
namespace lsp
28
30
{
@@ -77,6 +79,7 @@ namespace lsp
77
79
Label::~Label ()
78
80
{
79
81
nFlags |= FINALIZED;
82
+ clear_text_estimations ();
80
83
}
81
84
82
85
status_t Label::init ()
@@ -216,6 +219,53 @@ namespace lsp
216
219
}
217
220
}
218
221
222
+ void Label::clear_text_estimations ()
223
+ {
224
+ size_t removed = 0 ;
225
+ for (lltl::iterator<prop::String> it = vEstimations.values (); it; ++it)
226
+ {
227
+ prop::String *s = it.get ();
228
+ if (s != NULL )
229
+ {
230
+ ++removed;
231
+ delete s;
232
+ }
233
+ }
234
+ vEstimations.clear ();
235
+ if (removed > 0 )
236
+ query_resize ();
237
+ }
238
+
239
+ tk::String *Label::add_text_estimation ()
240
+ {
241
+ prop::String *s = new prop::String (&sProperties );
242
+ if (s == NULL )
243
+ return NULL ;
244
+ s->bind (&sStyle , pDisplay->dictionary ());
245
+
246
+ if (vEstimations.add (s))
247
+ return s;
248
+
249
+ delete s;
250
+ return NULL ;
251
+ }
252
+
253
+ void Label::estimate_string_size (estimation_t *e, tk::String *s)
254
+ {
255
+ if (s == NULL )
256
+ return ;
257
+
258
+ // Form the text string
259
+ s->format (&e->text );
260
+ sTextAdjust .apply (&e->text );
261
+
262
+ // Estimate sizes
263
+ sFont .get_multitext_parameters (pDisplay, &e->tp , e->fscaling , &e->text );
264
+
265
+ e->r ->nMinWidth = lsp_max (e->r ->nMinWidth , ceilf (e->tp .Width ));
266
+ e->r ->nMinHeight = lsp_max (e->r ->nMinHeight , ceilf (lsp_max (e->tp .Height , e->fp .Height )));
267
+ }
268
+
219
269
void Label::size_request (ws::size_limit_t *r)
220
270
{
221
271
r->nMinWidth = 0 ;
@@ -225,26 +275,21 @@ namespace lsp
225
275
r->nPreWidth = -1 ;
226
276
r->nPreHeight = -1 ;
227
277
228
- // Form the text string
229
- LSPString text;
230
- sText .format (&text);
231
- sTextAdjust .apply (&text);
232
-
233
- // Estimate sizes
234
- float scaling = lsp_max (0 .0f , sScaling .get ());
235
- float fscaling = lsp_max (0 .0f , scaling * sFontScaling .get ());
236
- ws::font_parameters_t fp;
237
- ws::text_parameters_t tp;
238
-
239
- sFont .get_parameters (pDisplay, fscaling, &fp);
240
- sFont .get_multitext_parameters (pDisplay, &tp, fscaling, &text);
241
-
242
- r->nMinWidth = ceil (tp.Width );
243
- r->nMinHeight = ceil (lsp_max (tp.Height , fp.Height ));
244
-
278
+ // Form the estimation parameters
279
+ estimation_t e;
280
+ e.scaling = lsp_max (0 .0f , sScaling .get ());
281
+ e.fscaling = lsp_max (0 .0f , e.scaling * sFontScaling .get ());
282
+ e.r = r;
283
+ sFont .get_parameters (pDisplay, e.fscaling , &e.fp );
284
+
285
+ // Estimate the size of the label
286
+ for (lltl::iterator<prop::String> it = vEstimations.values (); it; ++it)
287
+ estimate_string_size (&e, it.get ());
288
+ estimate_string_size (&e, &sText );
289
+
245
290
// Apply size constraints
246
- sConstraints .apply (r, scaling);
247
- sIPadding .add (r, scaling);
291
+ sConstraints .apply (r, e. scaling );
292
+ sIPadding .add (r, e. scaling );
248
293
}
249
294
250
295
status_t Label::on_mouse_in (const ws::event_t *e)
0 commit comments