From dc7892ed4e54a9565da3e7a65c8ff0310c804e62 Mon Sep 17 00:00:00 2001
From: StarArawn <toasterthegamer@gmail.com>
Date: Sat, 18 Dec 2021 08:08:45 -0500
Subject: [PATCH] Lots of cleanup.

---
 examples/text_box.rs               |  4 +++-
 kayak_core/src/binding.rs          |  8 ++++----
 kayak_core/src/context.rs          |  5 +++--
 kayak_core/src/lib.rs              | 17 +----------------
 kayak_core/src/render_command.rs   |  1 -
 kayak_core/src/render_primitive.rs |  1 -
 kayak_widgets/src/app.rs           |  2 +-
 kayak_widgets/src/text_box.rs      | 13 +------------
 8 files changed, 13 insertions(+), 38 deletions(-)

diff --git a/examples/text_box.rs b/examples/text_box.rs
index 6cd17e6..bbf01ec 100644
--- a/examples/text_box.rs
+++ b/examples/text_box.rs
@@ -13,7 +13,9 @@ use kayak_widgets::{App, OnChange, TextBox, Window};
 
 #[widget]
 fn TextBoxExample(context: &mut KayakContext) {
-    let value = context.create_state("".to_string()).unwrap();
+    let value = context
+        .create_state("I started with a value!".to_string())
+        .unwrap();
     let value2 = context.create_state("".to_string()).unwrap();
 
     let input_styles = Style {
diff --git a/kayak_core/src/binding.rs b/kayak_core/src/binding.rs
index fbd4a31..c157376 100644
--- a/kayak_core/src/binding.rs
+++ b/kayak_core/src/binding.rs
@@ -5,20 +5,20 @@ pub use flo_binding::{bind, notify, Binding, Bound, Changeable, MutableBound, Re
 #[derive(Debug, Clone, Copy, PartialEq)]
 pub struct Debouncer {
     last_updated: Instant,
-    time: f32,
+    threshold: f32,
 }
 
 impl Debouncer {
-    pub fn new(time: f32) -> Self {
+    pub fn new(threshold: f32) -> Self {
         Self {
-            time,
+            threshold,
             last_updated: Instant::now(),
         }
     }
 
     pub fn should_update(&mut self) -> bool {
         let elapsed_time = self.last_updated.elapsed().as_secs_f32();
-        if elapsed_time > self.time {
+        if elapsed_time > self.threshold {
             self.last_updated = Instant::now();
 
             return true;
diff --git a/kayak_core/src/context.rs b/kayak_core/src/context.rs
index a39d73a..f5b94f7 100644
--- a/kayak_core/src/context.rs
+++ b/kayak_core/src/context.rs
@@ -11,10 +11,11 @@ pub struct KayakContext {
     global_bindings: HashMap<crate::Index, Vec<flo_binding::Uuid>>,
     widget_state_lifetimes:
         HashMap<crate::Index, HashMap<flo_binding::Uuid, Box<dyn crate::Releasable>>>,
-    pub current_id: Index,
+    current_id: Index,
+    // TODO: Make widget_manager private.
     pub widget_manager: WidgetManager,
     last_mouse_position: (f32, f32),
-    pub global_state: resources::Resources,
+    global_state: resources::Resources,
     previous_events: HashMap<Index, Option<EventType>>,
     current_focus: Index,
     last_focus: Index,
diff --git a/kayak_core/src/lib.rs b/kayak_core/src/lib.rs
index 95f4d48..cee43bb 100644
--- a/kayak_core/src/lib.rs
+++ b/kayak_core/src/lib.rs
@@ -7,6 +7,7 @@ pub(crate) mod generational_arena;
 mod input_event;
 mod keys;
 pub mod layout_cache;
+mod multi_state;
 pub mod node;
 pub mod render_command;
 pub mod render_primitive;
@@ -15,7 +16,6 @@ pub mod tree;
 mod vec;
 pub mod widget;
 pub mod widget_manager;
-mod multi_state;
 
 use std::sync::{Arc, RwLock};
 
@@ -52,21 +52,6 @@ impl OnEvent {
     }
 }
 
-// impl std::ops::Deref for OnEvent {
-//     type Target =
-//         Arc<RwLock<dyn FnMut(&mut crate::context::KayakContext, &mut Event) + Send + Sync>>;
-
-//     fn deref(&self) -> &Self::Target {
-//         &self.0
-//     }
-// }
-
-// impl std::ops::DerefMut for OnEvent {
-//     fn deref_mut(&mut self) -> &mut Self::Target {
-//         &mut self.0
-//     }
-// }
-
 pub mod derivative {
     pub use derivative::*;
 }
diff --git a/kayak_core/src/render_command.rs b/kayak_core/src/render_command.rs
index d0c4b51..c8ebc25 100644
--- a/kayak_core/src/render_command.rs
+++ b/kayak_core/src/render_command.rs
@@ -3,7 +3,6 @@ use crate::layout_cache::Space;
 #[derive(Debug, Clone, PartialEq)]
 pub enum RenderCommand {
     Empty,
-    Window,
     /// Represents a node that has no renderable object but contributes to the layout.
     Layout,
     Clip,
diff --git a/kayak_core/src/render_primitive.rs b/kayak_core/src/render_primitive.rs
index 732a867..0fa313e 100644
--- a/kayak_core/src/render_primitive.rs
+++ b/kayak_core/src/render_primitive.rs
@@ -58,7 +58,6 @@ impl From<&Style> for RenderPrimitive {
         };
 
         match render_command {
-            RenderCommand::Window => Self::Empty,
             RenderCommand::Empty => Self::Empty,
             RenderCommand::Layout => Self::Empty,
             RenderCommand::Clip => Self::Clip {
diff --git a/kayak_widgets/src/app.rs b/kayak_widgets/src/app.rs
index a77f39d..b19bc64 100644
--- a/kayak_widgets/src/app.rs
+++ b/kayak_widgets/src/app.rs
@@ -12,7 +12,7 @@ use crate::Clip;
 #[widget]
 pub fn App(children: Children) {
     *styles = Some(Style {
-        render_command: StyleProp::Value(RenderCommand::Window),
+        render_command: StyleProp::Value(RenderCommand::Layout),
         ..styles.clone().unwrap_or_default()
     });
 
diff --git a/kayak_widgets/src/text_box.rs b/kayak_widgets/src/text_box.rs
index 8660e7a..0da96fe 100644
--- a/kayak_widgets/src/text_box.rs
+++ b/kayak_widgets/src/text_box.rs
@@ -53,9 +53,9 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) {
         ..styles.clone().unwrap_or_default()
     };
 
-    let internal_value = context.create_state("".to_string()).unwrap();
     let has_focus = context.create_state(Focus(false)).unwrap();
 
+    let mut current_value = value.clone();
     let cloned_on_change = on_change.clone();
     let cloned_has_focus = has_focus.clone();
     self.on_event = Some(OnEvent::new(move |_, event| match event.event_type {
@@ -63,7 +63,6 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) {
             if !cloned_has_focus.get().0 {
                 return;
             }
-            let mut current_value = internal_value.get();
             if c == '\u{8}' {
                 if current_value.len() > 0 {
                     current_value.truncate(current_value.len() - 1);
@@ -78,22 +77,12 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) {
                     });
                 }
             }
-            internal_value.set(current_value);
         }
         EventType::Focus => cloned_has_focus.set(Focus(true)),
         EventType::Blur => cloned_has_focus.set(Focus(false)),
         _ => {}
     }));
 
-    // let cloned_has_focus = has_focus.clone();
-    // let on_event = Some(OnEvent::new(move |_, event| match event.event_type {
-    //     EventType::Focus => {
-    //         dbg!("Has focus!");
-    //         cloned_has_focus.set(Focus(true))
-    //     }
-    //     _ => {}
-    // }));
-
     let value = value.clone();
     rsx! {
         <Background styles={Some(background_styles)}>
-- 
GitLab