ferroui_controls/command_bar/
command_bar_button.rs1use super::{CommandBarDefaultLabelPosition, ICommandBarElement};
2use crate::primitives::TemplatedControlImpl;
3use crate::Button;
4use crate::{ButtonImpl, ContentControlImpl, ControlImpl};
5use ferroui_base::input::InputElementImpl;
6use ferroui_base::interactivity::InteractiveImpl;
7use ferroui_base::layout::LayoutableImpl;
8use ferroui_base::{
9 ferro_class, ferro_class_info, ferro_impl_classes, ferro_properties, instantiate, BoxedValue, FerroObject,
10 FerroObjectImpl, FerroProperty, Ref, StyledElementImpl, StyledProperty, VisualImpl,
11};
12use std::rc::Rc;
13
14#[repr(C)]
16pub struct CommandBarButton {
17 base: Button,
18}
19
20ferro_class!(CommandBarButton: Button);
21ferro_class_info!(CommandBarButton {
22 new: CommandBarButton::new,
23 interfaces: [
24 Rc<dyn ICommandBarElement> => |button: Ref<CommandBarButton>| button.as_command_bar_element(),
25 ],
26});
27ferro_impl_classes!(
28 CommandBarButton: FerroObjectImpl,
29 StyledElementImpl,
30 VisualImpl,
31 LayoutableImpl,
32 InteractiveImpl,
33 InputElementImpl,
34 ControlImpl,
35 TemplatedControlImpl,
36 ContentControlImpl,
37 ButtonImpl
38);
39
40struct CommandBarButtonElement(Ref<CommandBarButton>);
43
44impl ICommandBarElement for CommandBarButtonElement {
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 CommandBarButton {
69 pub fn label_property() -> StyledProperty<Option<String>> {
71 FerroProperty::register::<CommandBarButton, _>("Label", None)
72 }
73
74 pub fn icon_property() -> StyledProperty<Option<BoxedValue>> {
76 FerroProperty::register::<CommandBarButton, _>("Icon", None)
77 }
78
79 pub fn is_compact_property() -> StyledProperty<bool> {
81 FerroProperty::register::<CommandBarButton, _>("IsCompact", false)
82 }
83
84 pub fn dynamic_overflow_order_property() -> StyledProperty<i32> {
86 FerroProperty::register::<CommandBarButton, _>("DynamicOverflowOrder", 0)
87 }
88
89 pub fn label_position_property() -> StyledProperty<CommandBarDefaultLabelPosition> {
91 FerroProperty::register::<CommandBarButton, _>("LabelPosition", CommandBarDefaultLabelPosition::Bottom)
92 }
93
94 pub fn is_in_overflow_property() -> StyledProperty<bool> {
96 FerroProperty::register::<CommandBarButton, _>("IsInOverflow", false)
97 }
98 }
99}
100
101impl CommandBarButton {
102 pub fn construct() -> Self {
104 Self { base: Button::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(CommandBarButtonElement(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}