From 66a3b24447cbdd62decdd6a11ba3a2116ad179fb Mon Sep 17 00:00:00 2001
From: MrGVSV <gino.valente.code@gmail.com>
Date: Fri, 4 Feb 2022 15:06:29 -0800
Subject: [PATCH] Set default focusability

---
 src/widgets/button.rs   | 29 ++++++++++++++++++++++++-----
 src/widgets/text_box.rs | 31 +++++++++++++++++++++++++------
 2 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/src/widgets/button.rs b/src/widgets/button.rs
index ed1f9f6..3084e7e 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 ebd0784..a1cd5fb 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,
-- 
GitLab