pub enum ClipShape {
Rect(Rect),
RoundRect {
rect: Rect,
radius: f32,
},
}Expand description
Axis-aligned or rounded clip region in local coordinates.
Possible values are ClipShape::Rect and ClipShape::RoundRect.
§Examples
use ailloli_ui_core::{ClipShape, Rect};
assert!(ClipShape::rect(Rect::new(0.0, 0.0, 10.0, 10.0)).contains_point(5.0, 5.0));Variants§
Implementations§
Source§impl ClipShape
impl ClipShape
Sourcepub fn rect(r: Rect) -> Self
pub fn rect(r: Rect) -> Self
Creates a rectangular clip.
§Examples
use ailloli_ui_core::{ClipShape, Rect};
let rect = Rect::new(0.0, 0.0, 10.0, 10.0);
assert_eq!(ClipShape::rect(rect).bounding_rect(), rect);Sourcepub fn round_rect(rect: Rect, radius: f32) -> Self
pub fn round_rect(rect: Rect, radius: f32) -> Self
Creates a rounded-rect clip without normalizing its radius or bounds.
§Examples
use ailloli_ui_core::{ClipShape, Rect};
assert!(matches!(ClipShape::round_rect(Rect::new(0.0, 0.0, 10.0, 10.0), 2.0), ClipShape::RoundRect { .. }));Sourcepub fn bounding_rect(&self) -> Rect
pub fn bounding_rect(&self) -> Rect
Tight axis-aligned bounds of this clip (ignores corner cut-outs for RoundRect).
§Examples
use ailloli_ui_core::{ClipShape, Rect};
let rect = Rect::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(ClipShape::round_rect(rect, 2.0).bounding_rect(), rect);Sourcepub fn contains_point(&self, px: f32, py: f32) -> bool
pub fn contains_point(&self, px: f32, py: f32) -> bool
Hit-test in local clip space (same coordinate system as rect).
§Examples
use ailloli_ui_core::{ClipShape, Rect};
assert!(!ClipShape::round_rect(Rect::new(0.0, 0.0, 10.0, 10.0), 5.0).contains_point(0.0, 0.0));Sourcepub fn intersect(&self, other: &Self) -> Option<Self>
pub fn intersect(&self, other: &Self) -> Option<Self>
Returns a conservative rectangular intersection of two clips.
A rounded result keeps the rounded operand’s radius, or the minimum
radius when both operands are rounded. This is not an exact geometric
intersection of corner arcs; it is a compact clip approximation. Zero-
area edge contact returns None through Rect::intersection.
§Examples
use ailloli_ui_core::{ClipShape, Rect};
let a = ClipShape::rect(Rect::new(0.0, 0.0, 10.0, 10.0));
let b = ClipShape::rect(Rect::new(5.0, 5.0, 10.0, 10.0));
assert_eq!(a.intersect(&b).unwrap().bounding_rect(), Rect::new(5.0, 5.0, 5.0, 5.0));Trait Implementations§
impl Copy for ClipShape
impl StructuralPartialEq for ClipShape
Auto Trait Implementations§
impl Freeze for ClipShape
impl RefUnwindSafe for ClipShape
impl Send for ClipShape
impl Sync for ClipShape
impl Unpin for ClipShape
impl UnwindSafe for ClipShape
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more