Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI
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
Commits
0af32b00
Commit
0af32b00
authored
3 years ago
by
MrGVSV
Browse files
Options
Downloads
Patches
Plain Diff
Extracted ChangeEvent and made it generic
parent
ea84d912
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/text_box.rs
+2
-1
2 additions, 1 deletion
examples/text_box.rs
kayak_core/src/event.rs
+37
-0
37 additions, 0 deletions
kayak_core/src/event.rs
kayak_widgets/src/text_box.rs
+5
-29
5 additions, 29 deletions
kayak_widgets/src/text_box.rs
with
44 additions
and
30 deletions
examples/text_box.rs
+
2
−
1
View file @
0af32b00
...
@@ -3,13 +3,14 @@ use bevy::{
...
@@ -3,13 +3,14 @@ use bevy::{
window
::
WindowDescriptor
,
window
::
WindowDescriptor
,
DefaultPlugins
,
DefaultPlugins
,
};
};
use
kayak_core
::
OnChange
;
use
kayak_ui
::
bevy
::{
BevyContext
,
BevyKayakUIPlugin
,
FontMapping
,
UICameraBundle
};
use
kayak_ui
::
bevy
::{
BevyContext
,
BevyKayakUIPlugin
,
FontMapping
,
UICameraBundle
};
use
kayak_ui
::
core
::{
use
kayak_ui
::
core
::{
render
,
rsx
,
render
,
rsx
,
styles
::{
Style
,
StyleProp
,
Units
},
styles
::{
Style
,
StyleProp
,
Units
},
widget
,
Bound
,
Index
,
MutableBound
,
widget
,
Bound
,
Index
,
MutableBound
,
};
};
use
kayak_widgets
::{
App
,
OnChange
,
TextBox
,
Window
};
use
kayak_widgets
::{
App
,
TextBox
,
Window
};
#[widget]
#[widget]
fn
TextBoxExample
(
context
:
&
mut
KayakContext
)
{
fn
TextBoxExample
(
context
:
&
mut
KayakContext
)
{
...
...
This diff is collapsed.
Click to expand it.
kayak_core/src/event.rs
+
37
−
0
View file @
0af32b00
use
std
::
sync
::{
Arc
,
RwLock
};
use
crate
::{
Index
,
KeyCode
};
use
crate
::{
Index
,
KeyCode
};
#[derive(Debug,
Clone,
Copy,
PartialEq)]
#[derive(Debug,
Clone,
Copy,
PartialEq)]
...
@@ -28,3 +29,39 @@ pub enum EventType {
...
@@ -28,3 +29,39 @@ pub enum EventType {
CharInput
{
c
:
char
},
CharInput
{
c
:
char
},
KeyboardInput
{
key
:
KeyCode
},
KeyboardInput
{
key
:
KeyCode
},
}
}
/// An event denoting a change of some type
#[derive(Debug,
Clone,
PartialEq)]
pub
struct
ChangeEvent
<
T
>
{
pub
value
:
T
,
}
/// A handler struct for a [ChangeEvent].
///
/// ## Example
/// ```rust
/// let handler = OnChange::new(move |event| {
/// let value = event.value;
/// // Do something...
/// });
/// ```
#[derive(Clone)]
pub
struct
OnChange
<
T
>
(
pub
Arc
<
RwLock
<
dyn
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>>
);
impl
<
T
>
OnChange
<
T
>
{
pub
fn
new
<
F
:
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>
(
f
:
F
)
->
Self
{
Self
(
Arc
::
new
(
RwLock
::
new
(
f
)))
}
}
impl
<
T
>
PartialEq
for
OnChange
<
T
>
{
fn
eq
(
&
self
,
_other
:
&
Self
)
->
bool
{
true
}
}
impl
<
T
>
std
::
fmt
::
Debug
for
OnChange
<
T
>
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
f
.debug_tuple
(
"OnChange"
)
.finish
()
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kayak_widgets/src/text_box.rs
+
5
−
29
View file @
0af32b00
use
std
::
sync
::{
Arc
,
RwLock
};
use
kayak_ui
::
core
::{
use
kayak_ui
::
core
::{
Bound
,
ChangeEvent
,
Color
,
EventType
,
MutableBound
,
OnChange
,
OnEvent
,
render_command
::
RenderCommand
,
render_command
::
RenderCommand
,
rsx
,
rsx
,
styles
::{
Style
,
StyleProp
,
Units
},
styles
::{
Style
,
StyleProp
,
Units
},
widget
,
Bound
,
Color
,
EventType
,
MutableBound
,
OnEvent
,
widget
};
};
use
std
::
sync
::{
Arc
,
RwLock
};
use
crate
::{
Background
,
Clip
,
Text
};
use
crate
::{
Background
,
Clip
,
Text
};
#[derive(Debug,
Clone,
PartialEq)]
pub
struct
ChangeEvent
{
pub
value
:
String
,
}
#[derive(Clone)]
pub
struct
OnChange
(
pub
Arc
<
RwLock
<
dyn
FnMut
(
ChangeEvent
)
+
Send
+
Sync
+
'static
>>
);
impl
OnChange
{
pub
fn
new
<
F
:
FnMut
(
ChangeEvent
)
+
Send
+
Sync
+
'static
>
(
f
:
F
)
->
OnChange
{
OnChange
(
Arc
::
new
(
RwLock
::
new
(
f
)))
}
}
impl
PartialEq
for
OnChange
{
fn
eq
(
&
self
,
_other
:
&
Self
)
->
bool
{
true
}
}
impl
std
::
fmt
::
Debug
for
OnChange
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
f
.debug_tuple
(
"OnChange"
)
.finish
()
}
}
#[derive(Debug,
Clone,
Copy,
PartialEq)]
#[derive(Debug,
Clone,
Copy,
PartialEq)]
pub
struct
Focus
(
pub
bool
);
pub
struct
Focus
(
pub
bool
);
#[widget(focusable)]
#[widget(focusable)]
pub
fn
TextBox
(
value
:
String
,
on_change
:
Option
<
OnChange
>
)
{
pub
fn
TextBox
(
value
:
String
,
on_change
:
Option
<
OnChange
<
String
>
>
)
{
*
styles
=
Some
(
Style
{
*
styles
=
Some
(
Style
{
render_command
:
StyleProp
::
Value
(
RenderCommand
::
Layout
),
render_command
:
StyleProp
::
Value
(
RenderCommand
::
Layout
),
..
styles
.clone
()
.unwrap_or_default
()
..
styles
.clone
()
.unwrap_or_default
()
...
...
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