Skip to content
Snippets Groups Projects
Commit f23a44a4 authored by MrGVSV's avatar MrGVSV
Browse files

Formatting

parent 2e73497a
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 49 deletions
...@@ -5,9 +5,9 @@ use bevy::{ ...@@ -5,9 +5,9 @@ use bevy::{
}; };
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle};
use kayak_ui::core::{ use kayak_ui::core::{
render, rsx, WidgetProps, render, rsx,
styles::{Style, StyleProp, Units}, 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}; use kayak_ui::widgets::{App, Button, Text, Window};
......
...@@ -7,9 +7,9 @@ use bevy::{ ...@@ -7,9 +7,9 @@ use bevy::{
use kayak_ui::{ use kayak_ui::{
bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle},
core::{ core::{
render, rsx, WidgetProps, render, rsx,
styles::{Style, StyleProp, Units}, 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}, widgets::{App, Background, Button, Fold, If, Text, Window},
}; };
......
...@@ -6,9 +6,9 @@ use bevy::{ ...@@ -6,9 +6,9 @@ use bevy::{
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, ImageManager, UICameraBundle}; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, ImageManager, UICameraBundle};
use kayak_ui::core::{ use kayak_ui::core::{
layout_cache::Space, layout_cache::Space,
render, rsx, WidgetProps, render, rsx,
styles::{LayoutType, Style, StyleProp, Units}, 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}; use kayak_ui::widgets::{App, NinePatch, Text};
...@@ -17,7 +17,7 @@ struct BlueButtonProps { ...@@ -17,7 +17,7 @@ struct BlueButtonProps {
#[prop_field(Styles)] #[prop_field(Styles)]
styles: Option<Style>, styles: Option<Style>,
#[prop_field(Children)] #[prop_field(Children)]
children: Option<Children> children: Option<Children>,
} }
#[widget] #[widget]
......
...@@ -4,7 +4,7 @@ use bevy::{ ...@@ -4,7 +4,7 @@ use bevy::{
DefaultPlugins, DefaultPlugins,
}; };
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; 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}; use kayak_ui::widgets::{App, Text, Window};
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
......
...@@ -16,7 +16,7 @@ use bevy::{ ...@@ -16,7 +16,7 @@ use bevy::{
}; };
use kayak_ui::{ use kayak_ui::{
bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, 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}, widgets::{App, Button, Text, Window},
}; };
......
...@@ -5,9 +5,9 @@ use bevy::{ ...@@ -5,9 +5,9 @@ use bevy::{
}; };
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle};
use kayak_ui::core::{ use kayak_ui::core::{
render, rsx, WidgetProps, render, rsx,
styles::{Style, StyleProp, Units}, 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}; use kayak_ui::widgets::{App, Button, If, Text, Window};
......
...@@ -13,17 +13,17 @@ ...@@ -13,17 +13,17 @@
use bevy::prelude::{ use bevy::prelude::{
App as BevyApp, AssetServer, Commands, DefaultPlugins, Res, ResMut, WindowDescriptor, App as BevyApp, AssetServer, Commands, DefaultPlugins, Res, ResMut, WindowDescriptor,
}; };
use kayak_core::Children;
use kayak_ui::{ use kayak_ui::{
bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle},
core::{ core::{
render, rsx, WidgetProps, render, rsx,
styles::{LayoutType, Style, StyleProp, Units}, 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}, widgets::{App, Background, Element, If, Text, TooltipConsumer, TooltipProvider, Window},
}; };
use std::sync::Arc; use std::sync::Arc;
use kayak_core::Children;
/// The color theme struct we will be using across our demo widgets /// The color theme struct we will be using across our demo widgets
#[derive(Debug, Default, Clone, PartialEq)] #[derive(Debug, Default, Clone, PartialEq)]
...@@ -74,7 +74,10 @@ struct ThemeProviderProps { ...@@ -74,7 +74,10 @@ struct ThemeProviderProps {
/// It can also be nested within itself, allowing for differing provider values. /// It can also be nested within itself, allowing for differing provider values.
#[widget] #[widget]
fn ThemeProvider(props: ThemeProviderProps) { fn ThemeProvider(props: ThemeProviderProps) {
let ThemeProviderProps { initial_theme, children } = props.clone(); let ThemeProviderProps {
initial_theme,
children,
} = props.clone();
// Create the provider // Create the provider
context.create_provider(initial_theme); context.create_provider(initial_theme);
rsx! { <>{children}</> } rsx! { <>{children}</> }
...@@ -166,7 +169,7 @@ fn ThemeSelector(props: ThemeSelectorProps) { ...@@ -166,7 +169,7 @@ fn ThemeSelector(props: ThemeSelectorProps) {
#[derive(WidgetProps, Clone, Debug, Default, PartialEq)] #[derive(WidgetProps, Clone, Debug, Default, PartialEq)]
struct ThemeDemoProps { struct ThemeDemoProps {
is_root: bool is_root: bool,
} }
/// A widget that demonstrates the theming in action /// A widget that demonstrates the theming in action
......
use kayak_ui::{ use kayak_ui::{
core::{ core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, WidgetProps, rsx,
styles::{LayoutType, Style, StyleProp, Units}, styles::{LayoutType, Style, StyleProp, Units},
use_state, widget, Bound, EventType, OnEvent, use_state, widget, Bound, EventType, OnEvent, WidgetProps,
}, },
widgets::{Background, Text}, widgets::{Background, Text},
}; };
...@@ -30,7 +30,9 @@ pub struct TabProps { ...@@ -30,7 +30,9 @@ pub struct TabProps {
/// The actual tab, displayed in a [TabBar](crate::tab_bar::TabBar) /// The actual tab, displayed in a [TabBar](crate::tab_bar::TabBar)
#[widget] #[widget]
pub fn Tab(props: TabProps) { 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 theme = context.create_consumer::<TabTheme>().unwrap_or_default();
let (focus_state, set_focus_state, ..) = use_state!(false); let (focus_state, set_focus_state, ..) = use_state!(false);
......
use kayak_ui::{ use kayak_ui::{
core::{ core::{
constructor, rsx, WidgetProps, constructor, rsx,
styles::{LayoutType, Style, StyleProp, Units}, styles::{LayoutType, Style, StyleProp, Units},
widget, Bound, EventType, Handler, KeyCode, OnEvent, VecTracker, widget, Bound, EventType, Handler, KeyCode, OnEvent, VecTracker, WidgetProps,
}, },
widgets::Background, widgets::Background,
}; };
...@@ -16,13 +16,18 @@ pub struct TabBarProps { ...@@ -16,13 +16,18 @@ pub struct TabBarProps {
pub selected: usize, pub selected: usize,
pub on_select_tab: Handler<usize>, pub on_select_tab: Handler<usize>,
#[prop_field(Styles)] #[prop_field(Styles)]
pub styles: Option<Style> pub styles: Option<Style>,
} }
/// A widget displaying a collection of tabs in a horizontal bar /// A widget displaying a collection of tabs in a horizontal bar
#[widget] #[widget]
pub fn TabBar(props: TabBarProps) { 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 theme = context.create_consumer::<TabTheme>().unwrap_or_default();
let tabs = tabs.into_iter().enumerate().map(move |(index, tab)| { let tabs = tabs.into_iter().enumerate().map(move |(index, tab)| {
......
use kayak_ui::core::{ use kayak_ui::core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, WidgetProps, rsx,
styles::{Style, StyleProp}, styles::{Style, StyleProp},
use_state, widget, Bound, Fragment, Handler, use_state, widget, Bound, Fragment, Handler, WidgetProps,
}; };
use std::fmt::Debug; use std::fmt::Debug;
...@@ -31,7 +31,9 @@ pub struct TabBoxProps { ...@@ -31,7 +31,9 @@ pub struct TabBoxProps {
/// This houses both the tab bar and its content. /// This houses both the tab bar and its content.
#[widget] #[widget]
pub fn TabBox(props: TabBoxProps) { 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 theme = context.create_consumer::<TabTheme>().unwrap_or_default();
let (selected, set_selected, ..) = use_state!(initial_tab); let (selected, set_selected, ..) = use_state!(initial_tab);
......
use kayak_ui::core::{ use kayak_ui::core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, WidgetProps, rsx,
styles::{Style, StyleProp}, styles::{Style, StyleProp},
widget, Bound, Fragment, VecTracker, widget, Bound, Fragment, VecTracker, WidgetProps,
}; };
use std::ops::Index; use std::ops::Index;
......
...@@ -13,9 +13,9 @@ use bevy::{ ...@@ -13,9 +13,9 @@ use bevy::{
use kayak_ui::{ use kayak_ui::{
bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle},
core::{ core::{
constructor, render, rsx, WidgetProps, constructor, render, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, StyleProp, Units},
widget, Color, Index, widget, Color, Index, WidgetProps,
}, },
widgets::{App, Text, Window}, widgets::{App, Text, Window},
}; };
......
use kayak_ui::core::{Children, rsx, widget, Color, WidgetProps}; use kayak_ui::core::{rsx, widget, Children, Color, WidgetProps};
#[derive(Clone, Copy, Debug, Default, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct TabTheme { pub struct TabTheme {
...@@ -23,12 +23,15 @@ pub struct ColorState { ...@@ -23,12 +23,15 @@ pub struct ColorState {
pub struct TabThemeProviderProps { pub struct TabThemeProviderProps {
pub initial_theme: TabTheme, pub initial_theme: TabTheme,
#[prop_field(Children)] #[prop_field(Children)]
pub children: Option<Children> pub children: Option<Children>,
} }
#[widget] #[widget]
pub fn TabThemeProvider(props: TabThemeProviderProps) { pub fn TabThemeProvider(props: TabThemeProviderProps) {
let TabThemeProviderProps { initial_theme, children } = props.clone(); let TabThemeProviderProps {
initial_theme,
children,
} = props.clone();
context.create_provider(initial_theme); context.create_provider(initial_theme);
rsx! { <>{children}</> } rsx! { <>{children}</> }
} }
...@@ -7,9 +7,9 @@ use kayak_core::Color; ...@@ -7,9 +7,9 @@ use kayak_core::Color;
use kayak_render_macros::use_state; use kayak_render_macros::use_state;
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle};
use kayak_ui::core::{ use kayak_ui::core::{
render, rsx, WidgetProps, render, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, StyleProp, Units},
widget, Index, widget, Index, WidgetProps,
}; };
use kayak_ui::widgets::{App, OnChange, TextBox, Window}; use kayak_ui::widgets::{App, OnChange, TextBox, Window};
......
use kayak_ui::core::{ use kayak_ui::core::{
color::Color, color::Color,
render_command::RenderCommand, render_command::RenderCommand,
rsx, WidgetProps, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, StyleProp, Units},
use_state, widget, EventType, OnEvent, use_state, widget, EventType, OnEvent, WidgetProps,
}; };
use kayak_ui::widgets::{Background, Text}; use kayak_ui::widgets::{Background, Text};
......
use kayak_ui::core::{ use kayak_ui::core::{
rsx, WidgetProps, rsx,
styles::{LayoutType, Style, StyleProp, Units}, styles::{LayoutType, Style, StyleProp, Units},
widget, Color, EventType, Handler, OnEvent, widget, Color, EventType, Handler, OnEvent, WidgetProps,
}; };
use kayak_ui::widgets::{Background, Text}; use kayak_ui::widgets::{Background, Text};
...@@ -16,7 +16,11 @@ pub struct CardProps { ...@@ -16,7 +16,11 @@ pub struct CardProps {
#[widget] #[widget]
pub fn Card(props: CardProps) { 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 { let background_styles = Style {
layout_type: StyleProp::Value(LayoutType::Row), layout_type: StyleProp::Value(LayoutType::Row),
background_color: StyleProp::Value(Color::new(0.176, 0.196, 0.215, 1.0)), background_color: StyleProp::Value(Color::new(0.176, 0.196, 0.215, 1.0)),
......
use kayak_ui::core::{ use kayak_ui::core::{
color::Color, color::Color,
render_command::RenderCommand, render_command::RenderCommand,
rsx, WidgetProps, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, StyleProp, Units},
use_state, widget, EventType, OnEvent, use_state, widget, EventType, OnEvent, WidgetProps,
}; };
use kayak_ui::widgets::{Background, Text}; use kayak_ui::widgets::{Background, Text};
......
...@@ -5,9 +5,9 @@ use bevy::{ ...@@ -5,9 +5,9 @@ use bevy::{
}; };
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}; use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle};
use kayak_ui::core::{ use kayak_ui::core::{
render, rsx, WidgetProps, render, rsx,
styles::{LayoutType, Style, StyleProp, Units}, 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}; use kayak_ui::widgets::{App, Element, OnChange, TextBox, Window};
......
...@@ -18,9 +18,9 @@ use bevy::{ ...@@ -18,9 +18,9 @@ use bevy::{
use kayak_ui::{ use kayak_ui::{
bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle}, bevy::{BevyContext, BevyKayakUIPlugin, FontMapping, UICameraBundle},
core::{ core::{
render, rsx, WidgetProps, render, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, StyleProp, Units},
use_state, widget, EventType, Index, OnEvent, use_state, widget, EventType, Index, OnEvent, WidgetProps,
}, },
widgets::{App, Button, Text, Window}, widgets::{App, Button, Text, Window},
}; };
......
use crate::{Index, KayakContextRef};
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::sync::Arc; use std::sync::Arc;
use crate::{Index, KayakContextRef};
/// A container for a function that generates child widgets /// A container for a function that generates child widgets
#[derive(Clone)] #[derive(Clone)]
pub struct Children(Arc<dyn Fn(Option<Index>, &mut KayakContextRef) + Send + Sync>); pub struct Children(Arc<dyn Fn(Option<Index>, &mut KayakContextRef) + Send + Sync>);
impl Children { 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)) Self(Arc::new(builder))
} }
pub fn build(&self, id: Option<Index>, context: &mut KayakContextRef) { pub fn build(&self, id: Option<Index>, context: &mut KayakContextRef) {
...@@ -26,4 +28,4 @@ impl PartialEq for Children { ...@@ -26,4 +28,4 @@ impl PartialEq for Children {
// Never prevent "==" for being true because of this struct // Never prevent "==" for being true because of this struct
true true
} }
} }
\ No newline at end of file
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