| 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 | |
| 6 | use crate::diagnostics::BuildDiagnostics; |
| 7 | use crate::expression_tree::{Expression, NamedReference}; |
| 8 | use crate::object_tree::Component; |
| 9 | use smol_str::SmolStr; |
| 10 | use std::rc::Rc; |
| 11 | |
| 12 | pub 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 | |
| 19 | pub 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: &Rc>, _| { |
| 24 | let bty: Rc = if let Some(bty: Rc) = elem.borrow().builtin_type() { bty } else { return }; |
| 25 | if bty.name == "Rectangle" |
| 26 | && elem.borrow().is_binding_set(property_name:"border-radius" , need_explicit:true) |
| 27 | && BORDER_RADIUS_PROPERTIES |
| 28 | .iter() |
| 29 | .any(|property_name: &&str| elem.borrow().is_binding_set(property_name, need_explicit:true)) |
| 30 | { |
| 31 | let border_radius: NamedReference = NamedReference::new(element:elem, name:SmolStr::new_static(text:"border-radius" )); |
| 32 | for property_name: &&str in BORDER_RADIUS_PROPERTIES.iter() { |
| 33 | elem.borrow_mut().set_binding_if_not_set(property_name:SmolStr::new(property_name), || { |
| 34 | Expression::PropertyReference(border_radius.clone()) |
| 35 | }); |
| 36 | } |
| 37 | } |
| 38 | }, |
| 39 | ) |
| 40 | } |
| 41 | |