slint
slint copied to clipboard
Bindings for default-font-size do not work when binding initially evaluates to 0
The following snippet fails to apply the default font size (initially and on window resize). Note that the very same binding applied directly to text works as expected.
export component Test inherits Window {
default-font-size: root.height * 0.3;
Text {
text: "Test";
// font-size: root.height * 0.3;
}
}
I can reproduce the problem.
It seems to be specific to this one binding, because default-font-size: 1px + root.height * 0.3;
actually works.
I think what happens is that the binding initially evaluates to 0 and then we initialize it to the default value from the backend.
But we should make a difference between unset and actually 0.
this testcase expose the problem. When the value at "start" is 0, the binding is broken. If we set a higher default, then it works.
Indeed, this code (and a few other places) assume that 0
means unset:
let default_font_size_prop =
crate::items::WindowItem::FIELD_OFFSETS.default_font_size.apply_pin(window_item);
if default_font_size_prop.get().get() <= 0 as Coord {
default_font_size_prop.set(window_adapter.renderer().default_font_size());
}
@medhefgo perhaps a workaround until we have the state of "unset" for properties would be for you to write
default-font-size: max(root.height * 0.3, 1px);
@tronical I think it's probably fine to assume that 0 means unset. But the problem is that we do erase the value with default_font_size_prop.set
To solve the problem we could either:
- leave the default_font_size property to zero, and call renderer().default_font_size() each time we do query this property
- have a default binding on the Window
default-font-size: __builtin-default-font-size()
set by the compiler.
Ah yes, you're right. I'm leaning towards (1). You?
Maybe actually 2 is going to be needed for rem
to work
or if someone does debug(root.default-font-size)