strange if statment on root, and proper text sizing #5175
Replies: 3 comments
-
there is a lot of missing option here but this works quite well even with gridlayout , component AdaptiveText {
in property <color> background;
in property <color> color;
in property <string> text;
in property <int> text_length;
property <length> with_size: root.width/(text_length/2);
property <length> height_size: root.height;
property <length> true_size;
states [
active when (with_size > height_size):{
true_size: height_size;
}
active when (with_size < height_size):{
true_size: with_size;
}
]
Rectangle {
if(true): Text{ // ?? break/skipp static size analysis, dirty but allow to use root based size
// option ? if(true_size != 0px)
text: text;
color: color;
font-size: true_size;
horizontal-alignment: center;
vertical-alignment: center;
}
background: background;
}
}
component TestAdText {
GridLayout {
AdaptiveText {background: black;text: "testtas";color: white; text_length: 7;}
}
} is there a way to get the amount of chars like a .len() ? and a function to get the greatest amount of char for a multiple line text , and maybe the amount of lines ? |
Beta Was this translation helpful? Give feedback.
-
Yes, there is a difference for the computation of the layout constraint of the parent when the element is in a We can get around that by specifying the layout constraint (minimum / preferred size) manually. |
Beta Was this translation helpful? Give feedback.
-
ok great, thanks for the info. |
Beta Was this translation helpful? Give feedback.
-
By default, it seems that a text element defines the size of its parent.
For example, if I create a gridlayout with rectangle, everything is the same size.
If I put text inside one of the rectangle, the whole cell takes the size of the text.
It's actually quite annoying that adding text to a sub-element ruins the formatting of all the parent elements.
I try to make the size of the text adapt to the size of the element.
I've found a trick to do this, but it seems quite dirty. Is this a bug?
the non working code :
and an if solve this, why ??
Oh wait what ? this also works with an if(true) 😅
Could it be that the "if" is annalyzed at runtime and that slint doesn't take the element into account for the size calculation, or something like that ? And how to do this without the very dirty if(true) ?
Beta Was this translation helpful? Give feedback.
All reactions