Skip to main content

i_slint_compiler/passes/
border_radius.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! Pass that applies the default border-radius to border-top|bottom-left|right-radius.
5
6use crate::diagnostics::BuildDiagnostics;
7use crate::expression_tree::{Expression, NamedReference};
8use crate::object_tree::Component;
9use smol_str::SmolStr;
10use std::rc::Rc;
11
12pub const BORDER_RADIUS_PROPERTIES: [&str; 4] = [
13    "border-top-left-radius",
14    "border-top-right-radius",
15    "border-bottom-right-radius",
16    "border-bottom-left-radius",
17];
18
19pub fn handle_border_radius(root_component: &Rc<Component>, _diag: &mut BuildDiagnostics) {
20    crate::object_tree::recurse_elem_including_sub_components_no_borrow(
21        root_component,
22        &(),
23        &mut |elem, _| {
24            let bty = if let Some(bty) = elem.borrow().builtin_type() { bty } else { return };
25            if bty.name == "Rectangle"
26                && elem.borrow().is_binding_set("border-radius", true)
27                && BORDER_RADIUS_PROPERTIES.iter().any(|property_name| {
28                    let elem = elem.borrow();
29                    elem.is_binding_set(property_name, true)
30                        || elem.binding_cell_including_synthetic(property_name).is_some_and(
31                            |binding| binding.borrow().expression.is_synthetic_debug_hook(),
32                        )
33                })
34            {
35                let border_radius = NamedReference::new(elem, SmolStr::new_static("border-radius"));
36                for property_name in BORDER_RADIUS_PROPERTIES.iter() {
37                    elem.borrow_mut().set_binding_if_not_set(SmolStr::new(property_name), || {
38                        Expression::PropertyReference(border_radius.clone())
39                    });
40                }
41            }
42        },
43    )
44}