ferroui_controls/command_bar/
command_bar_toggle_button.rs1use super::{CommandBarDefaultLabelPosition, ICommandBarElement};
2use crate::primitives::{TemplatedControlImpl, ToggleButton, ToggleButtonImpl};
3use crate::{ButtonImpl, ContentControlImpl, ControlImpl};
4use ferroui_base::input::InputElementImpl;
5use ferroui_base::interactivity::InteractiveImpl;
6use ferroui_base::layout::LayoutableImpl;
7use ferroui_base::{
8 ferro_class, ferro_class_info, ferro_impl_classes, ferro_properties, instantiate, BoxedValue, FerroObject,
9 FerroObjectImpl, FerroProperty, Ref, StyledElementImpl, StyledProperty, VisualImpl,
10};
11use std::rc::Rc;
12
13#[repr(C)]
15pub struct CommandBarToggleButton {
16 base: ToggleButton,
17}
18
19ferro_class!(CommandBarToggleButton: ToggleButton);
20ferro_class_info!(CommandBarToggleButton {
21 new: CommandBarToggleButton::new,
22 interfaces: [
23 Rc<dyn ICommandBarElement> => |button: Ref<CommandBarToggleButton>| button.as_command_bar_element(),
24 ],
25});
26ferro_impl_classes!(
27 CommandBarToggleButton: FerroObjectImpl,
28 StyledElementImpl,
29 VisualImpl,
30 LayoutableImpl,
31 InteractiveImpl,
32 InputElementImpl,
33 ControlImpl,
34 TemplatedControlImpl,
35 ContentControlImpl,
36 ButtonImpl,
37 ToggleButtonImpl
38);
39
40struct CommandBarToggleButtonElement(Ref<CommandBarToggleButton>);
43
44impl ICommandBarElement for CommandBarToggleButtonElement {
45 fn is_compact(&self) -> bool {
46 self.0.is_compact()
47 }
48
49 fn set_is_compact(&self, value: bool) {
50 self.0.set_is_compact(value)
51 }
52
53 fn is_in_overflow(&self) -> bool {
54 self.0.is_in_overflow()
55 }
56
57 fn set_is_in_overflow(&self, value: bool) {
58 self.0.set_is_in_overflow(value)
59 }
60
61 fn as_object(&self) -> Option<&FerroObject> {
62 let object: &FerroObject = &self.0;
63 Some(object)
64 }
65}
66
67ferro_properties! {
68 impl CommandBarToggleButton {
69 pub fn label_property() -> StyledProperty<Option<String>> {
71 FerroProperty::register::<CommandBarToggleButton, _>("Label", None)
72 }
73
74 pub fn icon_property() -> StyledProperty<Option<BoxedValue>> {
76 FerroProperty::register::<CommandBarToggleButton, _>("Icon", None)
77 }
78
79 pub fn is_compact_property() -> StyledProperty<bool> {
81 FerroProperty::register::<CommandBarToggleButton, _>("IsCompact", false)
82 }
83
84 pub fn dynamic_overflow_order_property() -> StyledProperty<i32> {
86 FerroProperty::register::<CommandBarToggleButton, _>("DynamicOverflowOrder", 0)
87 }
88
89 pub fn label_position_property() -> StyledProperty<CommandBarDefaultLabelPosition> {
91 FerroProperty::register::<CommandBarToggleButton, _>("LabelPosition", CommandBarDefaultLabelPosition::Bottom)
92 }
93
94 pub fn is_in_overflow_property() -> StyledProperty<bool> {
96 FerroProperty::register::<CommandBarToggleButton, _>("IsInOverflow", false)
97 }
98 }
99}
100
101impl CommandBarToggleButton {
102 pub fn construct() -> Self {
104 Self { base: ToggleButton::construct() }
105 }
106
107 pub fn new() -> Ref<Self> {
109 instantiate(Self::construct())
110 }
111
112 pub fn as_command_bar_element(&self) -> Rc<dyn ICommandBarElement> {
114 Rc::new(CommandBarToggleButtonElement(self.to_ref()))
115 }
116
117 pub fn label(&self) -> Option<String> {
119 self.get_value(Self::label_property())
120 }
121
122 pub fn set_label(&self, value: Option<&str>) {
124 self.set_value(Self::label_property(), value.map(str::to_string))
125 }
126
127 pub fn icon(&self) -> Option<BoxedValue> {
129 self.get_value(Self::icon_property())
130 }
131
132 pub fn set_icon(&self, value: Option<BoxedValue>) {
134 self.set_value(Self::icon_property(), value)
135 }
136
137 pub fn is_compact(&self) -> bool {
140 self.get_value(Self::is_compact_property())
141 }
142
143 pub fn set_is_compact(&self, value: bool) {
146 self.set_value(Self::is_compact_property(), value)
147 }
148
149 pub fn dynamic_overflow_order(&self) -> i32 {
153 self.get_value(Self::dynamic_overflow_order_property())
154 }
155
156 pub fn set_dynamic_overflow_order(&self, value: i32) {
159 self.set_value(Self::dynamic_overflow_order_property(), value)
160 }
161
162 pub fn label_position(&self) -> CommandBarDefaultLabelPosition {
165 self.get_value(Self::label_position_property())
166 }
167
168 pub fn set_label_position(&self, value: CommandBarDefaultLabelPosition) {
171 self.set_value(Self::label_position_property(), value)
172 }
173
174 pub fn is_in_overflow(&self) -> bool {
176 self.get_value(Self::is_in_overflow_property())
177 }
178
179 pub fn set_is_in_overflow(&self, value: bool) {
183 self.set_value(Self::is_in_overflow_property(), value)
184 }
185}