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
d917c988
Commit
d917c988
authored
3 years ago
by
MrGVSV
Browse files
Options
Downloads
Patches
Plain Diff
Documented event types
This includes InputEvent, EventType, EventCategory, and InputEventCategory
parent
0be194cf
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
kayak_core/src/event.rs
+18
-0
18 additions, 0 deletions
kayak_core/src/event.rs
kayak_core/src/input_event.rs
+10
-0
10 additions, 0 deletions
kayak_core/src/input_event.rs
kayak_core/src/on_event.rs
+4
-0
4 additions, 0 deletions
kayak_core/src/on_event.rs
with
32 additions
and
0 deletions
kayak_core/src/event.rs
+
18
−
0
View file @
d917c988
use
crate
::
cursor
::
CursorEvent
;
use
crate
::{
Index
,
KeyboardEvent
};
/// An event type sent to widgets
#[derive(Debug,
Clone,
Copy,
PartialEq)]
pub
struct
Event
{
/// The node targeted by this event
...
...
@@ -70,37 +71,54 @@ impl Event {
/// with a custom wrapper.
#[derive(Debug,
Clone,
Copy)]
pub
enum
EventType
{
/// An event that occurs when the user clicks a widget
Click
(
CursorEvent
),
/// An event that occurs when the user hovers the cursor over a widget
Hover
(
CursorEvent
),
/// An event that occurs when the user moves the cursor into a widget
MouseIn
(
CursorEvent
),
/// An event that occurs when the user moves the cursor out of a widget
MouseOut
(
CursorEvent
),
/// An event that occurs when the user presses down on the cursor over a widget
MouseDown
(
CursorEvent
),
/// An event that occurs when the user releases the cursor over a widget
MouseUp
(
CursorEvent
),
/// An event that occurs when a widget receives focus
Focus
,
/// An event that occurs when a widget loses focus
Blur
,
/// An event that occurs when the user types in a character within a _focused_ widget
CharInput
{
c
:
char
},
/// An event that occurs when the user releases a key within a _focused_ widget
KeyUp
(
KeyboardEvent
),
/// An event that occurs when the user presses a key down within a _focused_ widget
KeyDown
(
KeyboardEvent
),
}
impl
Eq
for
EventType
{}
/// __Note:__ Only checks if the two event types are the same discriminant
impl
PartialEq
for
EventType
{
fn
eq
(
&
self
,
other
:
&
Self
)
->
bool
{
std
::
mem
::
discriminant
(
self
)
==
std
::
mem
::
discriminant
(
other
)
}
}
/// __Note:__ Only uses the discriminant for hashing
impl
std
::
hash
::
Hash
for
EventType
{
fn
hash
<
H
:
std
::
hash
::
Hasher
>
(
&
self
,
state
:
&
mut
H
)
{
std
::
hash
::
Hash
::
hash
(
&
std
::
mem
::
discriminant
(
self
),
state
);
}
}
/// The various categories an event can belong to
#[derive(Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash)]
pub
enum
EventCategory
{
/// A category for events related to the mouse/cursor
Mouse
,
/// A category for events related to the keyboard
Keyboard
,
/// A category for events related to focus
Focus
,
}
...
...
This diff is collapsed.
Click to expand it.
kayak_core/src/input_event.rs
+
10
−
0
View file @
d917c988
use
crate
::
KeyCode
;
/// Events sent to [`KayakContext`](crate::KayakContext) containing user input data
#[derive(Debug,
PartialEq)]
pub
enum
InputEvent
{
/// An event that occurs when the user moves the mouse
MouseMoved
((
f32
,
f32
)),
/// An event that occurs when the user presses the left mouse button
MouseLeftPress
,
/// An event that occurs when the user releases the left mouse button
MouseLeftRelease
,
/// An event that occurs when the user types in a character
CharEvent
{
c
:
char
},
/// An event that occurs when the user presses or releases a key
Keyboard
{
key
:
KeyCode
,
is_pressed
:
bool
},
}
/// The various categories an input event can belong to
pub
enum
InputEventCategory
{
/// A category for events related to the mouse/cursor
Mouse
,
/// A category for events related to the keyboard
Keyboard
,
// TODO: Gamepad, etc.
}
impl
InputEvent
{
/// Get the category of this input event
pub
fn
category
(
&
self
)
->
InputEventCategory
{
match
self
{
// Mouse events
...
...
This diff is collapsed.
Click to expand it.
kayak_core/src/on_event.rs
+
4
−
0
View file @
d917c988
...
...
@@ -3,6 +3,10 @@ use std::fmt::{Debug, Formatter};
use
std
::
sync
::{
Arc
,
RwLock
};
/// A container for a function that handles events
///
/// This differs from a standard [`Handler`](crate::Handler) in that it's sent directly
/// from the [`KayakContext`](crate::KayakContext) and gives the [`KayakContextRef`]
/// as a parameter.
#[derive(Clone)]
pub
struct
OnEvent
(
Arc
<
RwLock
<
dyn
FnMut
(
&
mut
KayakContextRef
,
&
mut
Event
)
+
Send
+
Sync
+
'static
>>
,
...
...
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