Skip to content

Commit 0631dc7

Browse files
committed
Route master-merged bindings accesses through the sealed accessor
1 parent e8691ba commit 0631dc7

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

internal/compiler/generator/slint_sc.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ fn declared_properties(root: &ElementRc) -> Vec<DeclaredProperty> {
110110
.filter(|(_, decl)| decl.node.is_some())
111111
.map(|(name, decl)| {
112112
let init = root_borrowed
113-
.bindings
114-
.get(name)
113+
.binding_cell_including_synthetic(name)
115114
.map(|b| compile_expression(&b.borrow().expression, root))
116115
.unwrap_or_else(|| default_value(&decl.property_type));
117116
let snake = name.replace('-', "_");
@@ -202,8 +201,10 @@ fn emit_element(elem: &ElementRc, root: &ElementRc) -> TokenStream {
202201
let h = resolve(geometry.as_ref().map(|g| &g.height)).expect("element without a height");
203202
let x = resolve(geometry.as_ref().map(|g| &g.x)).unwrap_or_else(|| quote!(0i32));
204203
let y = resolve(geometry.as_ref().map(|g| &g.y)).unwrap_or_else(|| quote!(0i32));
205-
let background =
206-
elem.borrow().bindings.get("background").map(|b| b.borrow().expression.clone());
204+
let background = elem
205+
.borrow()
206+
.binding_cell_including_synthetic("background")
207+
.map(|b| b.borrow().expression.clone());
207208
let mut color = background.map(|expr| compile_expression(&expr, root));
208209
if std::rc::Rc::ptr_eq(elem, root) {
209210
// The window background defaults to black, so that the whole frame
@@ -237,7 +238,10 @@ fn emit_element(elem: &ElementRc, root: &ElementRc) -> TokenStream {
237238
/// size for the root's unbound width and height.
238239
fn compile_property_reference(nr: &NamedReference, root: &ElementRc) -> Option<TokenStream> {
239240
let element = nr.element();
240-
let binding = element.borrow().bindings.get(nr.name()).map(|b| b.borrow().expression.clone());
241+
let binding = element
242+
.borrow()
243+
.binding_cell_including_synthetic(nr.name())
244+
.map(|b| b.borrow().expression.clone());
241245
match binding {
242246
Some(expr) => Some(compile_expression(&expr, root)),
243247
None if std::rc::Rc::ptr_eq(&element, root) => match nr.name().as_str() {

internal/compiler/object_tree.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl Component {
542542
.is_some_and(|b| matches!(b.name.as_str(), "Window" | "Dialog"))
543543
{
544544
for prop in ["x", "y"] {
545-
if let Some(b) = c.root_element.borrow().bindings.get(prop) {
545+
if let Some(b) = c.root_element.borrow().binding_cell_including_synthetic(prop) {
546546
#[cfg(feature = "slint-sc")]
547547
if diag.slint_sc {
548548
diag.slint_sc_error(&format!("The property '{prop}' is"), &*b.borrow());
@@ -2199,8 +2199,7 @@ impl Element {
21992199
// Check if content-width and content-height are explicitly set by the user,
22002200
// either under their own name or through the deprecated viewport-* aliases.
22012201
let (content_width_is_explicitly_set, content_height_is_explicitly_set) = {
2202-
let has_binding =
2203-
|name| parent_elem.binding(name).is_some_and(|b| b.has_binding());
2202+
let has_binding = |name| parent_elem.binding(name).is_some_and(|b| b.has_binding());
22042203
(
22052204
has_binding("content-width") || has_binding("viewport-width"),
22062205
has_binding("content-height") || has_binding("viewport-height"),

0 commit comments

Comments
 (0)