Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions crates/bevy_feathers/src/controls/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use bevy_picking::{hover::Hovered, PickingSystems};
use bevy_scene::{prelude::*, template_value};
use bevy_text::{FontSize, FontWeight};
use bevy_ui::{
AlignItems, BoxShadow, Display, FlexDirection, GlobalZIndex, InteractionDisabled,
JustifyContent, Node, OverrideClip, PositionType, Pressed, UiRect, Val,
px, AlignItems, AlignSelf, BoxShadow, Display, FlexDirection, GlobalZIndex,
InteractionDisabled, JustifyContent, Node, OverrideClip, PositionType, Pressed, UiRect, Val,
};
use bevy_ui_widgets::{
popover::{Popover, PopoverAlign, PopoverPlacement, PopoverSide},
Expand All @@ -37,7 +37,7 @@ use crate::{
};
use bevy_input_focus::{
tab_navigation::{NavAction, TabIndex},
InputFocus,
InputFocus, InputFocusVisible,
};

/// Parameters for the menu button template, passed to [`menu_button`] function.
Expand Down Expand Up @@ -296,14 +296,15 @@ fn update_menuitem_styles(
>,
mut commands: Commands,
focus: Res<InputFocus>,
focus_visible: Res<InputFocusVisible>,
) {
for (item_ent, disabled, pressed, hovered, bg_color, font_color) in q_menuitems.iter() {
set_menuitem_colors(
item_ent,
disabled,
pressed,
hovered.0,
Some(item_ent) == focus.get(),
Some(item_ent) == focus.get() && focus_visible.0,
bg_color,
font_color,
&mut commands,
Expand All @@ -326,6 +327,7 @@ fn update_menuitem_styles_remove(
mut removed_disabled: RemovedComponents<InteractionDisabled>,
mut removed_pressed: RemovedComponents<Pressed>,
focus: Res<InputFocus>,
focus_visible: Res<InputFocusVisible>,
mut commands: Commands,
) {
removed_disabled
Expand All @@ -340,7 +342,7 @@ fn update_menuitem_styles_remove(
disabled,
pressed,
hovered.0,
Some(item_ent) == focus.get(),
Some(item_ent) == focus.get() && focus_visible.0,
bg_color,
font_color,
&mut commands,
Expand All @@ -362,16 +364,17 @@ fn update_menuitem_styles_focus_changed(
With<FeathersMenuItem>,
>,
focus: Res<InputFocus>,
focus_visible: Res<InputFocusVisible>,
mut commands: Commands,
) {
if focus.is_changed() {
if focus.is_changed() || focus_visible.is_changed() {
for (item_ent, disabled, pressed, hovered, bg_color, font_color) in q_menuitems.iter() {
set_menuitem_colors(
item_ent,
disabled,
pressed,
hovered.0,
Some(item_ent) == focus.get(),
Some(item_ent) == focus.get() && focus_visible.0,
bg_color,
font_color,
&mut commands,
Expand Down Expand Up @@ -417,6 +420,19 @@ fn set_menuitem_colors(
}
}

/// A decorative divider between menu items
pub fn menu_divider() -> impl Scene {
bsn! {
Node {
height: px(1),
justify_content: JustifyContent::Start,
align_self: AlignSelf::Stretch,
margin: UiRect::axes(Val::Px(0.0), Val::Px(2.)),
}
ThemeBackgroundColor(tokens::MENU_BORDER) // Same as menu
}
}

/// Plugin which registers the systems for updating the menu and menu button styles.
pub struct MenuPlugin;

Expand Down
9 changes: 5 additions & 4 deletions examples/ui/widgets/feathers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use bevy::{
feathers::{
controls::{
button, checkbox, color_plane, color_slider, color_swatch, menu, menu_button,
menu_item, menu_popup, radio, slider, text_input, text_input_container, toggle_switch,
ButtonProps, ButtonVariant, ColorChannel, ColorPlane, ColorPlaneValue, ColorSlider,
ColorSliderProps, ColorSwatch, ColorSwatchValue, MenuButtonProps, MenuItemProps,
SliderBaseColor, SliderProps, TextInputProps,
menu_divider, menu_item, menu_popup, radio, slider, text_input, text_input_container,
toggle_switch, ButtonProps, ButtonVariant, ColorChannel, ColorPlane, ColorPlaneValue,
ColorSlider, ColorSliderProps, ColorSwatch, ColorSwatchValue, MenuButtonProps,
MenuItemProps, SliderBaseColor, SliderProps, TextInputProps,
},
cursor::{EntityCursor, OverrideCursor},
dark_theme::create_dark_theme,
Expand Down Expand Up @@ -159,6 +159,7 @@ fn demo_root() -> impl Scene {
info!("Menu item 2 clicked!");
})
),
:menu_divider,
(
menu_item(MenuItemProps {
caption: Box::new(bsn_list!(
Expand Down