ferroui_controls/
column_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 ColumnDefinition {
10 base: DefinitionBase,
11}
12
13ferro_class!(ColumnDefinition: DefinitionBase);
14ferroui_base::ferro_class_info!(ColumnDefinition { new: ColumnDefinition::new });
15
16ferroui_base::ferro_impl_classes!(ColumnDefinition: FerroObjectImpl);
17
18impl DefinitionBaseImpl for ColumnDefinition {
19 fn user_size_value_cache(this: &Self) -> GridLength {
20 this.width()
21 }
22
23 fn user_min_size_value_cache(this: &Self) -> f64 {
24 this.min_width()
25 }
26
27 fn user_max_size_value_cache(this: &Self) -> f64 {
28 this.max_width()
29 }
30}
31
32ferroui_base::ferro_properties! { impl ColumnDefinition {
33 ferro_property!(
34 pub fn max_width_property() -> StyledProperty<f64> {
36 FerroProperty::register::<ColumnDefinition, _>("MaxWidth", f64::INFINITY)
37 }
38 );
39
40 ferro_property!(
41 pub fn min_width_property() -> StyledProperty<f64> {
43 FerroProperty::register::<ColumnDefinition, _>("MinWidth", 0.0)
44 }
45 );
46
47 ferro_property!(
48 pub fn width_property() -> StyledProperty<GridLength> {
50 FerroProperty::register::<ColumnDefinition, _>("Width", GridLength::new(1.0, GridUnitType::Star))
51 }
52 );
53} }
54
55impl ColumnDefinition {
56 fn static_constructor() {
57 DefinitionBase::affects_parent_measure(&[
58 Self::min_width_property().as_property(),
59 Self::max_width_property().as_property(),
60 ]);
61
62 Self::width_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_width(GridLength::new(value, type_))
82 }
83
84 pub fn with_width(width: GridLength) -> Ref<Self> {
86 let result = Self::new();
87 result.set_value(Self::width_property(), width);
88 result
89 }
90
91 pub fn actual_width(&self) -> f64 {
93 match self.parent() {
94 Some(parent) => parent.get_final_column_definition_width(self.index()),
95 None => 0.0,
96 }
97 }
98
99 pub fn max_width(&self) -> f64 {
101 self.get_value(Self::max_width_property())
102 }
103
104 pub fn set_max_width(&self, value: f64) {
105 self.set_value(Self::max_width_property(), value)
106 }
107
108 pub fn min_width(&self) -> f64 {
110 self.get_value(Self::min_width_property())
111 }
112
113 pub fn set_min_width(&self, value: f64) {
114 self.set_value(Self::min_width_property(), value)
115 }
116
117 pub fn width(&self) -> GridLength {
119 self.get_value(Self::width_property())
120 }
121
122 pub fn set_width(&self, value: GridLength) {
123 self.set_value(Self::width_property(), value)
124 }
125}