Skip to content
Snippets Groups Projects
Unverified Commit 68d56a11 authored by Ygg01's avatar Ygg01
Browse files

Refactor on_change to shared function

parent bd9786d5
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ mod if_element; ...@@ -8,6 +8,7 @@ mod if_element;
mod image; mod image;
mod inspector; mod inspector;
mod nine_patch; mod nine_patch;
mod on_change;
mod scroll; mod scroll;
mod text; mod text;
mod text_box; mod text_box;
...@@ -24,6 +25,7 @@ pub use if_element::*; ...@@ -24,6 +25,7 @@ pub use if_element::*;
pub use image::*; pub use image::*;
pub use inspector::*; pub use inspector::*;
pub use nine_patch::*; pub use nine_patch::*;
pub use on_change::*;
pub use scroll::*; pub use scroll::*;
pub use text::*; pub use text::*;
pub use text_box::*; pub use text_box::*;
......
use std::sync::{Arc, RwLock};
#[derive(Debug, Clone, PartialEq)]
pub struct ChangeEvent {
pub value: String,
}
#[derive(Clone)]
pub struct OnChange(pub Arc<RwLock<dyn FnMut(ChangeEvent) + Send + Sync + 'static>>);
impl OnChange {
pub fn new<F: FnMut(ChangeEvent) + Send + Sync + 'static>(f: F) -> OnChange {
OnChange(Arc::new(RwLock::new(f)))
}
}
impl PartialEq for OnChange {
fn eq(&self, _other: &Self) -> bool {
true
}
}
impl std::fmt::Debug for OnChange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("OnChange").finish()
}
}
\ No newline at end of file
use crate::core::{ use crate::{core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, rsx,
styles::{Corner, Style, Units}, styles::{Corner, Style, Units},
widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps, widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps,
}; }, widgets::ChangeEvent};
use kayak_core::{CursorIcon, OnLayout}; use kayak_core::{CursorIcon, OnLayout};
use std::sync::{Arc, RwLock};
use crate::widgets::{Background, Clip, Text}; use crate::widgets::{Background, Clip, Text, OnChange};
/// Props used by the [`TextBox`] widget /// Props used by the [`TextBox`] widget
#[derive(Default, Debug, PartialEq, Clone)] #[derive(Default, Debug, PartialEq, Clone)]
...@@ -56,32 +55,6 @@ impl WidgetProps for TextBoxProps { ...@@ -56,32 +55,6 @@ impl WidgetProps for TextBoxProps {
} }
} }
#[derive(Debug, Clone, PartialEq)]
pub struct ChangeEvent {
pub value: String,
}
#[derive(Clone)]
pub struct OnChange(pub Arc<RwLock<dyn FnMut(ChangeEvent) + Send + Sync + 'static>>);
impl OnChange {
pub fn new<F: FnMut(ChangeEvent) + Send + Sync + 'static>(f: F) -> OnChange {
OnChange(Arc::new(RwLock::new(f)))
}
}
impl PartialEq for OnChange {
fn eq(&self, _other: &Self) -> bool {
true
}
}
impl std::fmt::Debug for OnChange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("OnChange").finish()
}
}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Focus(pub bool); pub struct Focus(pub bool);
......
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