ferroui_controls/
row_definition.rs1use crate::definition_base::DefinitionBaseImpl;
2use crate::{DefinitionBase, GridLength, GridUnitType};
3use ferroui_base::{
4 ferro_class, ferro_property, instantiate, FerroObjectImpl, FerroProperty, Ref, StyledProperty,
5};
6
7#[repr(C)]
9pub struct RowDefinition {
10 base: DefinitionBase,
11}
12
13ferro_class!(RowDefinition: DefinitionBase);
14ferroui_base::ferro_class_info!(RowDefinition { new: RowDefinition::new });
15
16ferroui_base::ferro_impl_classes!(RowDefinition: FerroObjectImpl);
17
18impl DefinitionBaseImpl for RowDefinition {
19 fn user_size_value_cache(this: &Self) -> GridLength {
20 this.height()
21 }
22
23 fn user_min_size_value_cache(this: &Self) -> f64 {
24 this.min_height()
25 }
26
27 fn user_max_size_value_cache(this: &Self) -> f64 {
28 this.max_height()
29 }
30}
31
32ferroui_base::ferro_properties! { impl RowDefinition {
33 ferro_property!(
34 pub fn max_height_property() -> StyledProperty<f64> {
36 FerroProperty::register::<RowDefinition, _>("MaxHeight", f64::INFINITY)
37 }
38 );
39
40 ferro_property!(
41 pub fn min_height_property() -> StyledProperty<f64> {
43 FerroProperty::register::<RowDefinition, _>("MinHeight", 0.0)
44 }
45 );
46
47 ferro_property!(
48 pub fn height_property() -> StyledProperty<GridLength> {
50 FerroProperty::register::<RowDefinition, _>("Height", GridLength::new(1.0, GridUnitType::Star))
51 }
52 );
53} }
54
55impl RowDefinition {
56 fn static_constructor() {
57 DefinitionBase::affects_parent_measure(&[
58 Self::max_height_property().as_property(),
59 Self::min_height_property().as_property(),
60 ]);
61
62 Self::height_property()
63 .changed()
64 .add_class_handler::<DefinitionBase>(DefinitionBase::on_user_size_property_changed);
65 }
66
67 pub fn construct() -> Self {
69 Self {
70 base: DefinitionBase::construct(),
71 }
72 }
73
74 pub fn new() -> Ref<Self> {
76 instantiate(Self::construct())
77 }
78
79 pub fn with_value(value: f64, type_: GridUnitType) -> Ref<Self> {
81 Self::with_height(GridLength::new(value, type_))
82 }
83
84 pub fn with_height(height: GridLength) -> Ref<Self> {
86 let result = Self::new();
87 result.set_current_value(Self::height_property(), height);
88 result
89 }
90
91 pub fn actual_height(&self) -> f64 {
93 match self.parent() {
94 Some(parent) => parent.get_final_row_definition_height(self.index()),
95 None => 0.0,
96 }
97 }
98
99 pub fn max_height(&self) -> f64 {
101 self.get_value(Self::max_height_property())
102 }
103
104 pub fn set_max_height(&self, value: f64) {
105 self.set_value(Self::max_height_property(), value)
106 }
107
108 pub fn min_height(&self) -> f64 {
110 self.get_value(Self::min_height_property())
111 }
112
113 pub fn set_min_height(&self, value: f64) {
114 self.set_value(Self::min_height_property(), value)
115 }
116
117 pub fn height(&self) -> GridLength {
119 self.get_value(Self::height_property())
120 }
121
122 pub fn set_height(&self, value: GridLength) {
123 self.set_value(Self::height_property(), value)
124 }
125}