From f23a44a4c5279ecbdcd2872fbaa662cd79c45fcb Mon Sep 17 00:00:00 2001 From: MrGVSV <gino.valente.code@gmail.com> Date: Fri, 4 Feb 2022 14:22:11 -0800 Subject: [PATCH] Formatting --- examples/counter.rs | 4 +-- examples/fold.rs | 4 +-- examples/full_ui.rs | 6 ++--- examples/global_counter.rs | 2 +- examples/hooks.rs | 2 +- examples/if.rs | 4 +-- examples/provider.rs | 13 +++++---- examples/tabs/tab.rs | 8 +++--- examples/tabs/tab_bar.rs | 13 ++++++--- examples/tabs/tab_box.rs | 8 +++--- examples/tabs/tab_content.rs | 4 +-- examples/tabs/tabs.rs | 4 +-- examples/tabs/theming.rs | 9 ++++--- examples/text_box.rs | 4 +-- examples/todo/add_button.rs | 4 +-- examples/todo/card.rs | 10 ++++--- examples/todo/delete_button.rs | 4 +-- examples/todo/todo.rs | 4 +-- examples/world_interaction.rs | 4 +-- kayak_core/src/children.rs | 8 +++--- kayak_core/src/context_ref.rs | 6 +---- kayak_core/src/event_dispatcher.rs | 5 +++- kayak_core/src/fragment.rs | 9 +++++-- kayak_core/src/lib.rs | 4 +-- kayak_core/src/on_event.rs | 14 +++------- kayak_core/src/vec.rs | 23 +++++++++------- kayak_core/src/widget.rs | 27 ++++++++++++++----- kayak_core/src/widget_manager.rs | 12 ++++++++- kayak_render_macros/src/children.rs | 10 +++++-- kayak_render_macros/src/function_component.rs | 19 +++++++------ kayak_render_macros/src/tags.rs | 2 +- kayak_render_macros/src/use_effect.rs | 2 +- kayak_render_macros/src/widget.rs | 7 +++-- kayak_render_macros/src/widget_attributes.rs | 9 +++---- kayak_render_macros/src/widget_builder.rs | 1 - kayak_render_macros/src/widget_props.rs | 17 +++++++----- src/lib.rs | 4 ++- src/widgets/app.rs | 8 ++---- src/widgets/background.rs | 7 ++--- src/widgets/button.rs | 7 ++--- src/widgets/clip.rs | 6 ++--- src/widgets/element.rs | 7 ++--- src/widgets/fold.rs | 15 ++++++----- src/widgets/if_element.rs | 9 +------ src/widgets/image.rs | 11 ++++---- src/widgets/inspector.rs | 3 +-- src/widgets/nine_patch.rs | 14 +++++----- src/widgets/text.rs | 13 +++++---- src/widgets/text_box.rs | 14 +++++----- src/widgets/tooltip.rs | 14 +++++----- src/widgets/window.rs | 15 ++++++----- 51 files changed, 237 insertions(+), 196 deletions(-) diff --git a/examples/counter.rs b/examples/counter.rs index a301e4c..303de77 100644 --- a/examples/counter.rs +++ b/examples/counter.rs @@ -5,9 +5,9 @@ use bevy::{ }; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::core::{ - render, rsx, WidgetProps, + render, rsx, styles::{Style, StyleProp, Units}, - use_state, widget, EventType, Index, OnEvent, + use_state, widget, EventType, Index, OnEvent, WidgetProps, }; use kayak_ui::widgets::{App, Button, Text, Window}; diff --git a/examples/fold.rs b/examples/fold.rs index f88ed60..4fce8f5 100644 --- a/examples/fold.rs +++ b/examples/fold.rs @@ -7,9 +7,9 @@ use bevy::{ use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, core::{ - render, rsx, WidgetProps, + render, rsx, styles::{Style, StyleProp, Units}, - use_state, widget, Color, EventType, Handler, Index, OnEvent, + use_state, widget, Color, EventType, Handler, Index, OnEvent, WidgetProps, }, widgets::{App, Background, Button, Fold, If, Text, Window}, }; diff --git a/examples/full_ui.rs b/examples/full_ui.rs index 2208c49..3b3bc35 100644 --- a/examples/full_ui.rs +++ b/examples/full_ui.rs @@ -6,9 +6,9 @@ use bevy::{ use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, ImageManager, UICameraBundle}; use kayak_ui::core::{ layout_cache::Space, - render, rsx, WidgetProps, + render, rsx, styles::{LayoutType, Style, StyleProp, Units}, - widget, Bound, Children, EventType, Index, MutableBound, OnEvent, + widget, Bound, Children, EventType, Index, MutableBound, OnEvent, WidgetProps, }; use kayak_ui::widgets::{App, NinePatch, Text}; @@ -17,7 +17,7 @@ struct BlueButtonProps { #[prop_field(Styles)] styles: Option<Style>, #[prop_field(Children)] - children: Option<Children> + children: Option<Children>, } #[widget] diff --git a/examples/global_counter.rs b/examples/global_counter.rs index e2fbb7e..12f757b 100644 --- a/examples/global_counter.rs +++ b/examples/global_counter.rs @@ -4,7 +4,7 @@ use bevy::{ DefaultPlugins, }; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; -use kayak_ui::core::{bind, render, rsx, widget, WidgetProps, Binding, Bound, Index, MutableBound}; +use kayak_ui::core::{bind, render, rsx, widget, Binding, Bound, Index, MutableBound, WidgetProps}; use kayak_ui::widgets::{App, Text, Window}; #[derive(Clone, PartialEq)] diff --git a/examples/hooks.rs b/examples/hooks.rs index a85973d..72b5fb4 100644 --- a/examples/hooks.rs +++ b/examples/hooks.rs @@ -16,7 +16,7 @@ use bevy::{ }; use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, - core::{render, rsx, use_effect, use_state, widget, WidgetProps, EventType, Index, OnEvent}, + core::{render, rsx, use_effect, use_state, widget, EventType, Index, OnEvent, WidgetProps}, widgets::{App, Button, Text, Window}, }; diff --git a/examples/if.rs b/examples/if.rs index 7120ce9..b123b26 100644 --- a/examples/if.rs +++ b/examples/if.rs @@ -5,9 +5,9 @@ use bevy::{ }; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::core::{ - render, rsx, WidgetProps, + render, rsx, styles::{Style, StyleProp, Units}, - widget, Bound, EventType, Index, MutableBound, OnEvent, + widget, Bound, EventType, Index, MutableBound, OnEvent, WidgetProps, }; use kayak_ui::widgets::{App, Button, If, Text, Window}; diff --git a/examples/provider.rs b/examples/provider.rs index 8a39f05..97afd7c 100644 --- a/examples/provider.rs +++ b/examples/provider.rs @@ -13,17 +13,17 @@ use bevy::prelude::{ App as BevyApp, AssetServer, Commands, DefaultPlugins, Res, ResMut, WindowDescriptor, }; +use kayak_core::Children; use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, core::{ - render, rsx, WidgetProps, + render, rsx, styles::{LayoutType, Style, StyleProp, Units}, - widget, Bound, Color, EventType, Index, MutableBound, OnEvent, + widget, Bound, Color, EventType, Index, MutableBound, OnEvent, WidgetProps, }, widgets::{App, Background, Element, If, Text, TooltipConsumer, TooltipProvider, Window}, }; use std::sync::Arc; -use kayak_core::Children; /// The color theme struct we will be using across our demo widgets #[derive(Debug, Default, Clone, PartialEq)] @@ -74,7 +74,10 @@ struct ThemeProviderProps { /// It can also be nested within itself, allowing for differing provider values. #[widget] fn ThemeProvider(props: ThemeProviderProps) { - let ThemeProviderProps { initial_theme, children } = props.clone(); + let ThemeProviderProps { + initial_theme, + children, + } = props.clone(); // Create the provider context.create_provider(initial_theme); rsx! { <>{children}</> } @@ -166,7 +169,7 @@ fn ThemeSelector(props: ThemeSelectorProps) { #[derive(WidgetProps, Clone, Debug, Default, PartialEq)] struct ThemeDemoProps { - is_root: bool + is_root: bool, } /// A widget that demonstrates the theming in action diff --git a/examples/tabs/tab.rs b/examples/tabs/tab.rs index dd2eeae..428c55a 100644 --- a/examples/tabs/tab.rs +++ b/examples/tabs/tab.rs @@ -1,9 +1,9 @@ use kayak_ui::{ core::{ render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{LayoutType, Style, StyleProp, Units}, - use_state, widget, Bound, EventType, OnEvent, + use_state, widget, Bound, EventType, OnEvent, WidgetProps, }, widgets::{Background, Text}, }; @@ -30,7 +30,9 @@ pub struct TabProps { /// The actual tab, displayed in a [TabBar](crate::tab_bar::TabBar) #[widget] pub fn Tab(props: TabProps) { - let TabProps{content, selected, ..} = props.clone(); + let TabProps { + content, selected, .. + } = props.clone(); let theme = context.create_consumer::<TabTheme>().unwrap_or_default(); let (focus_state, set_focus_state, ..) = use_state!(false); diff --git a/examples/tabs/tab_bar.rs b/examples/tabs/tab_bar.rs index b382ea6..083e415 100644 --- a/examples/tabs/tab_bar.rs +++ b/examples/tabs/tab_bar.rs @@ -1,8 +1,8 @@ use kayak_ui::{ core::{ - constructor, rsx, WidgetProps, + constructor, rsx, styles::{LayoutType, Style, StyleProp, Units}, - widget, Bound, EventType, Handler, KeyCode, OnEvent, VecTracker, + widget, Bound, EventType, Handler, KeyCode, OnEvent, VecTracker, WidgetProps, }, widgets::Background, }; @@ -16,13 +16,18 @@ pub struct TabBarProps { pub selected: usize, pub on_select_tab: Handler<usize>, #[prop_field(Styles)] - pub styles: Option<Style> + pub styles: Option<Style>, } /// A widget displaying a collection of tabs in a horizontal bar #[widget] pub fn TabBar(props: TabBarProps) { - let TabBarProps{on_select_tab, selected, tabs, ..} = props.clone(); + let TabBarProps { + on_select_tab, + selected, + tabs, + .. + } = props.clone(); let theme = context.create_consumer::<TabTheme>().unwrap_or_default(); let tabs = tabs.into_iter().enumerate().map(move |(index, tab)| { diff --git a/examples/tabs/tab_box.rs b/examples/tabs/tab_box.rs index 4131307..8de0c47 100644 --- a/examples/tabs/tab_box.rs +++ b/examples/tabs/tab_box.rs @@ -1,8 +1,8 @@ use kayak_ui::core::{ render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - use_state, widget, Bound, Fragment, Handler, + use_state, widget, Bound, Fragment, Handler, WidgetProps, }; use std::fmt::Debug; @@ -31,7 +31,9 @@ pub struct TabBoxProps { /// This houses both the tab bar and its content. #[widget] pub fn TabBox(props: TabBoxProps) { - let TabBoxProps { initial_tab, tabs, .. } = props.clone(); + let TabBoxProps { + initial_tab, tabs, .. + } = props.clone(); let theme = context.create_consumer::<TabTheme>().unwrap_or_default(); let (selected, set_selected, ..) = use_state!(initial_tab); diff --git a/examples/tabs/tab_content.rs b/examples/tabs/tab_content.rs index afae825..3d3c4da 100644 --- a/examples/tabs/tab_content.rs +++ b/examples/tabs/tab_content.rs @@ -1,8 +1,8 @@ use kayak_ui::core::{ render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - widget, Bound, Fragment, VecTracker, + widget, Bound, Fragment, VecTracker, WidgetProps, }; use std::ops::Index; diff --git a/examples/tabs/tabs.rs b/examples/tabs/tabs.rs index 04e9b3d..7fd216c 100644 --- a/examples/tabs/tabs.rs +++ b/examples/tabs/tabs.rs @@ -13,9 +13,9 @@ use bevy::{ use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, core::{ - constructor, render, rsx, WidgetProps, + constructor, render, rsx, styles::{Style, StyleProp, Units}, - widget, Color, Index, + widget, Color, Index, WidgetProps, }, widgets::{App, Text, Window}, }; diff --git a/examples/tabs/theming.rs b/examples/tabs/theming.rs index 41f3f29..e8feaa4 100644 --- a/examples/tabs/theming.rs +++ b/examples/tabs/theming.rs @@ -1,4 +1,4 @@ -use kayak_ui::core::{Children, rsx, widget, Color, WidgetProps}; +use kayak_ui::core::{rsx, widget, Children, Color, WidgetProps}; #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct TabTheme { @@ -23,12 +23,15 @@ pub struct ColorState { pub struct TabThemeProviderProps { pub initial_theme: TabTheme, #[prop_field(Children)] - pub children: Option<Children> + pub children: Option<Children>, } #[widget] pub fn TabThemeProvider(props: TabThemeProviderProps) { - let TabThemeProviderProps { initial_theme, children } = props.clone(); + let TabThemeProviderProps { + initial_theme, + children, + } = props.clone(); context.create_provider(initial_theme); rsx! { <>{children}</> } } diff --git a/examples/text_box.rs b/examples/text_box.rs index bfaf2fc..c98a8a4 100644 --- a/examples/text_box.rs +++ b/examples/text_box.rs @@ -7,9 +7,9 @@ use kayak_core::Color; use kayak_render_macros::use_state; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::core::{ - render, rsx, WidgetProps, + render, rsx, styles::{Style, StyleProp, Units}, - widget, Index, + widget, Index, WidgetProps, }; use kayak_ui::widgets::{App, OnChange, TextBox, Window}; diff --git a/examples/todo/add_button.rs b/examples/todo/add_button.rs index d6143fa..905256a 100644 --- a/examples/todo/add_button.rs +++ b/examples/todo/add_button.rs @@ -1,9 +1,9 @@ use kayak_ui::core::{ color::Color, render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - use_state, widget, EventType, OnEvent, + use_state, widget, EventType, OnEvent, WidgetProps, }; use kayak_ui::widgets::{Background, Text}; diff --git a/examples/todo/card.rs b/examples/todo/card.rs index b9b0618..790a2d8 100644 --- a/examples/todo/card.rs +++ b/examples/todo/card.rs @@ -1,7 +1,7 @@ use kayak_ui::core::{ - rsx, WidgetProps, + rsx, styles::{LayoutType, Style, StyleProp, Units}, - widget, Color, EventType, Handler, OnEvent, + widget, Color, EventType, Handler, OnEvent, WidgetProps, }; use kayak_ui::widgets::{Background, Text}; @@ -16,7 +16,11 @@ pub struct CardProps { #[widget] pub fn Card(props: CardProps) { - let CardProps{card_id, name, on_delete} = props.clone(); + let CardProps { + card_id, + name, + on_delete, + } = props.clone(); let background_styles = Style { layout_type: StyleProp::Value(LayoutType::Row), background_color: StyleProp::Value(Color::new(0.176, 0.196, 0.215, 1.0)), diff --git a/examples/todo/delete_button.rs b/examples/todo/delete_button.rs index 34d5729..86bb007 100644 --- a/examples/todo/delete_button.rs +++ b/examples/todo/delete_button.rs @@ -1,9 +1,9 @@ use kayak_ui::core::{ color::Color, render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - use_state, widget, EventType, OnEvent, + use_state, widget, EventType, OnEvent, WidgetProps, }; use kayak_ui::widgets::{Background, Text}; diff --git a/examples/todo/todo.rs b/examples/todo/todo.rs index 95b063c..10ee013 100644 --- a/examples/todo/todo.rs +++ b/examples/todo/todo.rs @@ -5,9 +5,9 @@ use bevy::{ }; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::core::{ - render, rsx, WidgetProps, + render, rsx, styles::{LayoutType, Style, StyleProp, Units}, - use_state, widget, EventType, Handler, Index, OnEvent, + use_state, widget, EventType, Handler, Index, OnEvent, WidgetProps, }; use kayak_ui::widgets::{App, Element, OnChange, TextBox, Window}; diff --git a/examples/world_interaction.rs b/examples/world_interaction.rs index 9663309..44a1f14 100644 --- a/examples/world_interaction.rs +++ b/examples/world_interaction.rs @@ -18,9 +18,9 @@ use bevy::{ use kayak_ui::{ bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, core::{ - render, rsx, WidgetProps, + render, rsx, styles::{Style, StyleProp, Units}, - use_state, widget, EventType, Index, OnEvent, + use_state, widget, EventType, Index, OnEvent, WidgetProps, }, widgets::{App, Button, Text, Window}, }; diff --git a/kayak_core/src/children.rs b/kayak_core/src/children.rs index 3bb67f6..7388874 100644 --- a/kayak_core/src/children.rs +++ b/kayak_core/src/children.rs @@ -1,13 +1,15 @@ +use crate::{Index, KayakContextRef}; use std::fmt::{Debug, Formatter}; use std::sync::Arc; -use crate::{Index, KayakContextRef}; /// A container for a function that generates child widgets #[derive(Clone)] pub struct Children(Arc<dyn Fn(Option<Index>, &mut KayakContextRef) + Send + Sync>); impl Children { - pub fn new<F: Fn(Option<Index>, &mut KayakContextRef) + Send + Sync + 'static>(builder: F) -> Self { + pub fn new<F: Fn(Option<Index>, &mut KayakContextRef) + Send + Sync + 'static>( + builder: F, + ) -> Self { Self(Arc::new(builder)) } pub fn build(&self, id: Option<Index>, context: &mut KayakContextRef) { @@ -26,4 +28,4 @@ impl PartialEq for Children { // Never prevent "==" for being true because of this struct true } -} \ No newline at end of file +} diff --git a/kayak_core/src/context_ref.rs b/kayak_core/src/context_ref.rs index 534b5b8..b0710db 100644 --- a/kayak_core/src/context_ref.rs +++ b/kayak_core/src/context_ref.rs @@ -228,11 +228,7 @@ impl<'a> KayakContextRef<'a> { /// Adds a widget to the context reference tree that will be committed to the main tree when `commit` is called. /// This also adds the widget to the `KayakContext` and renders the new widget. - pub fn add_widget<W: crate::Widget>( - &mut self, - widget: W, - widget_index: usize, - ) { + pub fn add_widget<W: crate::Widget>(&mut self, widget: W, widget_index: usize) { let (_, child_id) = self.context .widget_manager diff --git a/kayak_core/src/event_dispatcher.rs b/kayak_core/src/event_dispatcher.rs index 2b02c47..6bf35bf 100644 --- a/kayak_core/src/event_dispatcher.rs +++ b/kayak_core/src/event_dispatcher.rs @@ -4,7 +4,10 @@ use crate::cursor::CursorEvent; use crate::layout_cache::Rect; use crate::render_command::RenderCommand; use crate::widget_manager::WidgetManager; -use crate::{Event, EventType, Index, InputEvent, InputEventCategory, KayakContext, KeyCode, KeyboardEvent, KeyboardModifiers, PointerEvents, BoxedWidget}; +use crate::{ + BoxedWidget, Event, EventType, Index, InputEvent, InputEventCategory, KayakContext, KeyCode, + KeyboardEvent, KeyboardModifiers, PointerEvents, +}; use std::collections::{HashMap, HashSet}; type EventMap = HashMap<Index, HashSet<EventType>>; diff --git a/kayak_core/src/fragment.rs b/kayak_core/src/fragment.rs index 16043d6..2815138 100644 --- a/kayak_core/src/fragment.rs +++ b/kayak_core/src/fragment.rs @@ -1,4 +1,6 @@ -use crate::{context_ref::KayakContextRef, styles::Style, Index, Widget, WidgetProps, Children, OnEvent}; +use crate::{ + context_ref::KayakContextRef, styles::Style, Children, Index, OnEvent, Widget, WidgetProps, +}; #[derive(Default, Debug, PartialEq, Clone)] pub struct FragmentProps { @@ -37,7 +39,10 @@ impl WidgetProps for FragmentProps { impl Widget for Fragment { type Props = FragmentProps; - fn constructor(props: Self::Props) -> Self where Self: Sized { + fn constructor(props: Self::Props) -> Self + where + Self: Sized, + { Self { id: Index::default(), props, diff --git a/kayak_core/src/lib.rs b/kayak_core/src/lib.rs index 2db69fe..ad41006 100644 --- a/kayak_core/src/lib.rs +++ b/kayak_core/src/lib.rs @@ -1,5 +1,6 @@ mod assets; mod binding; +mod children; pub mod color; pub mod context; mod context_ref; @@ -16,6 +17,7 @@ mod keys; pub mod layout_cache; mod multi_state; pub mod node; +mod on_event; pub mod render_command; pub mod render_primitive; pub mod styles; @@ -23,8 +25,6 @@ pub mod tree; mod vec; pub mod widget; pub mod widget_manager; -mod children; -mod on_event; use std::sync::{Arc, RwLock}; diff --git a/kayak_core/src/on_event.rs b/kayak_core/src/on_event.rs index c2fcb26..fe66509 100644 --- a/kayak_core/src/on_event.rs +++ b/kayak_core/src/on_event.rs @@ -1,14 +1,10 @@ +use crate::{Event, KayakContext}; use std::fmt::{Debug, Formatter}; use std::sync::{Arc, RwLock}; -use crate::{Event, KayakContext}; /// A container for a function that handles events #[derive(Clone)] -pub struct OnEvent( - Arc< - RwLock<dyn FnMut(&mut KayakContext, &mut Event) + Send + Sync + 'static>, - >, -); +pub struct OnEvent(Arc<RwLock<dyn FnMut(&mut KayakContext, &mut Event) + Send + Sync + 'static>>); impl OnEvent { /// Create a new event handler @@ -16,9 +12,7 @@ impl OnEvent { /// The handler should be a closure that takes the following arguments: /// 1. The current context /// 2. The event - pub fn new<F: FnMut(&mut KayakContext, &mut Event) + Send + Sync + 'static>( - f: F, - ) -> OnEvent { + pub fn new<F: FnMut(&mut KayakContext, &mut Event) + Send + Sync + 'static>(f: F) -> OnEvent { OnEvent(Arc::new(RwLock::new(f))) } @@ -46,4 +40,4 @@ impl PartialEq for OnEvent { // Never prevent "==" for being true because of this struct true } -} \ No newline at end of file +} diff --git a/kayak_core/src/vec.rs b/kayak_core/src/vec.rs index 4a3142c..502a935 100644 --- a/kayak_core/src/vec.rs +++ b/kayak_core/src/vec.rs @@ -1,4 +1,6 @@ -use crate::{context_ref::KayakContextRef, styles::Style, Index, Widget, Children, OnEvent, WidgetProps}; +use crate::{ + context_ref::KayakContextRef, styles::Style, Children, Index, OnEvent, Widget, WidgetProps, +}; #[derive(Default, Debug, PartialEq, Clone)] pub struct VecTrackerProps<T> { @@ -31,8 +33,8 @@ impl<T> VecTracker<T> { } impl<T, I> From<I> for VecTracker<T> - where - I: Iterator<Item=T>, +where + I: Iterator<Item = T>, { fn from(iter: I) -> Self { Self::new(iter.collect()) @@ -40,9 +42,9 @@ impl<T, I> From<I> for VecTracker<T> } impl<T> WidgetProps for VecTrackerProps<T> - where - T: Widget, { - +where + T: Widget, +{ fn get_children(&self) -> Option<Children> { self.children.clone() } @@ -65,12 +67,15 @@ impl<T> WidgetProps for VecTrackerProps<T> } impl<T> Widget for VecTracker<T> - where - T: Widget, +where + T: Widget, { type Props = VecTrackerProps<T>; - fn constructor(props: Self::Props) -> Self where Self: Sized { + fn constructor(props: Self::Props) -> Self + where + Self: Sized, + { Self { id: Index::default(), props, diff --git a/kayak_core/src/widget.rs b/kayak_core/src/widget.rs index a706535..4535d55 100644 --- a/kayak_core/src/widget.rs +++ b/kayak_core/src/widget.rs @@ -1,7 +1,10 @@ -use std::any::Any; use as_any::AsAny; +use std::any::Any; -use crate::{context::KayakContext, context_ref::KayakContextRef, styles::Style, Event, Index, OnEvent, Children}; +use crate::{ + context::KayakContext, context_ref::KayakContextRef, styles::Style, Children, Event, Index, + OnEvent, +}; /// An internal trait that has a blanket implementation over all implementors of [Widget] /// @@ -14,7 +17,9 @@ pub trait SealedWidget {} /// You should _never_ implement BaseWidget manually. It is automatically implemented on /// all implementors of [Widget]. pub trait BaseWidget: SealedWidget + std::fmt::Debug + Send + Sync { - fn constructor<P: WidgetProps>(props: P) -> Self where Self: Sized; + fn constructor<P: WidgetProps>(props: P) -> Self + where + Self: Sized; fn get_id(&self) -> Index; fn set_id(&mut self, id: Index); fn get_props(&self) -> &dyn WidgetProps; @@ -29,7 +34,9 @@ pub trait Widget: std::fmt::Debug + Clone + Default + PartialEq + AsAny + Send + type Props: WidgetProps + Clone + Default + PartialEq; /// Construct the widget with the given props - fn constructor(props: Self::Props) -> Self where Self: Sized; + fn constructor(props: Self::Props) -> Self + where + Self: Sized; /// Get this widget's ID fn get_id(&self) -> Index; @@ -74,8 +81,14 @@ pub trait WidgetProps: std::fmt::Debug + AsAny + Send + Sync { fn get_focusable(&self) -> Option<bool>; } -impl<T> BaseWidget for T where T: Widget + Clone + PartialEq + Default { - fn constructor<P: WidgetProps>(props: P) -> Self where Self: Sized { +impl<T> BaseWidget for T +where + T: Widget + Clone + PartialEq + Default, +{ + fn constructor<P: WidgetProps>(props: P) -> Self + where + Self: Sized, + { let props: Box<dyn Any> = Box::new(props); Widget::constructor(*props.downcast::<<T as Widget>::Props>().unwrap()) } @@ -109,4 +122,4 @@ impl<T> BaseWidget for T where T: Widget + Clone + PartialEq + Default { } } -impl<T> SealedWidget for T where T: Widget {} \ No newline at end of file +impl<T> SealedWidget for T where T: Widget {} diff --git a/kayak_core/src/widget_manager.rs b/kayak_core/src/widget_manager.rs index 4ac3f03..9ed82f0 100644 --- a/kayak_core/src/widget_manager.rs +++ b/kayak_core/src/widget_manager.rs @@ -4,7 +4,17 @@ use std::{ }; use crate::layout_cache::Rect; -use crate::{focus_tree::FocusTracker, focus_tree::FocusTree, layout_cache::LayoutCache, node::{Node, NodeBuilder}, render_command::RenderCommand, render_primitive::RenderPrimitive, styles::Style, tree::Tree, Arena, Index, Widget, WidgetProps, BoxedWidget}; +use crate::{ + focus_tree::FocusTracker, + focus_tree::FocusTree, + layout_cache::LayoutCache, + node::{Node, NodeBuilder}, + render_command::RenderCommand, + render_primitive::RenderPrimitive, + styles::Style, + tree::Tree, + Arena, BoxedWidget, Index, Widget, WidgetProps, +}; // use as_any::Downcast; #[derive(Debug)] diff --git a/kayak_render_macros/src/children.rs b/kayak_render_macros/src/children.rs index 4b9ef3b..b345753 100644 --- a/kayak_render_macros/src/children.rs +++ b/kayak_render_macros/src/children.rs @@ -1,6 +1,11 @@ use std::collections::HashSet; -use crate::{widget_builder::build_widget_stream, attribute::Attribute, child::{walk_block_to_variable, Child}, get_core_crate}; +use crate::{ + attribute::Attribute, + child::{walk_block_to_variable, Child}, + get_core_crate, + widget_builder::build_widget_stream, +}; use quote::{quote, ToTokens}; use syn::parse::{Parse, ParseStream, Result}; @@ -144,7 +149,8 @@ impl Children { for i in 0..children_quotes.len() { output.push(quote! { #base_clones_inner }); let name: proc_macro2::TokenStream = format!("child{}", i).parse().unwrap(); - let child = build_widget_stream(quote! { #name }, children_quotes[i].clone(), i); + let child = + build_widget_stream(quote! { #name }, children_quotes[i].clone(), i); output.push(quote! { #child }); } diff --git a/kayak_render_macros/src/function_component.rs b/kayak_render_macros/src/function_component.rs index 10c6a1e..e5b3cff 100644 --- a/kayak_render_macros/src/function_component.rs +++ b/kayak_render_macros/src/function_component.rs @@ -1,9 +1,9 @@ +use crate::get_core_crate; use proc_macro::TokenStream; use proc_macro_error::emit_error; use quote::quote; -use syn::{FnArg, Pat, Type}; use syn::spanned::Spanned; -use crate::get_core_crate; +use syn::{FnArg, Pat, Type}; pub struct WidgetArguments { pub focusable: bool, @@ -25,15 +25,17 @@ pub fn create_function_widget(f: syn::ItemFn, _widget_arguments: WidgetArguments } else { f.sig.span() }; - emit_error!(span, "Functional widgets expect exactly one argument (their props), but was given {}", f.sig.inputs.len()); + emit_error!( + span, + "Functional widgets expect exactly one argument (their props), but was given {}", + f.sig.inputs.len() + ); } let (props, prop_type) = match f.sig.inputs.first().unwrap() { FnArg::Typed(typed) => { let ident = match *typed.pat.clone() { - Pat::Ident(ident) => { - ident.ident - } + Pat::Ident(ident) => ident.ident, err => { emit_error!(err.span(), "Expected identifier, but got {:?}", err); return TokenStream::new(); @@ -41,9 +43,7 @@ pub fn create_function_widget(f: syn::ItemFn, _widget_arguments: WidgetArguments }; let ty = match *typed.ty.clone() { - Type::Path(type_path) => { - type_path.path - } + Type::Path(type_path) => type_path.path, err => { emit_error!(err.span(), "Invalid widget prop type: {:?}", err); return TokenStream::new(); @@ -63,7 +63,6 @@ pub fn create_function_widget(f: syn::ItemFn, _widget_arguments: WidgetArguments let kayak_core = get_core_crate(); - // TODO: See if this is still needed. If not, remove it // let mut input_names: Vec<_> = inputs // .iter() diff --git a/kayak_render_macros/src/tags.rs b/kayak_render_macros/src/tags.rs index 2536731..6c877dd 100644 --- a/kayak_render_macros/src/tags.rs +++ b/kayak_render_macros/src/tags.rs @@ -1,9 +1,9 @@ +use crate::get_core_crate; use crate::widget_attributes::WidgetAttributes; use proc_macro_error::abort; use quote::quote; use syn::parse::{Parse, ParseStream, Result}; use syn::spanned::Spanned; -use crate::get_core_crate; pub struct OpenTag { pub name: syn::Path, diff --git a/kayak_render_macros/src/use_effect.rs b/kayak_render_macros/src/use_effect.rs index 3856bbc..f09a151 100644 --- a/kayak_render_macros/src/use_effect.rs +++ b/kayak_render_macros/src/use_effect.rs @@ -1,10 +1,10 @@ +use crate::get_core_crate; use proc_macro::TokenStream; use proc_macro2::Ident; use quote::{format_ident, quote}; use syn::parse::{Parse, ParseStream}; use syn::punctuated::{Iter, Punctuated}; use syn::{bracketed, Token}; -use crate::get_core_crate; pub(crate) struct UseEffect { pub closure: syn::ExprClosure, diff --git a/kayak_render_macros/src/widget.rs b/kayak_render_macros/src/widget.rs index 93cc8fb..04b65d7 100644 --- a/kayak_render_macros/src/widget.rs +++ b/kayak_render_macros/src/widget.rs @@ -1,14 +1,14 @@ use proc_macro2::TokenStream; -use quote::{format_ident, quote}; use quote::ToTokens; +use quote::{format_ident, quote}; use syn::parse::{Parse, ParseStream, Result}; use syn::Path; -use crate::widget_builder::build_widget_stream; use crate::children::Children; use crate::tags::ClosingTag; -use crate::{get_core_crate, tags::OpenTag, widget_attributes::WidgetAttributes}; use crate::widget_attributes::CustomWidgetAttributes; +use crate::widget_builder::build_widget_stream; +use crate::{get_core_crate, tags::OpenTag, widget_attributes::WidgetAttributes}; #[derive(Clone)] pub struct Widget { @@ -88,7 +88,6 @@ impl Widget { }) } - /// Constructs a widget and its props /// /// The returned tuple contains: diff --git a/kayak_render_macros/src/widget_attributes.rs b/kayak_render_macros/src/widget_attributes.rs index 45f85a6..5b3f5f9 100644 --- a/kayak_render_macros/src/widget_attributes.rs +++ b/kayak_render_macros/src/widget_attributes.rs @@ -1,15 +1,15 @@ +use proc_macro2::{Ident, TokenStream}; use proc_macro_error::emit_error; use quote::{quote, ToTokens}; use std::collections::HashSet; -use proc_macro2::{Ident, TokenStream}; use syn::{ ext::IdentExt, parse::{Parse, ParseStream, Result}, spanned::Spanned, }; -use crate::{attribute::Attribute, children::Children, get_core_crate}; use crate::child::Child; +use crate::{attribute::Attribute, children::Children, get_core_crate}; #[derive(Clone)] pub struct WidgetAttributes { @@ -129,7 +129,6 @@ impl<'a, 'c> ToTokens for CustomWidgetAttributes<'a, 'c> { } impl<'a, 'c> CustomWidgetAttributes<'a, 'c> { - /// Assign this widget's attributes to the given ident /// /// This takes the form: `IDENT.ATTR_NAME = ATTR_VALUE;` @@ -183,11 +182,11 @@ impl<'a, 'c> CustomWidgetAttributes<'a, 'c> { block.stmts.len() > 0 } // Child is a widget - _ => true + _ => true, } } else { // Multiple children true } } -} \ No newline at end of file +} diff --git a/kayak_render_macros/src/widget_builder.rs b/kayak_render_macros/src/widget_builder.rs index cc9928d..ff2d105 100644 --- a/kayak_render_macros/src/widget_builder.rs +++ b/kayak_render_macros/src/widget_builder.rs @@ -1,7 +1,6 @@ use proc_macro2::TokenStream; use quote::quote; - /// Creates a token stream for building a widget /// /// # Arguments diff --git a/kayak_render_macros/src/widget_props.rs b/kayak_render_macros/src/widget_props.rs index 7fc4084..7f64f6e 100644 --- a/kayak_render_macros/src/widget_props.rs +++ b/kayak_render_macros/src/widget_props.rs @@ -1,9 +1,9 @@ use proc_macro::TokenStream; -use proc_macro2::{Ident}; +use proc_macro2::Ident; use proc_macro_error::emit_error; use quote::quote; -use syn::{Data, DeriveInput, Field, Meta, NestedMeta, parse_macro_input, spanned::Spanned}; +use syn::{parse_macro_input, spanned::Spanned, Data, DeriveInput, Field, Meta, NestedMeta}; use crate::get_core_crate; @@ -25,7 +25,10 @@ struct PropsHelpers { pub(crate) fn impl_widget_props(input: TokenStream) -> TokenStream { let DeriveInput { - ident, data, generics, .. + ident, + data, + generics, + .. } = parse_macro_input!(input); let helpers = process_data(data); @@ -90,7 +93,9 @@ fn process_data(data: Data) -> PropsHelpers { process_field(field, &mut helpers); } } - Data::Enum(data) => emit_error!(data.enum_token.span(), "Cannot derive WidgetProp for enum"), + Data::Enum(data) => { + emit_error!(data.enum_token.span(), "Cannot derive WidgetProp for enum") + } } helpers @@ -121,7 +126,7 @@ fn process_field(field: Field, props: &mut PropsHelpers) { PROP_STYLE => props.styles_ident = field.ident.clone(), PROP_ON_EVENT => props.on_event_ident = field.ident.clone(), PROP_FOCUSABLE => props.focusable_ident = field.ident.clone(), - err => emit_error!(err.span(), "Invalid attribute: {}", err) + err => emit_error!(err.span(), "Invalid attribute: {}", err), } } } @@ -140,4 +145,4 @@ fn quote_clone_field(field_ident: Option<Ident>) -> proc_macro2::TokenStream { None } } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index df6fa1e..f72eb49 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ pub mod core { pub use kayak_core::*; - pub use kayak_render_macros::{constructor, render, rsx, use_effect, use_state, widget, WidgetProps}; + pub use kayak_render_macros::{ + constructor, render, rsx, use_effect, use_state, widget, WidgetProps, + }; } #[cfg(feature = "bevy_renderer")] diff --git a/src/widgets/app.rs b/src/widgets/app.rs index a93b220..70d5379 100644 --- a/src/widgets/app.rs +++ b/src/widgets/app.rs @@ -1,9 +1,8 @@ - use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - widget, Children, + widget, Children, OnEvent, WidgetProps, }; use crate::widgets::Clip; @@ -13,13 +12,10 @@ pub struct AppProps { #[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>, } diff --git a/src/widgets/background.rs b/src/widgets/background.rs index b91db38..40a39e2 100644 --- a/src/widgets/background.rs +++ b/src/widgets/background.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - widget, Children, Fragment, + widget, Children, Fragment, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -10,13 +10,10 @@ pub struct BackgroundProps { #[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>, } diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 8f9abd1..ed1f9f6 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - Color, OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - widget, Children, Fragment, + widget, Children, Color, Fragment, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -10,13 +10,10 @@ pub struct ButtonProps { #[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>, } diff --git a/src/widgets/clip.rs b/src/widgets/clip.rs index f70e4cd..a55a4c1 100644 --- a/src/widgets/clip.rs +++ b/src/widgets/clip.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - widget, Children, + widget, Children, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -10,10 +10,8 @@ pub struct ClipProps { #[prop_field(Styles)] pub styles: Option<Style>, #[prop_field(Children)] - pub children: Option<Children>, #[prop_field(OnEvent)] - pub on_event: Option<OnEvent>, } diff --git a/src/widgets/element.rs b/src/widgets/element.rs index e671e6b..901357e 100644 --- a/src/widgets/element.rs +++ b/src/widgets/element.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - widget, Children, + widget, Children, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -10,13 +10,10 @@ pub struct ElementProps { #[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>, } diff --git a/src/widgets/fold.rs b/src/widgets/fold.rs index a88f676..a7458e0 100644 --- a/src/widgets/fold.rs +++ b/src/widgets/fold.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - use_state, widget, Children, EventType, Handler, + use_state, widget, Children, EventType, Handler, OnEvent, WidgetProps, }; use crate::widgets::{Background, Clip, If, Text}; @@ -16,13 +16,10 @@ pub struct FoldProps { #[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>, } @@ -58,7 +55,13 @@ pub struct FoldProps { /// ``` #[widget] pub fn Fold(props: FoldProps) { - let FoldProps {default_open, label, on_change, open, ..} = props.clone(); + let FoldProps { + default_open, + label, + on_change, + open, + .. + } = props.clone(); // === State === // let initial = default_open || open.unwrap_or_default(); diff --git a/src/widgets/if_element.rs b/src/widgets/if_element.rs index 807a229..a981384 100644 --- a/src/widgets/if_element.rs +++ b/src/widgets/if_element.rs @@ -1,8 +1,4 @@ -use crate::core::{ - OnEvent, rsx, WidgetProps, - styles::{Style}, - widget, Children, -}; +use crate::core::{rsx, styles::Style, widget, Children, OnEvent, WidgetProps}; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] pub struct IfProps { @@ -10,13 +6,10 @@ pub struct IfProps { #[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>, } diff --git a/src/widgets/image.rs b/src/widgets/image.rs index f73dc23..a1362cc 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - OnEvent, rsx, WidgetProps, + rsx, styles::{Style, StyleProp}, - widget, Children, + widget, Children, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -11,20 +11,19 @@ pub struct ImageProps { #[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>, } #[widget] pub fn Image(props: ImageProps) { props.styles = Some(Style { - render_command: StyleProp::Value(RenderCommand::Image { handle: props.handle }), + render_command: StyleProp::Value(RenderCommand::Image { + handle: props.handle, + }), ..props.styles.clone().unwrap_or_default() }); diff --git a/src/widgets/inspector.rs b/src/widgets/inspector.rs index d77251a..1e3559a 100644 --- a/src/widgets/inspector.rs +++ b/src/widgets/inspector.rs @@ -2,8 +2,7 @@ use kayak_core::styles::{PositionType, Style, StyleProp, Units}; use kayak_core::{Bound, Color, EventType, OnEvent, VecTracker}; use kayak_render_macros::{constructor, use_state}; - -use crate::core::{rsx, widget, WidgetProps, MutableBound}; +use crate::core::{rsx, widget, MutableBound, WidgetProps}; use crate::widgets::{Background, Button, Text}; diff --git a/src/widgets/nine_patch.rs b/src/widgets/nine_patch.rs index 48627e0..2152184 100644 --- a/src/widgets/nine_patch.rs +++ b/src/widgets/nine_patch.rs @@ -1,9 +1,9 @@ use crate::core::{ - render_command::RenderCommand, layout_cache::Space, - OnEvent, rsx, WidgetProps, + render_command::RenderCommand, + rsx, styles::{Style, StyleProp}, - widget, Children, + widget, Children, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -13,20 +13,20 @@ pub struct NinePatchProps { #[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>, } #[widget] pub fn NinePatch(props: NinePatchProps) { props.styles = Some(Style { - render_command: StyleProp::Value(RenderCommand::NinePatch { handle: props.handle, border: props.border }), + render_command: StyleProp::Value(RenderCommand::NinePatch { + handle: props.handle, + border: props.border, + }), ..props.styles.clone().unwrap_or_default() }); diff --git a/src/widgets/text.rs b/src/widgets/text.rs index 5b6562d..ef4793b 100644 --- a/src/widgets/text.rs +++ b/src/widgets/text.rs @@ -3,9 +3,8 @@ use kayak_font::{CoordinateSystem, KayakFont}; use crate::core::{ render_command::RenderCommand, - OnEvent, WidgetProps, styles::{Style, StyleProp}, - widget, + widget, OnEvent, WidgetProps, }; #[derive(WidgetProps, Default, Debug, PartialEq, Clone)] @@ -17,16 +16,20 @@ pub struct TextProps { #[prop_field(Styles)] pub styles: Option<Style>, #[prop_field(OnEvent)] - pub on_event: Option<OnEvent>, #[prop_field(Focusable)] - pub focusable: Option<bool>, } #[widget] pub fn Text(props: TextProps) { - let TextProps{content, font, line_height, size, ..} = props.clone(); + let TextProps { + content, + font, + line_height, + size, + .. + } = props.clone(); let font_name = font; let font: Binding<Option<KayakFont>> = context.get_asset(font_name.clone().unwrap_or("Roboto".into())); diff --git a/src/widgets/text_box.rs b/src/widgets/text_box.rs index 360b7bf..ebd0784 100644 --- a/src/widgets/text_box.rs +++ b/src/widgets/text_box.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - Children, rsx, WidgetProps, + rsx, styles::{Style, StyleProp, Units}, - widget, Bound, Color, EventType, MutableBound, OnEvent, + widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps, }; use std::sync::{Arc, RwLock}; @@ -16,13 +16,10 @@ pub struct TextBoxProps { #[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>, } @@ -57,7 +54,12 @@ pub struct Focus(pub bool); #[widget(focusable)] pub fn TextBox(props: TextBoxProps) { - let TextBoxProps {on_change, placeholder, value, ..} = props.clone(); + let TextBoxProps { + on_change, + placeholder, + value, + .. + } = props.clone(); let current_styles = props.styles.clone().unwrap_or_default(); props.styles = Some(Style { render_command: StyleProp::Value(RenderCommand::Layout), diff --git a/src/widgets/tooltip.rs b/src/widgets/tooltip.rs index e80dc93..d5974ea 100644 --- a/src/widgets/tooltip.rs +++ b/src/widgets/tooltip.rs @@ -1,8 +1,8 @@ use crate::core::{ render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{PositionType, Style, StyleProp, Units}, - widget, Bound, Children, Color, EventType, MutableBound, OnEvent, + widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps, }; use std::sync::Arc; @@ -27,10 +27,8 @@ pub struct TooltipProviderProps { #[prop_field(Styles)] pub styles: Option<Style>, #[prop_field(Children)] - pub children: Option<Children>, #[prop_field(OnEvent)] - pub on_event: Option<OnEvent>, } @@ -42,10 +40,8 @@ pub struct TooltipConsumerProps { #[prop_field(Styles)] pub styles: Option<Style>, #[prop_field(Children)] - pub children: Option<Children>, #[prop_field(OnEvent)] - pub on_event: Option<OnEvent>, } @@ -88,7 +84,7 @@ pub struct TooltipConsumerProps { /// ``` #[widget] pub fn TooltipProvider(props: TooltipProviderProps) { - let TooltipProviderProps{position, size, ..} = props; + let TooltipProviderProps { position, size, .. } = props; const WIDTH: f32 = 150.0; const HEIGHT: f32 = 18.0; const PADDING: (f32, f32) = (10.0, 5.0); @@ -197,7 +193,9 @@ pub fn TooltipProvider(props: TooltipProviderProps) { /// ``` #[widget] pub fn TooltipConsumer(props: TooltipConsumerProps) { - let TooltipConsumerProps {anchor, size, text, ..} = props.clone(); + let TooltipConsumerProps { + anchor, size, text, .. + } = props.clone(); props.styles = Some(Style { render_command: StyleProp::Value(RenderCommand::Clip), width: StyleProp::Value(Units::Auto), diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 08b3bec..4140d2a 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -1,9 +1,9 @@ use crate::core::{ color::Color, render_command::RenderCommand, - rsx, WidgetProps, + rsx, styles::{PositionType, Style, StyleProp, Units}, - use_state, widget, Children, EventType, OnEvent, + use_state, widget, Children, EventType, OnEvent, WidgetProps, }; use crate::widgets::{Background, Clip, Element, Text}; @@ -17,19 +17,22 @@ pub struct WindowProps { #[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>, } #[widget] pub fn Window(props: WindowProps) { - let WindowProps{draggable, position, size, title, ..} = props.clone(); + let WindowProps { + draggable, + position, + size, + title, + .. + } = props.clone(); let (is_dragging, set_is_dragging, ..) = use_state!(false); let (offset, set_offset, ..) = use_state!((0.0, 0.0)); -- GitLab