ferroui_base/media/
line_segment.rs1use crate::media::{PathSegment, PathSegmentImpl};
2use crate::platform::IGeometryContext;
3use crate::{
4 ferro_class, ferro_impl_classes, ferro_property, instantiate, FerroObjectImpl, FerroProperty, Point, Ref,
5 StyledProperty,
6};
7
8#[repr(C)]
10pub struct LineSegment {
11 base: PathSegment,
12}
13
14ferro_class!(LineSegment: PathSegment);
15crate::ferro_class_info!(LineSegment { new: LineSegment::new });
16ferro_impl_classes!(LineSegment: FerroObjectImpl);
17
18impl PathSegmentImpl for LineSegment {
19 fn apply_to(this: &Self, ctx: &mut dyn IGeometryContext) {
20 ctx.line_to(this.point(), this.is_stroked());
21 }
22
23 fn to_string(this: &Self) -> String {
24 format!("L {}", this.point())
25 }
26}
27
28crate::ferro_properties! { impl LineSegment {
29 ferro_property!(pub fn point_property() -> StyledProperty<Point> {
30 FerroProperty::register::<LineSegment, _>("Point", Point::default())
31 });
32} }
33
34impl LineSegment {
35 pub fn construct() -> Self {
37 Self { base: PathSegment::construct() }
38 }
39
40 pub fn new() -> Ref<Self> {
41 instantiate(Self::construct())
42 }
43
44 pub fn point(&self) -> Point {
46 self.get_value(Self::point_property())
47 }
48
49 pub fn set_point(&self, value: Point) {
50 self.set_value(Self::point_property(), value)
51 }
52}