Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Advent UI
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
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
Advent UI
Commits
6bbbcd60
Verified
Commit
6bbbcd60
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Fix macro exports and exportes utilities
parent
f081ac1c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+3
-2
3 additions, 2 deletions
src/lib.rs
src/utilities.rs
+49
-40
49 additions, 40 deletions
src/utilities.rs
with
52 additions
and
42 deletions
src/lib.rs
+
3
−
2
View file @
6bbbcd60
...
@@ -4,7 +4,7 @@ mod theme;
...
@@ -4,7 +4,7 @@ mod theme;
mod
types
;
mod
types
;
pub
(
crate
)
mod
utilities
;
pub
(
crate
)
mod
utilities
;
pub
(
crate
)
extern
crate
bevy
;
pub
extern
crate
bevy
;
pub
extern
crate
kayak_font
;
pub
extern
crate
kayak_font
;
pub
extern
crate
kayak_ui
;
pub
extern
crate
kayak_ui
;
...
@@ -37,7 +37,8 @@ pub use styles::{edge_px, pct, px, stretch, val_auto, value};
...
@@ -37,7 +37,8 @@ pub use styles::{edge_px, pct, px, stretch, val_auto, value};
pub
use
theme
::{
tokens
,
ThemeMapping
,
ThemeProvider
};
pub
use
theme
::{
tokens
,
ThemeMapping
,
ThemeProvider
};
pub
use
types
::
IconContent
;
pub
use
types
::
IconContent
;
pub
use
utilities
::{
pub
use
utilities
::{
context
,
remove_root_ui
,
widget_update_with_resource
,
EmptyProps
,
StateUIRoot
,
context
,
remove_root_ui
,
remove_tagged_root
,
widget_update_with_resource
,
EmptyProps
,
StateUIRoot
,
};
};
pub
mod
prelude
{
pub
mod
prelude
{
...
...
This diff is collapsed.
Click to expand it.
src/utilities.rs
+
49
−
40
View file @
6bbbcd60
...
@@ -19,34 +19,34 @@ pub struct EmptyProps;
...
@@ -19,34 +19,34 @@ pub struct EmptyProps;
#[macro_export]
#[macro_export]
macro_rules!
empty_props
{
macro_rules!
empty_props
{
(
$name
:
ident
)
=>
{
(
$name
:
ident
)
=>
{
#[derive(::bevy::prelude::Component,
Clone,
PartialEq,
Default)]
#[derive(
$
crate
::bevy::prelude::Component,
Clone,
PartialEq,
Default)]
#[repr(transparent)]
#[repr(transparent)]
pub
struct
$name
(
$crate
::
ui
::
utilities
::
EmptyProps
);
pub
struct
$name
(
$crate
::
EmptyProps
);
impl
kayak_ui
::
prelude
::
Widget
for
$name
{}
impl
$crate
::
kayak_ui
::
prelude
::
Widget
for
$name
{}
};
};
}
}
#[macro_export]
#[macro_export]
macro_rules!
basic_widget
{
macro_rules!
basic_widget
{
(
$props
:
ident
=>
$name
:
ident
)
=>
{
(
$props
:
ident
=>
$name
:
ident
)
=>
{
#[derive(bevy::prelude::Bundle)]
#[derive(
$
crate::
bevy::prelude::Bundle)]
pub
struct
$name
{
pub
struct
$name
{
pub
props
:
$props
,
pub
props
:
$props
,
pub
name
:
::
kayak_ui
::
prelude
::
WidgetName
,
pub
name
:
$crate
::
kayak_ui
::
prelude
::
WidgetName
,
pub
styles
:
::
kayak_ui
::
prelude
::
KStyle
,
pub
styles
:
$crate
::
kayak_ui
::
prelude
::
KStyle
,
pub
computed_styles
:
::
kayak_ui
::
prelude
::
ComputedStyles
,
pub
computed_styles
:
$crate
::
kayak_ui
::
prelude
::
ComputedStyles
,
pub
on_event
:
::
kayak_ui
::
prelude
::
OnEvent
,
pub
on_event
:
$crate
::
kayak_ui
::
prelude
::
OnEvent
,
}
}
impl
std
::
default
::
Default
for
$name
{
impl
std
::
default
::
Default
for
$name
{
fn
default
()
->
$name
{
fn
default
()
->
$name
{
let
props
=
$props
::
default
();
let
props
=
$props
::
default
();
$name
{
$name
{
name
:
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
props
),
name
:
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
props
),
props
,
props
,
styles
:
::
kayak_ui
::
prelude
::
KStyle
::
default
(),
styles
:
$crate
::
kayak_ui
::
prelude
::
KStyle
::
default
(),
computed_styles
:
::
kayak_ui
::
prelude
::
ComputedStyles
::
default
(),
computed_styles
:
$crate
::
kayak_ui
::
prelude
::
ComputedStyles
::
default
(),
on_event
:
::
kayak_ui
::
prelude
::
OnEvent
::
default
(),
on_event
:
$crate
::
kayak_ui
::
prelude
::
OnEvent
::
default
(),
}
}
}
}
}
}
...
@@ -55,26 +55,26 @@ macro_rules! basic_widget {
...
@@ -55,26 +55,26 @@ macro_rules! basic_widget {
#[macro_export]
#[macro_export]
macro_rules!
parent_widget
{
macro_rules!
parent_widget
{
(
$props
:
ident
=>
$name
:
ident
)
=>
{
(
$props
:
ident
=>
$name
:
ident
)
=>
{
#[derive(bevy::prelude::Bundle)]
#[derive(
$
crate::
bevy::prelude::Bundle)]
pub
struct
$name
{
pub
struct
$name
{
pub
props
:
$props
,
pub
props
:
$props
,
pub
name
:
::
kayak_ui
::
prelude
::
WidgetName
,
pub
name
:
$crate
::
kayak_ui
::
prelude
::
WidgetName
,
pub
styles
:
::
kayak_ui
::
prelude
::
KStyle
,
pub
styles
:
$crate
::
kayak_ui
::
prelude
::
KStyle
,
pub
computed_styles
:
::
kayak_ui
::
prelude
::
ComputedStyles
,
pub
computed_styles
:
$crate
::
kayak_ui
::
prelude
::
ComputedStyles
,
pub
children
:
::
kayak_ui
::
prelude
::
KChildren
,
pub
children
:
$crate
::
kayak_ui
::
prelude
::
KChildren
,
pub
on_event
:
::
kayak_ui
::
prelude
::
OnEvent
,
pub
on_event
:
$crate
::
kayak_ui
::
prelude
::
OnEvent
,
}
}
impl
std
::
default
::
Default
for
$name
{
impl
std
::
default
::
Default
for
$name
{
fn
default
()
->
$name
{
fn
default
()
->
$name
{
let
props
=
$props
::
default
();
let
props
=
$props
::
default
();
$name
{
$name
{
name
:
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
props
),
name
:
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
props
),
props
,
props
,
styles
:
::
kayak_ui
::
prelude
::
KStyle
::
default
(),
styles
:
$crate
::
kayak_ui
::
prelude
::
KStyle
::
default
(),
computed_styles
:
::
kayak_ui
::
prelude
::
ComputedStyles
::
default
(),
computed_styles
:
$crate
::
kayak_ui
::
prelude
::
ComputedStyles
::
default
(),
children
:
::
kayak_ui
::
prelude
::
KChildren
::
default
(),
children
:
$crate
::
kayak_ui
::
prelude
::
KChildren
::
default
(),
on_event
:
::
kayak_ui
::
prelude
::
OnEvent
::
default
(),
on_event
:
$crate
::
kayak_ui
::
prelude
::
OnEvent
::
default
(),
}
}
}
}
}
}
...
@@ -86,8 +86,8 @@ macro_rules! register_widget {
...
@@ -86,8 +86,8 @@ macro_rules! register_widget {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
)
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
)
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
::
kayak_ui
::
prelude
::
widget_update
::
<
$props
,
$state
>
,
$crate
::
kayak_ui
::
prelude
::
widget_update
::
<
$props
,
$state
>
,
$system
,
$system
,
);
);
}};
}};
...
@@ -98,7 +98,7 @@ macro_rules! register_widget_with_update {
...
@@ -98,7 +98,7 @@ macro_rules! register_widget_with_update {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
$update
:
expr
)
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
$update
:
expr
)
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$update
,
$update
,
$system
,
$system
,
);
);
...
@@ -110,8 +110,8 @@ macro_rules! register_widget_with_resource {
...
@@ -110,8 +110,8 @@ macro_rules! register_widget_with_resource {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$resource
:
ident
,
$system
:
ident
)
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$resource
:
ident
,
$system
:
ident
)
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
ui
::
utilities
::
widget_update_with_resource
::
<
$props
,
$state
,
$resource
>
,
$crate
::
widget_update_with_resource
::
<
$props
,
$state
,
$resource
>
,
$system
,
$system
,
);
);
}};
}};
...
@@ -122,8 +122,8 @@ macro_rules! register_widget_with_context {
...
@@ -122,8 +122,8 @@ macro_rules! register_widget_with_context {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
path
,
$context
:
ident
,
$system
:
ident
)
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
path
,
$context
:
ident
,
$system
:
ident
)
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
::
kayak_ui
::
prelude
::
widget_update_with_context
::
<
$props
,
$state
,
$context
>
,
$crate
::
kayak_ui
::
prelude
::
widget_update_with_context
::
<
$props
,
$state
,
$context
>
,
$system
,
$system
,
);
);
}};
}};
...
@@ -134,11 +134,11 @@ macro_rules! register_widget_with_many_resources {
...
@@ -134,11 +134,11 @@ macro_rules! register_widget_with_many_resources {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
$
(
$name
:
ident
:
$resource
:
ident
),
+
)
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
$
(
$name
:
ident
:
$resource
:
ident
),
+
)
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
|
|
::
bevy
::
prelude
::
In
((
widget_context
,
entity
,
previous_entity
)):
::
bevy
::
prelude
::
In
<
(::
kayak_ui
::
prelude
::
KayakWidgetContext
,
::
bevy
::
prelude
::
Entity
,
::
bevy
::
prelude
::
Entity
)
>
,
$crate
::
bevy
::
prelude
::
In
((
widget_context
,
entity
,
previous_entity
)):
$crate
::
bevy
::
prelude
::
In
<
(
$crate
::
kayak_ui
::
prelude
::
KayakWidgetContext
,
$crate
::
bevy
::
prelude
::
Entity
,
$crate
::
bevy
::
prelude
::
Entity
)
>
,
$
(
$name
:
::
bevy
::
prelude
::
Res
<
$resource
>
),
+
,
$
(
$name
:
$crate
::
bevy
::
prelude
::
Res
<
$resource
>
),
+
,
widget_param
:
::
kayak_ui
::
prelude
::
WidgetParam
<
$props
,
$state
>
,
widget_param
:
$crate
::
kayak_ui
::
prelude
::
WidgetParam
<
$props
,
$state
>
,
|
{
|
{
widget_param
.has_changed
(
&
widget_context
,
entity
,
previous_entity
)
widget_param
.has_changed
(
&
widget_context
,
entity
,
previous_entity
)
$
(
||
$name
.is_changed
()
)
+
$
(
||
$name
.is_changed
()
)
+
...
@@ -153,12 +153,12 @@ macro_rules! register_complex_widget {
...
@@ -153,12 +153,12 @@ macro_rules! register_complex_widget {
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
R
(
$
(
$r_name
:
ident
:
$resource
:
ident
),
*
),
C
(
$
(
$c_name
:
ident
:
$context
:
ident
),
*
))
=>
{{
(
$ctx
:
expr
,
$props
:
ident
,
$state
:
ident
,
$system
:
ident
,
R
(
$
(
$r_name
:
ident
:
$resource
:
ident
),
*
),
C
(
$
(
$c_name
:
ident
:
$context
:
ident
),
*
))
=>
{{
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_data
::
<
$props
,
$state
>
();
$ctx
.add_widget_system
(
$ctx
.add_widget_system
(
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
$crate
::
kayak_ui
::
prelude
::
Widget
::
get_name
(
&
$props
::
default
()),
|
|
::
bevy
::
prelude
::
In
((
widget_context
,
entity
,
previous_entity
)):
::
bevy
::
prelude
::
In
<
(::
kayak_ui
::
prelude
::
KayakWidgetContext
,
::
bevy
::
prelude
::
Entity
,
::
bevy
::
prelude
::
Entity
)
>
,
$crate
::
bevy
::
prelude
::
In
((
widget_context
,
entity
,
previous_entity
)):
$crate
::
bevy
::
prelude
::
In
<
(
$crate
::
kayak_ui
::
prelude
::
KayakWidgetContext
,
$crate
::
bevy
::
prelude
::
Entity
,
$crate
::
bevy
::
prelude
::
Entity
)
>
,
$
(
$r_name
:
::
bevy
::
prelude
::
Res
<
$resource
>
),
*
,
$
(
$r_name
:
$crate
::
bevy
::
prelude
::
Res
<
$resource
>
),
*
,
$
(
$c_name
:
::
bevy
::
prelude
::
Query
<
::
bevy
::
prelude
::
Entity
,
::
bevy
::
prelude
::
Changed
<
$context
>>
),
*
,
$
(
$c_name
:
$crate
::
bevy
::
prelude
::
Query
<
$crate
::
bevy
::
prelude
::
Entity
,
$crate
::
bevy
::
prelude
::
Changed
<
$context
>>
),
*
,
widget_param
:
::
kayak_ui
::
prelude
::
WidgetParam
<
$props
,
$state
>
,
widget_param
:
$crate
::
kayak_ui
::
prelude
::
WidgetParam
<
$props
,
$state
>
,
|
{
|
{
$
(
$
(
if
let
Some
(
context_entity
)
=
widget_context
.get_context_entity
::
<
$context
>
(
entity
)
{
if
let
Some
(
context_entity
)
=
widget_context
.get_context_entity
::
<
$context
>
(
entity
)
{
...
@@ -200,6 +200,15 @@ pub fn remove_root_ui(
...
@@ -200,6 +200,15 @@ pub fn remove_root_ui(
}
}
}
}
pub
fn
remove_tagged_root
<
T
:
Component
>
(
mut
commands
:
Commands
,
query
:
Query
<
Entity
,
(
With
<
KayakRootContext
>
,
With
<
T
>
)
>
,
)
{
for
entity
in
&
query
{
commands
.entity
(
entity
)
.despawn_recursive
();
}
}
pub
mod
context
{
pub
mod
context
{
use
kayak_ui
::
prelude
::{
EmptyState
,
KayakRootContext
};
use
kayak_ui
::
prelude
::{
EmptyState
,
KayakRootContext
};
use
kayak_ui
::
widgets
::
KayakWidgetsContextPlugin
;
use
kayak_ui
::
widgets
::
KayakWidgetsContextPlugin
;
...
@@ -259,7 +268,7 @@ pub type OnEventParams = In<(EventDispatcherContext, WidgetState, Event, Entity)
...
@@ -259,7 +268,7 @@ pub type OnEventParams = In<(EventDispatcherContext, WidgetState, Event, Entity)
macro_rules!
on_button_click
{
macro_rules!
on_button_click
{
(
$param_type
:
ty
,
$func_body
:
expr
)
=>
{
(
$param_type
:
ty
,
$func_body
:
expr
)
=>
{
$crate
::
kayak_ui
::
prelude
::
OnEvent
::
new
(
$crate
::
kayak_ui
::
prelude
::
OnEvent
::
new
(
move
|::
bevy
::
prelude
::
In
((
move
|
$crate
::
bevy
::
prelude
::
In
((
event_dispatcher_context
,
event_dispatcher_context
,
_widget_state
,
_widget_state
,
event
,
event
,
...
...
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