Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bevy Cosmic Edit
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
Bevy Cosmic Edit
Commits
ef84f0ed
Commit
ef84f0ed
authored
11 months ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
per-widget mouse cursor control
parent
2b65f131
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/every_option.rs
+1
-0
1 addition, 0 deletions
examples/every_option.rs
src/cosmic_edit.rs
+2
-0
2 additions, 0 deletions
src/cosmic_edit.rs
src/cursor.rs
+47
-34
47 additions, 34 deletions
src/cursor.rs
src/lib.rs
+1
-3
1 addition, 3 deletions
src/lib.rs
with
51 additions
and
37 deletions
examples/every_option.rs
+
1
−
0
View file @
ef84f0ed
...
...
@@ -42,6 +42,7 @@ fn setup(mut commands: Commands, mut font_system: ResMut<CosmicFontSystem>) {
// Computed fields
padding
:
Default
::
default
(),
widget_size
:
Default
::
default
(),
hover_cursor
:
Default
::
default
(),
})
.id
();
...
...
This diff is collapsed.
Click to expand it.
src/cosmic_edit.rs
+
2
−
0
View file @
ef84f0ed
...
...
@@ -81,6 +81,7 @@ pub struct CosmicEditBundle {
pub
text_position
:
CosmicTextPosition
,
pub
padding
:
CosmicPadding
,
pub
widget_size
:
CosmicWidgetSize
,
pub
hover_cursor
:
HoverCursor
,
}
impl
Default
for
CosmicEditBundle
{
...
...
@@ -107,6 +108,7 @@ impl Default for CosmicEditBundle {
x_offset
:
Default
::
default
(),
padding
:
Default
::
default
(),
widget_size
:
Default
::
default
(),
hover_cursor
:
Default
::
default
(),
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/cursor.rs
+
47
−
34
View file @
ef84f0ed
use
crate
::
*
;
use
bevy
::{
input
::
mouse
::
MouseMotion
,
prelude
::
*
,
window
::
PrimaryWindow
};
/// System set for mouse cursor systems. Runs in [`Update`]
#[derive(SystemSet,
Debug,
Clone,
PartialEq,
Eq,
Hash)]
pub
struct
CursorSet
;
pub
struct
CursorPlugin
{
pub
change_cursor
:
CursorConfig
,
}
pub
struct
CursorPlugin
;
impl
Plugin
for
CursorPlugin
{
fn
build
(
&
self
,
app
:
&
mut
App
)
{
match
self
.change_cursor
{
CursorConfig
::
Default
=>
{
app
.add_systems
(
Update
,
(
hover_sprites
,
hover_ui
,
change_cursor
))
.add_event
::
<
TextHoverIn
>
()
.add_event
::
<
TextHoverOut
>
();
}
CursorConfig
::
Events
=>
{
app
.add_systems
(
Update
,
(
hover_sprites
,
hover_ui
))
.add_event
::
<
TextHoverIn
>
()
.add_event
::
<
TextHoverOut
>
();
}
CursorConfig
::
None
=>
{}
}
app
.add_systems
(
Update
,
((
hover_sprites
,
hover_ui
),
change_cursor
)
.chain
())
.add_event
::
<
TextHoverIn
>
()
.add_event
::
<
TextHoverOut
>
();
}
}
/// For use with custom cursor control; Event is emitted when cursor enters a text widget
#[derive(Event)]
pub
struct
TextHoverIn
;
#[derive(Component,
Deref)]
pub
struct
HoverCursor
(
pub
CursorIcon
);
impl
Default
for
HoverCursor
{
fn
default
()
->
Self
{
Self
(
CursorIcon
::
Text
)
}
}
/// For use with custom cursor control; Event is emitted when cursor leaves a text widget
/// For use with custom cursor control
/// Event is emitted when cursor enters a text widget
/// Event contains the cursor from the buffer's [`HoverCursor`]
#[derive(Event,
Deref)]
pub
struct
TextHoverIn
(
pub
CursorIcon
);
/// For use with custom cursor control
/// Event is emitted when cursor leaves a text widget
#[derive(Event)]
pub
struct
TextHoverOut
;
pub
fn
change_cursor
(
evr_hover_in
:
EventReader
<
TextHoverIn
>
,
pub
(
crate
)
fn
change_cursor
(
mut
evr_hover_in
:
EventReader
<
TextHoverIn
>
,
evr_hover_out
:
EventReader
<
TextHoverOut
>
,
evr_text_changed
:
EventReader
<
CosmicTextChanged
>
,
evr_mouse_motion
:
EventReader
<
MouseMotion
>
,
...
...
@@ -46,15 +47,17 @@ pub fn change_cursor(
return
;
}
let
mut
window
=
windows
.single_mut
();
if
!
evr_hover_in
.is_empty
()
{
window
.cursor.icon
=
CursorIcon
::
Text
;
}
if
!
evr_hover_out
.is_empty
()
{
if
let
Some
(
ev
)
=
evr_hover_in
.read
()
.last
()
{
window
.cursor.icon
=
ev
.0
;
}
else
if
!
evr_hover_out
.is_empty
()
{
window
.cursor.icon
=
CursorIcon
::
Default
;
}
if
!
evr_text_changed
.is_empty
()
{
window
.cursor.visible
=
false
;
}
if
mouse_buttons
.get_just_pressed
()
.len
()
!=
0
||
!
evr_mouse_motion
.is_empty
()
{
window
.cursor.visible
=
true
;
}
...
...
@@ -67,9 +70,12 @@ type CameraQuery<'a, 'b, 'c, 'd> =
#[cfg(not(feature
=
"multicam"
))]
type
CameraQuery
<
'a
,
'b
,
'c
,
'd
>
=
Query
<
'a
,
'b
,
(
&
'c
Camera
,
&
'd
GlobalTransform
)
>
;
pub
fn
hover_sprites
(
pub
(
crate
)
fn
hover_sprites
(
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
mut
cosmic_edit_query
:
Query
<
(
&
mut
Sprite
,
&
Visibility
,
&
GlobalTransform
),
With
<
CosmicBuffer
>>
,
mut
cosmic_edit_query
:
Query
<
(
&
mut
Sprite
,
&
Visibility
,
&
GlobalTransform
,
&
HoverCursor
),
With
<
CosmicBuffer
>
,
>
,
camera_q
:
CameraQuery
,
mut
hovered
:
Local
<
bool
>
,
mut
last_hovered
:
Local
<
bool
>
,
...
...
@@ -82,7 +88,10 @@ pub fn hover_sprites(
}
let
window
=
windows
.single
();
let
(
camera
,
camera_transform
)
=
camera_q
.single
();
for
(
sprite
,
visibility
,
node_transform
)
in
&
mut
cosmic_edit_query
.iter_mut
()
{
let
mut
icon
=
CursorIcon
::
Default
;
for
(
sprite
,
visibility
,
node_transform
,
hover
)
in
&
mut
cosmic_edit_query
.iter_mut
()
{
if
visibility
==
Visibility
::
Hidden
{
continue
;
}
...
...
@@ -96,6 +105,7 @@ pub fn hover_sprites(
if
let
Some
(
pos
)
=
camera
.viewport_to_world_2d
(
camera_transform
,
pos
)
{
if
x_min
<
pos
.x
&&
pos
.x
<
x_max
&&
y_min
<
pos
.y
&&
pos
.y
<
y_max
{
*
hovered
=
true
;
icon
=
hover
.0
;
}
}
}
...
...
@@ -103,7 +113,7 @@ pub fn hover_sprites(
if
*
last_hovered
!=
*
hovered
{
if
*
hovered
{
evw_hover_in
.send
(
TextHoverIn
);
evw_hover_in
.send
(
TextHoverIn
(
icon
)
);
}
else
{
evw_hover_out
.send
(
TextHoverOut
);
}
...
...
@@ -112,18 +122,21 @@ pub fn hover_sprites(
*
last_hovered
=
*
hovered
;
}
pub
fn
hover_ui
(
mut
interaction_query
:
Query
<&
Interaction
,
(
Changed
<
Interaction
>
,
With
<
CosmicSource
>
)
>
,
pub
(
crate
)
fn
hover_ui
(
interaction_query
:
Query
<
(
&
Interaction
,
&
CosmicSource
),
Changed
<
Interaction
>>
,
cosmic_query
:
Query
<&
HoverCursor
,
With
<
CosmicBuffer
>>
,
mut
evw_hover_in
:
EventWriter
<
TextHoverIn
>
,
mut
evw_hover_out
:
EventWriter
<
TextHoverOut
>
,
)
{
for
interaction
in
interaction_query
.iter
_mut
()
{
for
(
interaction
,
source
)
in
interaction_query
.iter
()
{
match
interaction
{
Interaction
::
None
=>
{
evw_hover_out
.send
(
TextHoverOut
);
}
Interaction
::
Hovered
=>
{
evw_hover_in
.send
(
TextHoverIn
);
if
let
Ok
(
hover
)
=
cosmic_query
.get
(
source
.0
)
{
evw_hover_in
.send
(
TextHoverIn
(
hover
.0
));
}
}
_
=>
{}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
1
−
3
View file @
ef84f0ed
...
...
@@ -49,9 +49,7 @@ impl Plugin for CosmicEditPlugin {
WidgetPlugin
,
InputPlugin
,
FocusPlugin
,
CursorPlugin
{
change_cursor
:
self
.change_cursor
.clone
(),
},
CursorPlugin
,
PlaceholderPlugin
,
PasswordPlugin
,
EventsPlugin
,
...
...
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