Skip to content

Commit

Permalink
Fix clipping and border-radius
Browse files Browse the repository at this point in the history
Fix #4854
  • Loading branch information
ogoffart committed Mar 14, 2024
1 parent 78771e0 commit 5c381fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export component TextInput {
}

export component Clip {
in property <length> border-radius;
in property <length> border-top-left-radius;
in property <length> border-top-right-radius;
in property <length> border-bottom-left-radius;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/passes/border_radius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::expression_tree::{Expression, NamedReference};
use crate::object_tree::Component;
use std::rc::Rc;

const BORDER_RADIUS_PROPERTIES: [&str; 4] = [
pub const BORDER_RADIUS_PROPERTIES: [&str; 4] = [
"border-top-left-radius",
"border-top-right-radius",
"border-bottom-right-radius",
Expand Down
36 changes: 24 additions & 12 deletions internal/compiler/passes/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ fn create_clip_element(parent_elem: &ElementRc, native_clip: &Rc<NativeClass>) {
)
})
.collect();
for optional_binding in [
"border-radius",
"border-top-left-radius",
"border-top-right-radius",
"border-bottom-right-radius",
"border-bottom-left-radius",
"border-width",
]
.iter()

copy_optional_binding(parent_elem, "border-width", &clip);
if super::border_radius::BORDER_RADIUS_PROPERTIES
.iter()
.any(|property_name| parent_elem.borrow().is_binding_set(property_name, true))
{
if parent_elem.borrow().bindings.contains_key(*optional_binding) {
for optional_binding in super::border_radius::BORDER_RADIUS_PROPERTIES.iter() {
copy_optional_binding(parent_elem, optional_binding, &clip);
}
} else if parent_elem.borrow().bindings.contains_key("border-radius") {
for prop in super::border_radius::BORDER_RADIUS_PROPERTIES.iter() {
clip.borrow_mut().bindings.insert(
optional_binding.to_string(),
prop.to_string(),
RefCell::new(
Expression::PropertyReference(NamedReference::new(
parent_elem,
optional_binding,
"border-radius",
))
.into(),
),
Expand All @@ -107,3 +107,15 @@ fn create_clip_element(parent_elem: &ElementRc, native_clip: &Rc<NativeClass>) {
BindingExpression::new_two_way(NamedReference::new(parent_elem, "clip")).into(),
);
}

fn copy_optional_binding(parent_elem: &ElementRc, optional_binding: &str, clip: &ElementRc) {
if parent_elem.borrow().bindings.contains_key(optional_binding) {
clip.borrow_mut().bindings.insert(
optional_binding.to_string(),
RefCell::new(
Expression::PropertyReference(NamedReference::new(parent_elem, optional_binding))
.into(),
),
);
}
}
1 change: 0 additions & 1 deletion internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ declare_item_vtable! {
#[pin]
/// The implementation of the `Clip` element
pub struct Clip {
pub border_radius: Property<LogicalLength>,
pub border_top_left_radius: Property<LogicalLength>,
pub border_top_right_radius: Property<LogicalLength>,
pub border_bottom_left_radius: Property<LogicalLength>,
Expand Down

0 comments on commit 5c381fd

Please sign in to comment.