Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI 0.11
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI 0.11
Commits
4aa58707
Commit
4aa58707
authored
2 years ago
by
Maccesch
Browse files
Options
Downloads
Patches
Plain Diff
added layout example
parent
be13425b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/layout.rs
+143
-0
143 additions, 0 deletions
examples/layout.rs
src/node.rs
+2
-8
2 additions, 8 deletions
src/node.rs
src/styles/style.rs
+4
-4
4 additions, 4 deletions
src/styles/style.rs
with
149 additions
and
12 deletions
examples/layout.rs
0 → 100644
+
143
−
0
View file @
4aa58707
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
()
}
This diff is collapsed.
Click to expand it.
src/node.rs
+
2
−
8
View file @
4aa58707
...
@@ -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
),
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
src/styles/style.rs
+
4
−
4
View file @
4aa58707
...
@@ -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.
///
///
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment