diff --git a/src/widgets/button.rs b/src/widgets/button.rs index ed1f9f6f2b10c8ff65911d5020687ff8bfd4c2ab..3084e7e0c534e94b0d12cc0c13f6d5d5e3a1e5ac 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -5,18 +5,37 @@ use crate::core::{ widget, Children, Color, Fragment, OnEvent, WidgetProps, }; -#[derive(WidgetProps, Default, Debug, PartialEq, Clone)] +#[derive(Default, Debug, PartialEq, Clone)] pub struct ButtonProps { - #[prop_field(Styles)] + pub disabled: bool, pub styles: Option<Style>, - #[prop_field(Children)] pub children: Option<Children>, - #[prop_field(OnEvent)] pub on_event: Option<OnEvent>, - #[prop_field(Focusable)] pub focusable: Option<bool>, } +impl WidgetProps for ButtonProps { + fn get_children(&self) -> Option<Children> { + self.children.clone() + } + + fn set_children(&mut self, children: Option<Children>) { + self.children = children; + } + + fn get_styles(&self) -> Option<Style> { + self.styles.clone() + } + + fn get_on_event(&self) -> Option<OnEvent> { + self.on_event.clone() + } + + fn get_focusable(&self) -> Option<bool> { + Some(!self.disabled) + } +} + #[widget] pub fn Button(props: ButtonProps) { let base_styles = props.styles.clone().unwrap_or_default(); diff --git a/src/widgets/text_box.rs b/src/widgets/text_box.rs index ebd0784772de84b9c2b964c3ddbf9939bfc5f65e..a1cd5fbfbd533798a34848cb4b151cddcc978477 100644 --- a/src/widgets/text_box.rs +++ b/src/widgets/text_box.rs @@ -8,21 +8,40 @@ use std::sync::{Arc, RwLock}; use crate::widgets::{Background, Clip, Text}; -#[derive(WidgetProps, Default, Debug, PartialEq, Clone)] +#[derive(Default, Debug, PartialEq, Clone)] pub struct TextBoxProps { + pub disabled: bool, pub value: String, pub on_change: Option<OnChange>, pub placeholder: Option<String>, - #[prop_field(Styles)] pub styles: Option<Style>, - #[prop_field(Children)] pub children: Option<Children>, - #[prop_field(OnEvent)] pub on_event: Option<OnEvent>, - #[prop_field(Focusable)] pub focusable: Option<bool>, } +impl WidgetProps for TextBoxProps { + fn get_children(&self) -> Option<Children> { + self.children.clone() + } + + fn set_children(&mut self, children: Option<Children>) { + self.children = children; + } + + fn get_styles(&self) -> Option<Style> { + self.styles.clone() + } + + fn get_on_event(&self) -> Option<OnEvent> { + self.on_event.clone() + } + + fn get_focusable(&self) -> Option<bool> { + Some(!self.disabled) + } +} + #[derive(Debug, Clone, PartialEq)] pub struct ChangeEvent { pub value: String, @@ -52,7 +71,7 @@ impl std::fmt::Debug for OnChange { #[derive(Debug, Clone, Copy, PartialEq)] pub struct Focus(pub bool); -#[widget(focusable)] +#[widget] pub fn TextBox(props: TextBoxProps) { let TextBoxProps { on_change,