ferroui_base/rendering/composition/
composition_view_box.rs1use super::composition_object_impls::composition_object_impls;
2use super::generated::{CompositionViewBoxHooks, CompositionViewBoxProps, ServerCompositionViewBoxProps};
3use super::server::{ServerCompositionViewBox, ServerObjectId};
4use super::{CompositionObject, CompositionStretch, Compositor};
5use crate::Vector;
6use std::rc::{Rc, Weak};
7
8pub struct CompositionViewBox {
18 this: Weak<CompositionViewBox>,
19 object: CompositionObject,
20 props: CompositionViewBoxProps,
21}
22
23impl CompositionViewBox {
24 pub(crate) fn new(compositor: &Rc<Compositor>) -> Rc<CompositionViewBox> {
25 let server = compositor.create_server_object(|compositor, _| ServerCompositionViewBox::new(compositor));
26 let view_box = Rc::new_cyclic(|this: &Weak<CompositionViewBox>| CompositionViewBox {
27 this: this.clone(),
28 object: CompositionObject::new(compositor, Some(server)),
29 props: CompositionViewBoxProps::new(),
30 });
31 view_box.props.initialize_defaults(&*view_box);
32 view_box
33 }
34
35 pub fn compositor(&self) -> &Rc<Compositor> {
36 self.object.compositor()
37 }
38
39 pub fn object(&self) -> &CompositionObject {
41 &self.object
42 }
43
44 pub fn server(&self) -> ServerObjectId {
46 self.object.required_server()
47 }
48
49 pub fn is_disposed(&self) -> bool {
50 self.object.is_disposed()
51 }
52
53 pub fn dispose(&self) {
54 self.object.dispose();
55 }
56
57 pub fn props(&self) -> &CompositionViewBoxProps {
59 &self.props
60 }
61
62 pub fn horizontal_alignment_ratio(&self) -> f32 {
65 self.props.horizontal_alignment_ratio()
66 }
67
68 pub fn set_horizontal_alignment_ratio(&self, value: f32) {
69 self.props.set_horizontal_alignment_ratio(self, value)
70 }
71
72 pub fn offset(&self) -> Vector {
74 self.props.offset()
75 }
76
77 pub fn set_offset(&self, value: Vector) {
78 self.props.set_offset(self, value)
79 }
80
81 pub fn size(&self) -> Vector {
83 self.props.size()
84 }
85
86 pub fn set_size(&self, value: Vector) {
87 self.props.set_size(self, value)
88 }
89
90 pub fn stretch(&self) -> CompositionStretch {
92 self.props.stretch()
93 }
94
95 pub fn set_stretch(&self, value: CompositionStretch) {
96 self.props.set_stretch(self, value)
97 }
98
99 pub fn vertical_alignment_ratio(&self) -> f32 {
102 self.props.vertical_alignment_ratio()
103 }
104
105 pub fn set_vertical_alignment_ratio(&self, value: f32) {
106 self.props.set_vertical_alignment_ratio(self, value)
107 }
108}
109
110impl CompositionViewBoxHooks for CompositionViewBox {}
111
112composition_object_impls!(
113 CompositionViewBox, "CompositionViewBox",
114 serialize: |this, writer| this.props.serialize_changes_core(this, writer),
115 start_animation: |this, name, animation, final_value| this.props.start_animation(this, name, animation, final_value),
116 composition_property: |_this, name| ServerCompositionViewBoxProps::get_composition_property(name),
117);