diff --git a/examples/layout.rs b/examples/layout.rs new file mode 100644 index 0000000000000000000000000000000000000000..41e335a54a0255ba8db2998b4a4468d87c91f3a9 --- /dev/null +++ b/examples/layout.rs @@ -0,0 +1,143 @@ +use bevy::prelude::*; +use kayak_ui::prelude::{widgets::*, *}; + +fn startup( + mut commands: Commands, + mut font_mapping: ResMut<FontMapping>, + asset_server: Res<AssetServer>, +) { + font_mapping.set_default(asset_server.load("roboto.kayak_font")); + + // Camera 2D forces a clear pass in bevy. + // We do this because our scene is not rendering anything else. + commands.spawn(Camera2dBundle::default()); + + let mut widget_context = KayakRootContext::new(); + widget_context.add_plugin(KayakWidgetsContextPlugin); + let parent_id = None; + + rsx! { + <KayakAppBundle> + <WindowBundle + window={KWindow { + title: "Layout example".into(), + draggable: true, + initial_position: Vec2::new(10.0, 10.0), + size: Vec2::new(512.0, 512.0), + ..KWindow::default() + }} + > + <ElementBundle + styles={KStyle{ + layout_type: LayoutType::Grid.into(), + grid_rows: vec![Units::Stretch(1.0), Units::Stretch(2.0), Units::Stretch(5.0)].into(), + grid_cols: vec![Units::Stretch(1.0), Units::Stretch(1.0)].into(), + ..default() + }} + > + <BackgroundBundle + styles={KStyle{ + background_color: Color::rgb(0.4, 0.9, 0.4).into(), + color: Color::rgb(0.0, 0.0, 0.0).into(), + padding: Edge::all(Units::Pixels(5.0)).into(), + border_radius: Corner::all(10.0).into(), + row_index: 0.into(), + col_index: 0.into(), + col_span: 2.into(), + layout_type: LayoutType::Row.into(), + col_between: Units::Pixels(5.0).into(), + ..default() + }} + > + <TextWidgetBundle + text={TextProps { + content: "A".into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "B".into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "C".into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "D".into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "E".into(), + ..default() + }} + /> + + </BackgroundBundle> + <TextWidgetBundle + text={TextProps { + content: "R1 C0".into(), + ..default() + }} + styles={KStyle{ + row_index: 1.into(), + col_index: 0.into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "R1 C1".into(), + ..default() + }} + styles={KStyle{ + row_index: 1.into(), + col_index: 1.into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "R2 C0".into(), + ..default() + }} + styles={KStyle{ + row_index: 2.into(), + col_index: 0.into(), + ..default() + }} + /> + <TextWidgetBundle + text={TextProps { + content: "R2 C1".into(), + ..default() + }} + styles={KStyle{ + row_index: 2.into(), + col_index: 1.into(), + ..default() + }} + /> + </ElementBundle> + </WindowBundle> + </KayakAppBundle> + } + + commands.spawn(UICameraBundle::new(widget_context)); +} + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugin(KayakContextPlugin) + .add_plugin(KayakWidgets) + .add_startup_system(startup) + .run() +} diff --git a/src/node.rs b/src/node.rs index dfd3165d4e75b1b28fe130d61bb4c1805791829e..b307207fa7cff0b66674aed8b3d568aa8986726e 100644 --- a/src/node.rs +++ b/src/node.rs @@ -415,14 +415,8 @@ impl<'a> morphorm::Node<'a> for WrappedIndex { fn col_index(&self, store: &'_ Self::Data) -> Option<usize> { if let Ok(node) = store.get(self.0) { return match node.resolved_styles.col_index { - StyleProp::Default => { - println!("col_index default"); - Some(0) - }, - StyleProp::Value(prop) => { - println!("col_index value {prop}"); - Some(prop) - }, + StyleProp::Default => Some(0), + StyleProp::Value(prop) => Some(prop), _ => Some(0), }; } diff --git a/src/styles/style.rs b/src/styles/style.rs index 7277196d6e68eeeeddc0bacda6b110cba7813fd2..5dba8472a8c1905b4f4637750b0708b0cce3f199 100644 --- a/src/styles/style.rs +++ b/src/styles/style.rs @@ -54,8 +54,8 @@ pub enum StyleProp<T: Default + Clone + Reflect + FromReflect> { } impl<T> Default for StyleProp<T> - where - T: Default + Clone + Reflect + FromReflect, +where + T: Default + Clone + Reflect + FromReflect, { fn default() -> Self { Self::Unset @@ -63,8 +63,8 @@ impl<T> Default for StyleProp<T> } impl<T> StyleProp<T> - where - T: Default + Clone + Reflect + FromReflect, +where + T: Default + Clone + Reflect + FromReflect, { /// Resolves this style property into a concrete value. ///