Always set Window.default-font-size

Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
This commit is contained in:
Simon Hausmann 2022-11-02 15:20:22 +01:00 committed by Simon Hausmann
parent a95504ad4f
commit 39121994ca
12 changed files with 87 additions and 3 deletions

View file

@ -157,7 +157,7 @@ WindowItem := _ {
input property <string> title: "Slint Window";
input property <bool> no-frame;
input property <string> default-font-family;
input property <length> default-font-size;
input output property <length> default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style
input property <int> default-font-weight;
input property <image> icon;
}
@ -613,6 +613,7 @@ export global NativeStyleMetrics := {
output property <length> text-cursor-width;
output property <color> window-background;
output property <color> default-text-color;
output property <length> default-font-size;
output property <color> textedit-background;
output property <color> textedit-text-color;
output property <color> textedit-background-disabled;

View file

@ -58,6 +58,25 @@ pub fn apply_default_properties_from_style(
.into(),
to: Type::Brush,
});
if !matches!(
style_metrics
.root_element
.borrow()
.lookup_property("default-font-size")
.property_type,
Type::Invalid,
) {
elem.set_binding_if_not_set("default-font-size".into(), || {
Expression::Cast {
from: Expression::PropertyReference(NamedReference::new(
&style_metrics.root_element,
"default-font-size",
))
.into(),
to: Type::LogicalLength,
}
});
}
}
_ => {}