use super::{CommandBarDefaultLabelPosition, ICommandBarElement};
use crate::primitives::TemplatedControlImpl;
use crate::Button;
use crate::{ButtonImpl, ContentControlImpl, ControlImpl};
use ferroui_base::input::InputElementImpl;
use ferroui_base::interactivity::InteractiveImpl;
use ferroui_base::layout::LayoutableImpl;
use ferroui_base::{
ferro_class, ferro_class_info, ferro_impl_classes, ferro_properties, instantiate, BoxedValue, FerroObject,
FerroObjectImpl, FerroProperty, Ref, StyledElementImpl, StyledProperty, VisualImpl,
};
use std::rc::Rc;
#[repr(C)]
pub struct CommandBarButton {
base: Button,
}
ferro_class!(CommandBarButton: Button);
ferro_class_info!(CommandBarButton {
new: CommandBarButton::new,
interfaces: [
Rc<dyn ICommandBarElement> => |button: Ref<CommandBarButton>| button.as_command_bar_element(),
],
});
ferro_impl_classes!(
CommandBarButton: FerroObjectImpl,
StyledElementImpl,
VisualImpl,
LayoutableImpl,
InteractiveImpl,
InputElementImpl,
ControlImpl,
TemplatedControlImpl,
ContentControlImpl,
ButtonImpl
);
struct CommandBarButtonElement(Ref<CommandBarButton>);
impl ICommandBarElement for CommandBarButtonElement {
fn is_compact(&self) -> bool {
self.0.is_compact()
}
fn set_is_compact(&self, value: bool) {
self.0.set_is_compact(value)
}
fn is_in_overflow(&self) -> bool {
self.0.is_in_overflow()
}
fn set_is_in_overflow(&self, value: bool) {
self.0.set_is_in_overflow(value)
}
fn as_object(&self) -> Option<&FerroObject> {
let object: &FerroObject = &self.0;
Some(object)
}
}
ferro_properties! {
impl CommandBarButton {
pub fn label_property() -> StyledProperty<Option<String>> {
FerroProperty::register::<CommandBarButton, _>("Label", None)
}
pub fn icon_property() -> StyledProperty<Option<BoxedValue>> {
FerroProperty::register::<CommandBarButton, _>("Icon", None)
}
pub fn is_compact_property() -> StyledProperty<bool> {
FerroProperty::register::<CommandBarButton, _>("IsCompact", false)
}
pub fn dynamic_overflow_order_property() -> StyledProperty<i32> {
FerroProperty::register::<CommandBarButton, _>("DynamicOverflowOrder", 0)
}
pub fn label_position_property() -> StyledProperty<CommandBarDefaultLabelPosition> {
FerroProperty::register::<CommandBarButton, _>("LabelPosition", CommandBarDefaultLabelPosition::Bottom)
}
pub fn is_in_overflow_property() -> StyledProperty<bool> {
FerroProperty::register::<CommandBarButton, _>("IsInOverflow", false)
}
}
}
impl CommandBarButton {
pub fn construct() -> Self {
Self { base: Button::construct() }
}
pub fn new() -> Ref<Self> {
instantiate(Self::construct())
}
pub fn as_command_bar_element(&self) -> Rc<dyn ICommandBarElement> {
Rc::new(CommandBarButtonElement(self.to_ref()))
}
pub fn label(&self) -> Option<String> {
self.get_value(Self::label_property())
}
pub fn set_label(&self, value: Option<&str>) {
self.set_value(Self::label_property(), value.map(str::to_string))
}
pub fn icon(&self) -> Option<BoxedValue> {
self.get_value(Self::icon_property())
}
pub fn set_icon(&self, value: Option<BoxedValue>) {
self.set_value(Self::icon_property(), value)
}
pub fn is_compact(&self) -> bool {
self.get_value(Self::is_compact_property())
}
pub fn set_is_compact(&self, value: bool) {
self.set_value(Self::is_compact_property(), value)
}
pub fn dynamic_overflow_order(&self) -> i32 {
self.get_value(Self::dynamic_overflow_order_property())
}
pub fn set_dynamic_overflow_order(&self, value: i32) {
self.set_value(Self::dynamic_overflow_order_property(), value)
}
pub fn label_position(&self) -> CommandBarDefaultLabelPosition {
self.get_value(Self::label_position_property())
}
pub fn set_label_position(&self, value: CommandBarDefaultLabelPosition) {
self.set_value(Self::label_position_property(), value)
}
pub fn is_in_overflow(&self) -> bool {
self.get_value(Self::is_in_overflow_property())
}
pub fn set_is_in_overflow(&self, value: bool) {
self.set_value(Self::is_in_overflow_property(), value)
}
}