mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 18:29:09 +00:00
Properly initialize the default binding of a state to its materialized value
Fixes #1237
This commit is contained in:
parent
8be92eac1d
commit
01bf529f79
3 changed files with 59 additions and 4 deletions
|
@ -201,7 +201,9 @@ fn expression_for_property(element: &ElementRc, name: &str) -> ExpressionForProp
|
|||
None
|
||||
};
|
||||
}
|
||||
ExpressionForProperty::Expression(Expression::default_value_for_type(
|
||||
&element.borrow().lookup_property(name).property_type,
|
||||
))
|
||||
let expr = super::materialize_fake_properties::initialize(element, name).unwrap_or_else(|| {
|
||||
Expression::default_value_for_type(&element.borrow().lookup_property(name).property_type)
|
||||
});
|
||||
|
||||
ExpressionForProperty::Expression(expr)
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ fn has_declared_property(elem: &Element, prop: &str) -> bool {
|
|||
}
|
||||
|
||||
/// Initialize a sensible default binding for the now materialized property
|
||||
fn initialize(elem: &ElementRc, name: &str) -> Option<Expression> {
|
||||
pub fn initialize(elem: &ElementRc, name: &str) -> Option<Expression> {
|
||||
let expr = match name {
|
||||
"min-height" => layout_constraint_prop(elem, "min", Orientation::Vertical),
|
||||
"min-width" => layout_constraint_prop(elem, "min", Orientation::Horizontal),
|
||||
|
|
53
tests/cases/properties/issue1237_states_visible.slint
Normal file
53
tests/cases/properties/issue1237_states_visible.slint
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||
|
||||
TestCase := Window {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
property<int> niceness: 33;
|
||||
greeting := TouchArea {
|
||||
clicked => { root.niceness += 1; }
|
||||
t:= Text {
|
||||
text: "Hello world";
|
||||
}
|
||||
|
||||
states [
|
||||
rude when root.niceness <= 0: {visible: false;}
|
||||
mannered when root.niceness > 100: {t.text: "Hello, dearest world"; t.font-size: 32px;}
|
||||
]
|
||||
}
|
||||
|
||||
property <bool> test: greeting.visible;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
```cpp
|
||||
auto handle = TestCase::create();
|
||||
const TestCase &instance = *handle;
|
||||
assert(instance.get_test());
|
||||
slint::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert_eq(instance.get_niceness(), 34);
|
||||
|
||||
instance.set_niceness(-1);
|
||||
assert(!instance.get_test());
|
||||
slint::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert_eq(instance.get_niceness(), -1);
|
||||
|
||||
```
|
||||
|
||||
|
||||
```rust
|
||||
let instance = TestCase::new();
|
||||
assert!(instance.get_test());
|
||||
slint::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert_eq!(instance.get_niceness(), 34);
|
||||
|
||||
instance.set_niceness(-1);
|
||||
assert!(!instance.get_test());
|
||||
slint::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert_eq!(instance.get_niceness(), -1);
|
||||
```
|
||||
|
||||
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue