Skip to content

Commit 6b3ea3d

Browse files
committed
Fix font familly of component that inherit from PopupWindow with the material style
Fixes slint-ui#9866 The material style defines a `StyleMetrics.default-font-family` which is meant to be applied to `Window` element if not set by the user. But it was mistakely sometimes applied to PopupWindow Consider this code: ```slint component MyPopup inherits PopupWindow { Text { text: "Hello"; } } export component MainWindow inherits Window { my_popup := MyPopup { } } ``` First, we would process MyPopup: `apply_default_property_from_style` wouldn't do anything, but the `lower_popups` pass would replace its root with a Window builtin. Second, we would process MainWindow: `apply_default_property_from_style` would see that my_popup is using the Window as a builtin and would apply default window properties from style, which it shouldn't. In fact, `apply_default_property_from_style` should only apply default for elements that are directly using the builtin, not a component that inherits from that builtin, as these property should have been already set.
1 parent ce4283e commit 6b3ea3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/compiler/passes/apply_default_properties_from_style.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use crate::diagnostics::BuildDiagnostics;
99
use crate::expression_tree::{Expression, NamedReference};
10-
use crate::langtype::Type;
10+
use crate::langtype::{ElementType, Type};
1111
use crate::object_tree::Component;
1212
use smol_str::SmolStr;
1313
use std::rc::Rc;
@@ -24,7 +24,9 @@ pub fn apply_default_properties_from_style(
2424
&(),
2525
&mut |elem, _| {
2626
let mut elem = elem.borrow_mut();
27-
match elem.builtin_type().as_ref().map_or("", |b| b.name.as_str()) {
27+
let ElementType::Builtin(builtin) = &elem.base_type else { return };
28+
let builtin_name = builtin.name.as_str();
29+
match builtin_name {
2830
"TextInput" => {
2931
elem.set_binding_if_not_set("text-cursor-width".into(), || {
3032
Expression::PropertyReference(NamedReference::new(

0 commit comments

Comments
 (0)