Skip to content
Snippets Groups Projects
Commit dc7892ed authored by StarArawn's avatar StarArawn
Browse files

Lots of cleanup.

parent 7400b605
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,9 @@ use kayak_widgets::{App, OnChange, TextBox, Window}; ...@@ -13,7 +13,9 @@ use kayak_widgets::{App, OnChange, TextBox, Window};
#[widget] #[widget]
fn TextBoxExample(context: &mut KayakContext) { 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 value2 = context.create_state("".to_string()).unwrap();
let input_styles = Style { let input_styles = Style {
......
...@@ -5,20 +5,20 @@ pub use flo_binding::{bind, notify, Binding, Bound, Changeable, MutableBound, Re ...@@ -5,20 +5,20 @@ pub use flo_binding::{bind, notify, Binding, Bound, Changeable, MutableBound, Re
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Debouncer { pub struct Debouncer {
last_updated: Instant, last_updated: Instant,
time: f32, threshold: f32,
} }
impl Debouncer { impl Debouncer {
pub fn new(time: f32) -> Self { pub fn new(threshold: f32) -> Self {
Self { Self {
time, threshold,
last_updated: Instant::now(), last_updated: Instant::now(),
} }
} }
pub fn should_update(&mut self) -> bool { pub fn should_update(&mut self) -> bool {
let elapsed_time = self.last_updated.elapsed().as_secs_f32(); 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(); self.last_updated = Instant::now();
return true; return true;
......
...@@ -11,10 +11,11 @@ pub struct KayakContext { ...@@ -11,10 +11,11 @@ pub struct KayakContext {
global_bindings: HashMap<crate::Index, Vec<flo_binding::Uuid>>, global_bindings: HashMap<crate::Index, Vec<flo_binding::Uuid>>,
widget_state_lifetimes: widget_state_lifetimes:
HashMap<crate::Index, HashMap<flo_binding::Uuid, Box<dyn crate::Releasable>>>, 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, pub widget_manager: WidgetManager,
last_mouse_position: (f32, f32), last_mouse_position: (f32, f32),
pub global_state: resources::Resources, global_state: resources::Resources,
previous_events: HashMap<Index, Option<EventType>>, previous_events: HashMap<Index, Option<EventType>>,
current_focus: Index, current_focus: Index,
last_focus: Index, last_focus: Index,
......
...@@ -7,6 +7,7 @@ pub(crate) mod generational_arena; ...@@ -7,6 +7,7 @@ pub(crate) mod generational_arena;
mod input_event; mod input_event;
mod keys; mod keys;
pub mod layout_cache; pub mod layout_cache;
mod multi_state;
pub mod node; pub mod node;
pub mod render_command; pub mod render_command;
pub mod render_primitive; pub mod render_primitive;
...@@ -15,7 +16,6 @@ pub mod tree; ...@@ -15,7 +16,6 @@ pub mod tree;
mod vec; mod vec;
pub mod widget; pub mod widget;
pub mod widget_manager; pub mod widget_manager;
mod multi_state;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
...@@ -52,21 +52,6 @@ impl OnEvent { ...@@ -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 mod derivative {
pub use derivative::*; pub use derivative::*;
} }
...@@ -3,7 +3,6 @@ use crate::layout_cache::Space; ...@@ -3,7 +3,6 @@ use crate::layout_cache::Space;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum RenderCommand { pub enum RenderCommand {
Empty, Empty,
Window,
/// Represents a node that has no renderable object but contributes to the layout. /// Represents a node that has no renderable object but contributes to the layout.
Layout, Layout,
Clip, Clip,
......
...@@ -58,7 +58,6 @@ impl From<&Style> for RenderPrimitive { ...@@ -58,7 +58,6 @@ impl From<&Style> for RenderPrimitive {
}; };
match render_command { match render_command {
RenderCommand::Window => Self::Empty,
RenderCommand::Empty => Self::Empty, RenderCommand::Empty => Self::Empty,
RenderCommand::Layout => Self::Empty, RenderCommand::Layout => Self::Empty,
RenderCommand::Clip => Self::Clip { RenderCommand::Clip => Self::Clip {
......
...@@ -12,7 +12,7 @@ use crate::Clip; ...@@ -12,7 +12,7 @@ use crate::Clip;
#[widget] #[widget]
pub fn App(children: Children) { pub fn App(children: Children) {
*styles = Some(Style { *styles = Some(Style {
render_command: StyleProp::Value(RenderCommand::Window), render_command: StyleProp::Value(RenderCommand::Layout),
..styles.clone().unwrap_or_default() ..styles.clone().unwrap_or_default()
}); });
......
...@@ -53,9 +53,9 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) { ...@@ -53,9 +53,9 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) {
..styles.clone().unwrap_or_default() ..styles.clone().unwrap_or_default()
}; };
let internal_value = context.create_state("".to_string()).unwrap();
let has_focus = context.create_state(Focus(false)).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_on_change = on_change.clone();
let cloned_has_focus = has_focus.clone(); let cloned_has_focus = has_focus.clone();
self.on_event = Some(OnEvent::new(move |_, event| match event.event_type { 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>) { ...@@ -63,7 +63,6 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) {
if !cloned_has_focus.get().0 { if !cloned_has_focus.get().0 {
return; return;
} }
let mut current_value = internal_value.get();
if c == '\u{8}' { if c == '\u{8}' {
if current_value.len() > 0 { if current_value.len() > 0 {
current_value.truncate(current_value.len() - 1); current_value.truncate(current_value.len() - 1);
...@@ -78,22 +77,12 @@ pub fn TextBox(value: String, on_change: Option<OnChange>) { ...@@ -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::Focus => cloned_has_focus.set(Focus(true)),
EventType::Blur => cloned_has_focus.set(Focus(false)), 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(); let value = value.clone();
rsx! { rsx! {
<Background styles={Some(background_styles)}> <Background styles={Some(background_styles)}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment