Skip to content
Snippets Groups Projects
Commit 4aa58707 authored by Maccesch's avatar Maccesch
Browse files

added layout example

parent be13425b
No related branches found
No related tags found
No related merge requests found
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()
}
...@@ -415,14 +415,8 @@ impl<'a> morphorm::Node<'a> for WrappedIndex { ...@@ -415,14 +415,8 @@ impl<'a> morphorm::Node<'a> for WrappedIndex {
fn col_index(&self, store: &'_ Self::Data) -> Option<usize> { fn col_index(&self, store: &'_ Self::Data) -> Option<usize> {
if let Ok(node) = store.get(self.0) { if let Ok(node) = store.get(self.0) {
return match node.resolved_styles.col_index { return match node.resolved_styles.col_index {
StyleProp::Default => { StyleProp::Default => Some(0),
println!("col_index default"); StyleProp::Value(prop) => Some(prop),
Some(0)
},
StyleProp::Value(prop) => {
println!("col_index value {prop}");
Some(prop)
},
_ => Some(0), _ => Some(0),
}; };
} }
......
...@@ -54,8 +54,8 @@ pub enum StyleProp<T: Default + Clone + Reflect + FromReflect> { ...@@ -54,8 +54,8 @@ pub enum StyleProp<T: Default + Clone + Reflect + FromReflect> {
} }
impl<T> Default for StyleProp<T> impl<T> Default for StyleProp<T>
where where
T: Default + Clone + Reflect + FromReflect, T: Default + Clone + Reflect + FromReflect,
{ {
fn default() -> Self { fn default() -> Self {
Self::Unset Self::Unset
...@@ -63,8 +63,8 @@ impl<T> Default for StyleProp<T> ...@@ -63,8 +63,8 @@ impl<T> Default for StyleProp<T>
} }
impl<T> StyleProp<T> impl<T> StyleProp<T>
where where
T: Default + Clone + Reflect + FromReflect, T: Default + Clone + Reflect + FromReflect,
{ {
/// Resolves this style property into a concrete value. /// Resolves this style property into a concrete value.
/// ///
......
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