-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add highlight interaction to plugins
- Loading branch information
1 parent
36d1559
commit 9d3a609
Showing
8 changed files
with
48 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use bevy::prelude::*; | ||
|
||
pub struct InteractionColorPlugin; | ||
|
||
impl Plugin for InteractionColorPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_type::<InteractionColor>() | ||
.add_systems(Update, update_button_color); | ||
} | ||
} | ||
|
||
// The background color to use for each interaction state | ||
#[derive(Component, Reflect)] | ||
pub struct InteractionColor { | ||
pub normal: Color, | ||
pub hovered: Color, | ||
pub pressed: Color, | ||
} | ||
|
||
fn update_button_color( | ||
mut interaction_query: Query< | ||
(&InteractionColor, &Interaction, &mut BackgroundColor), | ||
Changed<Interaction>, | ||
>, | ||
) { | ||
for (palette, interaction, mut color) in &mut interaction_query { | ||
color.0 = match interaction { | ||
Interaction::None => palette.normal, | ||
Interaction::Hovered => palette.hovered, | ||
Interaction::Pressed => palette.pressed, | ||
} | ||
} | ||
} |