ferroui_controls/shapes/
ellipse.rs1use super::{Shape, ShapeImpl};
2use crate::ControlImpl;
3use ferroui_base::input::InputElementImpl;
4use ferroui_base::interactivity::InteractiveImpl;
5use ferroui_base::layout::LayoutableImpl;
6use ferroui_base::media::{EllipseGeometry, Geometry};
7use ferroui_base::{
8 ferro_class, ferro_impl_classes, instantiate, FerroObjectImpl, Rect, Ref, Size,
9 StyledElementImpl, Visual, VisualImpl,
10};
11
12#[repr(C)]
14pub struct Ellipse {
15 base: Shape,
16}
17
18ferro_class!(Ellipse: Shape);
19ferroui_base::ferro_class_info!(Ellipse { new: Ellipse::new });
20ferro_impl_classes!(Ellipse: StyledElementImpl, VisualImpl, InteractiveImpl, InputElementImpl, ControlImpl);
21
22ferroui_base::ferro_impl_classes!(Ellipse: FerroObjectImpl);
23
24impl ShapeImpl for Ellipse {
25 fn create_defining_geometry(this: &Self) -> Option<Ref<Geometry>> {
26 let rect = Rect::from_size(this.bounds().size()).deflate(this.stroke_thickness() / 2.0);
27 Some(EllipseGeometry::with_rect(rect).upcast())
28 }
29}
30
31impl LayoutableImpl for Ellipse {
32 fn measure_override(this: &Self, _available_size: Size) -> Size {
33 Size::new(this.stroke_thickness(), this.stroke_thickness())
34 }
35}
36
37impl Ellipse {
38 fn static_constructor() {
39 Shape::affects_geometry::<Ellipse>(&[
40 Visual::bounds_property().as_property(),
41 Shape::stroke_thickness_property().as_property(),
42 ]);
43 }
44
45 pub fn construct() -> Self {
47 Self { base: Shape::construct() }
48 }
49
50 pub fn new() -> Ref<Self> {
51 instantiate(Self::construct())
52 }
53}