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
5a3c0db5
Commit
5a3c0db5
authored
3 years ago
by
MrGVSV
Browse files
Options
Downloads
Patches
Plain Diff
Added convenience method for sending events
parent
0af32b00
No related branches found
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
-2
2 additions, 2 deletions
examples/text_box.rs
kayak_core/src/event.rs
+8
-0
8 additions, 0 deletions
kayak_core/src/event.rs
kayak_widgets/src/text_box.rs
+3
-5
3 additions, 5 deletions
kayak_widgets/src/text_box.rs
with
13 additions
and
7 deletions
examples/text_box.rs
+
2
−
2
View file @
5a3c0db5
...
@@ -25,12 +25,12 @@ fn TextBoxExample(context: &mut KayakContext) {
...
@@ -25,12 +25,12 @@ fn TextBoxExample(context: &mut KayakContext) {
};
};
let
cloned_value
=
value
.clone
();
let
cloned_value
=
value
.clone
();
let
on_change
=
OnChange
::
new
(
move
|
event
|
{
let
on_change
=
OnChange
::
new
_handler
(
move
|
event
|
{
cloned_value
.set
(
event
.value
);
cloned_value
.set
(
event
.value
);
});
});
let
cloned_value2
=
value2
.clone
();
let
cloned_value2
=
value2
.clone
();
let
on_change2
=
OnChange
::
new
(
move
|
event
|
{
let
on_change2
=
OnChange
::
new
_handler
(
move
|
event
|
{
cloned_value2
.set
(
event
.value
);
cloned_value2
.set
(
event
.value
);
});
});
...
...
This diff is collapsed.
Click to expand it.
kayak_core/src/event.rs
+
8
−
0
View file @
5a3c0db5
...
@@ -49,9 +49,17 @@ pub struct ChangeEvent<T> {
...
@@ -49,9 +49,17 @@ pub struct ChangeEvent<T> {
pub
struct
OnChange
<
T
>
(
pub
Arc
<
RwLock
<
dyn
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>>
);
pub
struct
OnChange
<
T
>
(
pub
Arc
<
RwLock
<
dyn
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>>
);
impl
<
T
>
OnChange
<
T
>
{
impl
<
T
>
OnChange
<
T
>
{
/// Create a new handler for a [ChangeEvent]
pub
fn
new
<
F
:
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>
(
f
:
F
)
->
Self
{
pub
fn
new
<
F
:
FnMut
(
ChangeEvent
<
T
>
)
+
Send
+
Sync
+
'static
>
(
f
:
F
)
->
Self
{
Self
(
Arc
::
new
(
RwLock
::
new
(
f
)))
Self
(
Arc
::
new
(
RwLock
::
new
(
f
)))
}
}
/// Send the given event to be handled by the current handler
pub
fn
send
(
&
self
,
event
:
ChangeEvent
<
T
>
)
{
if
let
Ok
(
mut
on_change
)
=
self
.0
.write
()
{
on_change
(
event
);
}
}
}
}
impl
<
T
>
PartialEq
for
OnChange
<
T
>
{
impl
<
T
>
PartialEq
for
OnChange
<
T
>
{
...
...
This diff is collapsed.
Click to expand it.
kayak_widgets/src/text_box.rs
+
3
−
5
View file @
5a3c0db5
...
@@ -47,11 +47,9 @@ pub fn TextBox(value: String, on_change: Option<OnChange<String>>) {
...
@@ -47,11 +47,9 @@ pub fn TextBox(value: String, on_change: Option<OnChange<String>>) {
current_value
.push
(
c
);
current_value
.push
(
c
);
}
}
if
let
Some
(
on_change
)
=
cloned_on_change
.as_ref
()
{
if
let
Some
(
on_change
)
=
cloned_on_change
.as_ref
()
{
if
let
Ok
(
mut
on_change
)
=
on_change
.0
.write
()
{
on_change
.send
(
ChangeEvent
{
on_change
(
ChangeEvent
{
value
:
current_value
.clone
(),
value
:
current_value
.clone
(),
});
});
}
}
}
}
}
EventType
::
Focus
=>
cloned_has_focus
.set
(
Focus
(
true
)),
EventType
::
Focus
=>
cloned_has_focus
.set
(
Focus
(
true
)),
...
...
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