Skip to main content

ferroui_base/media/
path_segment.rs

1use crate::platform::IGeometryContext;
2use crate::{ferro_class, ferro_property, FerroObject, FerroObjectImpl, FerroProperty, StyledProperty};
3
4/// Represents a segment of a [`PathFigure`](crate::media::PathFigure).
5#[repr(C)]
6pub struct PathSegment {
7    base: FerroObject,
8}
9
10ferro_class! {
11    PathSegment: FerroObject, virtuals PathSegmentImpl: FerroObjectImpl {
12        /// Draws the segment into `ctx`.
13        fn apply_to(this, ctx: &mut dyn IGeometryContext);
14
15        /// The path markup of the segment.
16        fn to_string(this) -> String;
17    }
18}
19
20crate::ferro_impl_classes!(PathSegment: FerroObjectImpl);
21
22impl PathSegmentImpl for PathSegment {
23    fn apply_to(_this: &Self, _ctx: &mut dyn IGeometryContext) {
24        panic!("PathSegment is abstract: 'apply_to' must be implemented by the deriving class")
25    }
26
27    fn to_string(this: &Self) -> String {
28        this.get_type().name().to_string()
29    }
30}
31
32crate::ferro_properties! { impl PathSegment {
33    ferro_property!(pub fn is_stroked_property() -> StyledProperty<bool> {
34        FerroProperty::register::<PathSegment, _>("IsStroked", true)
35    });
36} }
37
38impl PathSegment {
39    /// Creates the class data.
40    pub fn construct() -> Self {
41        Self { base: FerroObject::construct() }
42    }
43
44    /// Whether the segment is stroked.
45    pub fn is_stroked(&self) -> bool {
46        self.get_value(Self::is_stroked_property())
47    }
48
49    pub fn set_is_stroked(&self, value: bool) {
50        self.set_value(Self::is_stroked_property(), value)
51    }
52}