Skip to content
Snippets Groups Projects
Commit 33de177f authored by StarToaster's avatar StarToaster
Browse files

Updated to the latest bevy! And fixed a few issues.

parent 3171ba3a
No related branches found
No related tags found
No related merge requests found
Showing
with 140 additions and 236 deletions
...@@ -10,7 +10,7 @@ members = ["kayak_ui_macros"] ...@@ -10,7 +10,7 @@ members = ["kayak_ui_macros"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", rev="9423cb6a8d0c140e11364eb23c8feb7e576baa8c" } bevy = { git = "https://github.com/bevyengine/bevy", rev="4bcf49b2ea6fb5f42388b0e15d204020053ee5c7" }
bytemuck = "1.12" bytemuck = "1.12"
dashmap = "5.4" dashmap = "5.4"
kayak_font = { path = "./kayak_font" } kayak_font = { path = "./kayak_font" }
...@@ -18,6 +18,7 @@ morphorm = { git = "https://github.com/geom3trik/morphorm", rev = "1243152d4cebe ...@@ -18,6 +18,7 @@ morphorm = { git = "https://github.com/geom3trik/morphorm", rev = "1243152d4cebe
kayak_ui_macros = { path = "./kayak_ui_macros" } kayak_ui_macros = { path = "./kayak_ui_macros" }
indexmap = "1.9" indexmap = "1.9"
log = "0.4" log = "0.4"
bitflags = "1.3.2"
[dev-dependencies] [dev-dependencies]
fastrand = "1.8" fastrand = "1.8"
......
use bevy::{ use bevy::prelude::*;
prelude::{App, AssetServer, Commands, ImageSettings, Res, ResMut},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup( fn startup(
...@@ -64,8 +61,8 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque. ...@@ -64,8 +61,8 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque.
fn main() { fn main() {
App::new() App::new()
.insert_resource(ImageSettings::default_nearest()) .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_startup_system(startup) .add_startup_system(startup)
......
...@@ -7,13 +7,7 @@ ...@@ -7,13 +7,7 @@
//! for better specificity and makes local contexts much easier to manage. In the case of theming, //! for better specificity and makes local contexts much easier to manage. In the case of theming,
//! this allows us to have multiple active themes, even if they are nested within each other! //! this allows us to have multiple active themes, even if they are nested within each other!
use bevy::{ use bevy::prelude::*;
prelude::{
App as BevyApp, AssetServer, Bundle, Color, Commands, Component, Entity, ImageSettings, In,
Query, Res, ResMut, Vec2,
},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
/// The color theme struct we will be using across our demo widgets /// The color theme struct we will be using across our demo widgets
...@@ -395,8 +389,7 @@ fn startup( ...@@ -395,8 +389,7 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
...@@ -27,7 +27,6 @@ fn startup( ...@@ -27,7 +27,6 @@ fn startup(
fn main() { fn main() {
App::new() App::new()
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
...@@ -53,7 +53,6 @@ fn startup( ...@@ -53,7 +53,6 @@ fn startup(
} }
fn main() { fn main() {
App::new() App::new()
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
use bevy::{ use bevy::prelude::*;
prelude::{App as BevyApp, AssetServer, Commands, ImageSettings, Res, ResMut},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup( fn startup(
...@@ -19,10 +16,10 @@ fn startup( ...@@ -19,10 +16,10 @@ fn startup(
let parent_id = None; let parent_id = None;
rsx! { rsx! {
<KayakAppBundle> <KayakAppBundle>
<ImageBundle <KImageBundle
image={Image(image.clone())} image={Image(image.clone())}
style={KStyle { style={KStyle {
position_type: StyleProp::Value(PositionType::SelfDirected), position_type: StyleProp::Value(KPositionType::SelfDirected),
left: StyleProp::Value(Units::Pixels(10.0)), left: StyleProp::Value(Units::Pixels(10.0)),
top: StyleProp::Value(Units::Pixels(10.0)), top: StyleProp::Value(Units::Pixels(10.0)),
border_radius: StyleProp::Value(Corner::all(500.0)), border_radius: StyleProp::Value(Corner::all(500.0)),
...@@ -37,9 +34,8 @@ fn startup( ...@@ -37,9 +34,8 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ImageSettings::default_nearest()) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_startup_system(startup) .add_startup_system(startup)
......
use bevy::{ use bevy::prelude::*;
prelude::{App as BevyApp, AssetServer, Commands, ImageSettings, Res, ResMut},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup( fn startup(
...@@ -59,9 +56,8 @@ fn startup( ...@@ -59,9 +56,8 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ImageSettings::default_nearest()) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_startup_system(startup) .add_startup_system(startup)
......
use bevy::{ use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::{ prelude::*,
App as BevyApp, AssetServer, Bundle, Color, Commands, Component, Entity, In, Query, Res,
ResMut, Vec2,
},
DefaultPlugins,
}; };
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
...@@ -22,7 +18,7 @@ fn my_quad_update( ...@@ -22,7 +18,7 @@ fn my_quad_update(
if let Ok((quad, mut style, mut on_event)) = query.get_mut(entity) { if let Ok((quad, mut style, mut on_event)) = query.get_mut(entity) {
if style.render_command.resolve() != RenderCommand::Quad { if style.render_command.resolve() != RenderCommand::Quad {
style.render_command = StyleProp::Value(RenderCommand::Quad); style.render_command = StyleProp::Value(RenderCommand::Quad);
style.position_type = StyleProp::Value(PositionType::SelfDirected); style.position_type = StyleProp::Value(KPositionType::SelfDirected);
style.left = StyleProp::Value(Units::Pixels(quad.pos.x)); style.left = StyleProp::Value(Units::Pixels(quad.pos.x));
style.top = StyleProp::Value(Units::Pixels(quad.pos.y)); style.top = StyleProp::Value(Units::Pixels(quad.pos.y));
style.width = StyleProp::Value(Units::Pixels(quad.size.x)); style.width = StyleProp::Value(Units::Pixels(quad.size.x));
...@@ -126,7 +122,7 @@ fn startup( ...@@ -126,7 +122,7 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(LogDiagnosticsPlugin::default()) .add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default())
......
use bevy::{ use bevy::prelude::*;
prelude::{App, AssetServer, Commands, ImageSettings, Res, ResMut},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup( fn startup(
...@@ -66,8 +63,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque. ...@@ -66,8 +63,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed tellus neque.
fn main() { fn main() {
App::new() App::new()
.insert_resource(ImageSettings::default_nearest()) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_startup_system(startup) .add_startup_system(startup)
......
use bevy::{ use bevy::prelude::*;
prelude::{
App as BevyApp, AssetServer, Bundle, Commands, Component, Entity, In, Query, Res, ResMut,
Vec2,
},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, *}; use kayak_ui::prelude::{widgets::*, *};
#[derive(Component, Default, PartialEq, Clone)] #[derive(Component, Default, PartialEq, Clone)]
...@@ -125,7 +119,8 @@ fn startup( ...@@ -125,7 +119,8 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
...@@ -89,7 +89,6 @@ fn startup( ...@@ -89,7 +89,6 @@ fn startup(
fn main() { fn main() {
App::new() App::new()
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
use bevy::{ use bevy::prelude::*;
prelude::{
App as BevyApp, AssetServer, Bundle, Commands, Component, Entity, In, Input, KeyCode,
Query, Res, ResMut, Resource,
},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
#[derive(Component, Default, Clone, PartialEq)] #[derive(Component, Default, Clone, PartialEq)]
...@@ -12,24 +6,35 @@ pub struct MyWidgetProps { ...@@ -12,24 +6,35 @@ pub struct MyWidgetProps {
pub foo: u32, pub foo: u32,
} }
fn my_widget_1_update( fn my_widget_1_render(
In((_widget_context, entity)): In<(KayakWidgetContext, Entity)>, In((_widget_context, entity)): In<(KayakWidgetContext, Entity)>,
my_resource: Res<MyResource>, my_resource: Res<MyResource>,
mut query: Query<(&mut MyWidgetProps, &mut KStyle)>, mut query: Query<(&mut MyWidgetProps, &mut KStyle)>,
) -> bool { ) -> bool {
if my_resource.is_changed() || my_resource.is_added() { if let Ok((mut my_widget, mut style)) = query.get_mut(entity) {
if let Ok((mut my_widget, mut style)) = query.get_mut(entity) { my_widget.foo = my_resource.0;
my_widget.foo = my_resource.0; dbg!(my_widget.foo);
dbg!(my_widget.foo); // Note: We will see two updates because of the mutable change to styles.
style.render_command = StyleProp::Value(RenderCommand::Text { // Which means when foo changes MyWidget will render twice!
content: format!("My number is: {}", my_widget.foo).to_string(), style.render_command = StyleProp::Value(RenderCommand::Text {
alignment: Alignment::Start, content: format!("My number is: {}", my_widget.foo).to_string(),
}); alignment: Alignment::Start,
return true; });
}
} }
false true
}
// Our own version of widget_update that handles resource change events.
pub fn widget_update_with_resource<
Props: PartialEq + Component + Clone,
State: PartialEq + Component + Clone,
>(
In((widget_context, entity, previous_entity)): In<(KayakWidgetContext, Entity, Entity)>,
my_resource: Res<MyResource>,
widget_param: WidgetParam<Props, State>,
) -> bool {
widget_param.has_changed(&widget_context, entity, previous_entity) || my_resource.is_changed()
} }
impl Widget for MyWidgetProps {} impl Widget for MyWidgetProps {}
...@@ -68,8 +73,8 @@ fn startup( ...@@ -68,8 +73,8 @@ fn startup(
widget_context.add_widget_data::<MyWidgetProps, EmptyState>(); widget_context.add_widget_data::<MyWidgetProps, EmptyState>();
widget_context.add_widget_system( widget_context.add_widget_system(
MyWidgetProps::default().get_name(), MyWidgetProps::default().get_name(),
widget_update::<MyWidgetProps, EmptyState>, widget_update_with_resource::<MyWidgetProps, EmptyState>,
my_widget_1_update, my_widget_1_render,
); );
rsx! { rsx! {
<KayakAppBundle><MyWidgetBundle props={MyWidgetProps { foo: 0 }} /></KayakAppBundle> <KayakAppBundle><MyWidgetBundle props={MyWidgetProps { foo: 0 }} /></KayakAppBundle>
...@@ -84,7 +89,7 @@ fn update_resource(keyboard_input: Res<Input<KeyCode>>, mut my_resource: ResMut< ...@@ -84,7 +89,7 @@ fn update_resource(keyboard_input: Res<Input<KeyCode>>, mut my_resource: ResMut<
} }
fn main() { fn main() {
BevyApp::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
use bevy::{ use bevy::prelude::*;
prelude::{
App as BevyApp, AssetServer, Bundle, Commands, Component, Entity, In, Query, Res, ResMut,
Vec2,
},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, *}; use kayak_ui::prelude::{widgets::*, *};
#[derive(Component, Default, Clone, PartialEq)] #[derive(Component, Default, Clone, PartialEq)]
...@@ -126,7 +120,7 @@ fn startup( ...@@ -126,7 +120,7 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
use bevy::{ use bevy::prelude::*;
prelude::{App as BevyApp, AssetServer, Commands, ImageSettings, Res, ResMut},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup( fn startup(
...@@ -37,7 +34,7 @@ fn startup( ...@@ -37,7 +34,7 @@ fn startup(
let parent_id = None; let parent_id = None;
let atlas_styles = KStyle { let atlas_styles = KStyle {
position_type: StyleProp::Value(PositionType::ParentDirected), position_type: StyleProp::Value(KPositionType::ParentDirected),
width: StyleProp::Value(Units::Pixels(200.0)), width: StyleProp::Value(Units::Pixels(200.0)),
height: StyleProp::Value(Units::Pixels(200.0)), height: StyleProp::Value(Units::Pixels(200.0)),
..KStyle::default() ..KStyle::default()
...@@ -54,7 +51,7 @@ fn startup( ...@@ -54,7 +51,7 @@ fn startup(
rsx! { rsx! {
<KayakAppBundle> <KayakAppBundle>
<TextureAtlasBundle <TextureAtlasBundle
atlas={TextureAtlas { atlas={TextureAtlasProps {
handle: image_handle.clone(), handle: image_handle.clone(),
position: sign_position, position: sign_position,
tile_size: sign_size, tile_size: sign_size,
...@@ -62,7 +59,7 @@ fn startup( ...@@ -62,7 +59,7 @@ fn startup(
styles={atlas_styles.clone()} styles={atlas_styles.clone()}
/> />
<TextureAtlasBundle <TextureAtlasBundle
atlas={TextureAtlas { atlas={TextureAtlasProps {
handle: image_handle.clone(), handle: image_handle.clone(),
position: flower_position, position: flower_position,
tile_size: flower_size, tile_size: flower_size,
...@@ -76,9 +73,8 @@ fn startup( ...@@ -76,9 +73,8 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ImageSettings::default_nearest()) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
.add_startup_system(startup) .add_startup_system(startup)
......
...@@ -34,80 +34,76 @@ pub fn render_todo_items( ...@@ -34,80 +34,76 @@ pub fn render_todo_items(
In((widget_context, entity)): In<(KayakWidgetContext, Entity)>, In((widget_context, entity)): In<(KayakWidgetContext, Entity)>,
mut commands: Commands, mut commands: Commands,
todo_list: Res<TodoList>, todo_list: Res<TodoList>,
query: Query<&TodoItemsProps, Or<(Changed<Style>, Changed<TodoItemsProps>, With<Mounted>)>>,
) -> bool { ) -> bool {
if query.is_empty() || todo_list.is_changed() { let parent_id = Some(entity);
let parent_id = Some(entity); rsx! {
rsx! { <ElementBundle
<ElementBundle styles={KStyle {
styles={KStyle { height: Units::Auto.into(),
height: Units::Auto.into(), ..Default::default()
..Default::default() }}
}} >
> {todo_list.items.iter().enumerate().for_each(|(index, content)| {
{todo_list.items.iter().enumerate().for_each(|(index, content)| { let handle_click = OnEvent::new(
let handle_click = OnEvent::new( move |In((event_dispatcher_context, _, event, _)): In<(
move |In((event_dispatcher_context, _, event, _)): In<( EventDispatcherContext,
EventDispatcherContext, WidgetState,
WidgetState, Event,
Event, Entity,
Entity, )>,
)>, mut todo_list: ResMut<TodoList>,| {
mut todo_list: ResMut<TodoList>,| { match event.event_type {
match event.event_type { EventType::Click(..) => {
EventType::Click(..) => { todo_list.items.remove(index);
todo_list.items.remove(index); },
}, _ => {}
_ => {} }
} (event_dispatcher_context, event)
(event_dispatcher_context, event) },
}, );
); constructor! {
constructor! { <ElementBundle
<ElementBundle styles={KStyle {
render_command: StyleProp::Value(RenderCommand::Quad),
background_color: StyleProp::Value(Color::rgba(0.0781, 0.0898, 0.101, 1.0)),
border_radius: StyleProp::Value(Corner::all(3.0)),
bottom: StyleProp::Value(Units::Pixels(5.0)),
height: StyleProp::Value(Units::Auto),
padding: StyleProp::Value(Edge::all(Units::Pixels(10.0))),
layout_type: StyleProp::Value(LayoutType::Row),
..Default::default()
}}
>
<TextWidgetBundle
text={TextProps {
content: content.clone(),
..Default::default()
}}
styles={KStyle { styles={KStyle {
render_command: StyleProp::Value(RenderCommand::Quad), right: StyleProp::Value(Units::Stretch(1.0)),
background_color: StyleProp::Value(Color::rgba(0.0781, 0.0898, 0.101, 1.0)), top: StyleProp::Value(Units::Stretch(1.0)),
border_radius: StyleProp::Value(Corner::all(3.0)), bottom: StyleProp::Value(Units::Stretch(1.0)),
bottom: StyleProp::Value(Units::Pixels(5.0)),
height: StyleProp::Value(Units::Auto),
padding: StyleProp::Value(Edge::all(Units::Pixels(10.0))),
layout_type: StyleProp::Value(LayoutType::Row),
..Default::default() ..Default::default()
}} }}
/>
<KButtonBundle
styles={KStyle {
width: StyleProp::Value(Units::Pixels(32.0)),
height: StyleProp::Value(Units::Pixels(32.0)),
left: StyleProp::Value(Units::Pixels(15.0)),
..Default::default()
}}
on_event={handle_click}
> >
<TextWidgetBundle <TextWidgetBundle text={TextProps {
text={TextProps { content: "X".into(),
content: content.clone(), ..Default::default()
..Default::default() }} />
}} </KButtonBundle>
styles={KStyle { </ElementBundle>
right: StyleProp::Value(Units::Stretch(1.0)), }
top: StyleProp::Value(Units::Stretch(1.0)), })}
bottom: StyleProp::Value(Units::Stretch(1.0)), </ElementBundle>
..Default::default()
}}
/>
<KButtonBundle
styles={KStyle {
width: StyleProp::Value(Units::Pixels(32.0)),
height: StyleProp::Value(Units::Pixels(32.0)),
left: StyleProp::Value(Units::Pixels(15.0)),
..Default::default()
}}
on_event={handle_click}
>
<TextWidgetBundle text={TextProps {
content: "X".into(),
..Default::default()
}} />
</KButtonBundle>
</ElementBundle>
}
})}
</ElementBundle>
}
return true;
} }
false true
} }
use bevy::{ use bevy::prelude::*;
prelude::{
App as BevyApp, AssetServer, Bundle, Changed, Commands, Component, Entity, In, Or, Query,
Res, ResMut, With,
},
DefaultPlugins,
};
use kayak_ui::prelude::{widgets::*, KStyle, *}; use kayak_ui::prelude::{widgets::*, KStyle, *};
#[derive(Component, Default, PartialEq, Clone)] #[derive(Component, Default, PartialEq, Clone)]
...@@ -84,7 +78,8 @@ fn startup( ...@@ -84,7 +78,8 @@ fn startup(
} }
fn main() { fn main() {
BevyApp::new() App::new()
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(KayakContextPlugin) .add_plugin(KayakContextPlugin)
.add_plugin(KayakWidgets) .add_plugin(KayakWidgets)
......
/// This is a simple widget template.
/// It'll auto update if the props change.
/// Don't forget to register the update system with kayak!
use bevy::prelude::*;
use kayak_ui::prelude::*;
#[derive(Component, Default)]
pub struct WidgetProps;
impl Widget for WidgetProps {}
#[derive(Bundle)]
pub struct WidgetBundle {
pub widget: WidgetProps,
pub styles: KStyle,
pub children: KChildren,
pub widget_name: WidgetName,
}
impl Default for WidgetBundle {
fn default() -> Self {
Self {
widget: WidgetProps::default(),
styles: KStyle {
render_command: StyleProp::Value(RenderCommand::Clip),
height: StyleProp::Value(Units::Stretch(1.0)),
width: StyleProp::Value(Units::Stretch(1.0)),
..KStyle::default()
},
children: KChildren::default(),
widget_name: WidgetProps::default().get_name(),
}
}
}
pub fn update_widget(
In((widget_context, entity)): In<(KayakWidgetContext, Entity)>,
_: Commands,
mut query: Query<
(&Style, &KChildren),
Or<(Changed<Style>, Changed<WidgetProps>, With<Mounted>)>,
>,
) -> bool {
if let Ok((_, children)) = query.get_mut(entity) {
children.process(&widget_context, Some(entity));
return true;
}
false
}
fn main() {}
...@@ -15,8 +15,8 @@ unicode-segmentation = "1.9" ...@@ -15,8 +15,8 @@ unicode-segmentation = "1.9"
# Provides UAX #14 line break segmentation # Provides UAX #14 line break segmentation
xi-unicode = "0.3" xi-unicode = "0.3"
bevy = { git = "https://github.com/bevyengine/bevy", rev="9423cb6a8d0c140e11364eb23c8feb7e576baa8c", optional = true, default-features = false, features = ["bevy_asset", "bevy_render", "bevy_core_pipeline"] } bevy = { git = "https://github.com/bevyengine/bevy", rev="4bcf49b2ea6fb5f42388b0e15d204020053ee5c7", optional = true, default-features = false, features = ["bevy_asset", "bevy_render", "bevy_core_pipeline"] }
[dev-dependencies] [dev-dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", rev="9423cb6a8d0c140e11364eb23c8feb7e576baa8c" } bevy = { git = "https://github.com/bevyengine/bevy", rev="4bcf49b2ea6fb5f42388b0e15d204020053ee5c7" }
bytemuck = "1.12.0" bytemuck = "1.12.0"
...@@ -2,10 +2,10 @@ use bevy::{ ...@@ -2,10 +2,10 @@ use bevy::{
math::Vec2, math::Vec2,
prelude::{ prelude::{
App as BevyApp, AssetServer, Camera2dBundle, Commands, Component, Handle, Input, KeyCode, App as BevyApp, AssetServer, Camera2dBundle, Commands, Component, Handle, Input, KeyCode,
Query, Res, ResMut, Sprite, SpriteBundle, Transform, With, Without, PluginGroup, Query, Res, ResMut, Sprite, SpriteBundle, Transform, With, Without,
}, },
render::color::Color, render::color::Color,
window::WindowDescriptor, window::{WindowDescriptor, WindowPlugin},
DefaultPlugins, DefaultPlugins,
}; };
...@@ -119,13 +119,15 @@ fn control_text( ...@@ -119,13 +119,15 @@ fn control_text(
fn main() { fn main() {
BevyApp::new() BevyApp::new()
.insert_resource(WindowDescriptor { .add_plugins(DefaultPlugins.set(WindowPlugin {
width: 1270.0, window: WindowDescriptor {
height: 720.0, width: 1270.0,
title: String::from("UI Example"), height: 720.0,
title: String::from("UI Example"),
..Default::default()
},
..Default::default() ..Default::default()
}) }))
.add_plugins(DefaultPlugins)
.add_plugin(KayakFontPlugin) .add_plugin(KayakFontPlugin)
.add_plugin(FontRenderPlugin) .add_plugin(FontRenderPlugin)
.add_startup_system(startup) .add_startup_system(startup)
......
...@@ -17,4 +17,4 @@ proc-macro-crate = "1.1" ...@@ -17,4 +17,4 @@ proc-macro-crate = "1.1"
[dev-dependencies] [dev-dependencies]
kayak_ui = { path = "../", version = "0.1.0" } kayak_ui = { path = "../", version = "0.1.0" }
pretty_assertions = "1.2.1" pretty_assertions = "1.2.1"
bevy = { git = "https://github.com/bevyengine/bevy", rev="9423cb6a8d0c140e11364eb23c8feb7e576baa8c" } bevy = { git = "https://github.com/bevyengine/bevy", rev="4bcf49b2ea6fb5f42388b0e15d204020053ee5c7" }
\ No newline at end of file \ 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