mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
Add BorderRectangle::border_top|bottom_left|right_radius
This commit is contained in:
parent
9644f62f00
commit
51457025bf
5 changed files with 52 additions and 1 deletions
|
@ -565,6 +565,7 @@ When not part of a layout, its width and height default to 100% of the parent el
|
|||
- **`background`** (_in_ _brush_): The background brush of this `Rectangle`, typically a color. (default value: `transparent`)
|
||||
- **`border-color`** (_in_ _brush_): The color of the border. (default value: `transparent`)
|
||||
- **`border-radius`** (_in_ _length_): The size of the radius. (default value: 0)
|
||||
- **`border-top-left-radius`**, **`border-top-right-radius`**, **`border-bottom-left-radius`** and **`border-bottom-right-radius`** (_in_ _length_): Set these properties to override the radius for specific corners.
|
||||
- **`border-width`** (_in_ _length_): The width of the border. (default value: 0)
|
||||
- **`clip`** (_in_ _bool_): By default, when an element is bigger or outside another element, it's still shown. When this property is set to `true`, the children of this `Rectangle` are clipped to the border of the rectangle. (default value: `false`)
|
||||
|
||||
|
|
|
@ -32,6 +32,10 @@ component Rectangle inherits Empty {
|
|||
component BorderRectangle inherits Rectangle {
|
||||
in property <length> border-width;
|
||||
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;
|
||||
in property <length> border-bottom-right-radius;
|
||||
in property <brush> border-color;
|
||||
//-default_size_binding:expands_to_parent_geometry
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
mod apply_default_properties_from_style;
|
||||
mod binding_analysis;
|
||||
mod border_radius;
|
||||
mod check_expressions;
|
||||
mod check_public_api;
|
||||
mod check_rotation;
|
||||
|
@ -111,6 +112,7 @@ pub async fn run_passes(
|
|||
for component in (root_component.used_types.borrow().sub_components.iter())
|
||||
.chain(std::iter::once(root_component))
|
||||
{
|
||||
border_radius::handle_border_radius(component, diag);
|
||||
flickable::handle_flickable(component, &global_type_registry.borrow());
|
||||
repeater_component::process_repeater_components(component);
|
||||
lower_popups::lower_popups(component, &doc.local_registry, diag);
|
||||
|
|
28
internal/compiler/passes/border_radius.rs
Normal file
28
internal/compiler/passes/border_radius.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
||||
|
||||
//! Pass that applies the default border-radius to border-top|bottom-left|right-radius.
|
||||
|
||||
use crate::diagnostics::BuildDiagnostics;
|
||||
use crate::expression_tree::{Expression, NamedReference};
|
||||
use crate::object_tree::Component;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub fn handle_border_radius(root_component: &Rc<Component>, _diag: &mut BuildDiagnostics) {
|
||||
crate::object_tree::recurse_elem_including_sub_components_no_borrow(
|
||||
root_component,
|
||||
&(),
|
||||
&mut |elem, _| {
|
||||
let bty = if let Some(bty) = elem.borrow().builtin_type() { bty } else { return };
|
||||
if bty.name == "Rectangle" && elem.borrow().is_binding_set("border-radius", true) {
|
||||
let border_radius = NamedReference::new(elem, "border-radius");
|
||||
for corner in ["top-left", "top-right", "bottom-right", "bottom-left"].iter() {
|
||||
elem.borrow_mut()
|
||||
.set_binding_if_not_set(format!("border-{}-radius", corner), || {
|
||||
Expression::PropertyReference(border_radius.clone())
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
|
@ -29,7 +29,8 @@ use crate::item_rendering::CachedRenderingData;
|
|||
pub use crate::item_tree::ItemRc;
|
||||
use crate::layout::LayoutInfo;
|
||||
use crate::lengths::{
|
||||
LogicalLength, LogicalPoint, LogicalRect, LogicalSize, LogicalVector, PointLengths, RectLengths,
|
||||
LogicalBorderRadius, LogicalLength, LogicalPoint, LogicalRect, LogicalSize, LogicalVector,
|
||||
PointLengths, RectLengths,
|
||||
};
|
||||
#[cfg(feature = "rtti")]
|
||||
use crate::rtti::*;
|
||||
|
@ -332,6 +333,10 @@ pub struct BorderRectangle {
|
|||
pub background: Property<Brush>,
|
||||
pub border_width: Property<LogicalLength>,
|
||||
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>,
|
||||
pub border_bottom_right_radius: Property<LogicalLength>,
|
||||
pub border_color: Property<Brush>,
|
||||
pub cached_rendering_data: CachedRenderingData,
|
||||
}
|
||||
|
@ -394,6 +399,17 @@ impl Item for BorderRectangle {
|
|||
}
|
||||
}
|
||||
|
||||
impl BorderRectangle {
|
||||
pub fn logical_border_radius(self: Pin<&Self>) -> LogicalBorderRadius {
|
||||
LogicalBorderRadius::from_lengths(
|
||||
self.border_top_left_radius(),
|
||||
self.border_top_right_radius(),
|
||||
self.border_bottom_right_radius(),
|
||||
self.border_bottom_left_radius(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ItemConsts for BorderRectangle {
|
||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
||||
BorderRectangle,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue