1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Highlight submenu buttons when hovered and open (#3780)

Submenu buttons in menues now properly highlight when hovered and when
opened.

…plus a bunch of other cleanup
This commit is contained in:
Emil Ernerfeldt
2024-01-07 22:08:32 +01:00
committed by GitHub
parent 327f599407
commit 8c30e8c5f7
13 changed files with 62 additions and 57 deletions

View File

@@ -502,7 +502,7 @@ impl<'open> Window<'open> {
// END FRAME --------------------------------
if let Some(title_bar) = title_bar {
if on_top {
if on_top && area_content_ui.visuals().window_highlight_topmost {
let rect = Rect::from_min_size(
outer_rect.min,
Vec2 {
@@ -515,7 +515,7 @@ impl<'open> Window<'open> {
round.se = 0.0;
round.sw = 0.0;
}
let header_color = area_content_ui.visuals().widgets.hovered.bg_fill;
let header_color = area_content_ui.visuals().widgets.open.weak_bg_fill;
area_content_ui.painter().set(
*where_to_put_header_background,

View File

@@ -440,11 +440,11 @@ impl SubMenuButton {
fn visuals<'a>(
ui: &'a Ui,
response: &'_ Response,
menu_state: &'_ MenuState,
response: &Response,
menu_state: &MenuState,
sub_id: Id,
) -> &'a WidgetVisuals {
if menu_state.is_open(sub_id) {
if menu_state.is_open(sub_id) && !response.hovered() {
&ui.style().visuals.widgets.open
} else {
ui.style().interact(response)
@@ -528,15 +528,15 @@ impl SubMenu {
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<Option<R>> {
let sub_id = ui.id().with(self.button.index);
let button = self.button.show(ui, &self.parent_state.read(), sub_id);
let response = self.button.show(ui, &self.parent_state.read(), sub_id);
self.parent_state
.write()
.submenu_button_interaction(ui, sub_id, &button);
.submenu_button_interaction(ui, sub_id, &response);
let inner = self
.parent_state
.write()
.show_submenu(ui.ctx(), sub_id, add_contents);
InnerResponse::new(inner, button)
InnerResponse::new(inner, response)
}
}

View File

@@ -779,6 +779,9 @@ pub struct Visuals {
pub window_fill: Color32,
pub window_stroke: Stroke,
/// Highlight the topmost window.
pub window_highlight_topmost: bool,
pub menu_rounding: Rounding,
/// Panel background color
@@ -1130,6 +1133,7 @@ impl Visuals {
window_shadow: Shadow::big_dark(),
window_fill: Color32::from_gray(27),
window_stroke: Stroke::new(1.0, Color32::from_gray(60)),
window_highlight_topmost: true,
menu_rounding: Rounding::same(6.0),
@@ -1247,7 +1251,7 @@ impl Widgets {
expansion: 1.0,
},
open: WidgetVisuals {
weak_bg_fill: Color32::from_gray(27),
weak_bg_fill: Color32::from_gray(45),
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
@@ -1694,6 +1698,7 @@ impl Visuals {
window_shadow,
window_fill,
window_stroke,
window_highlight_topmost,
menu_rounding,
@@ -1736,6 +1741,7 @@ impl Visuals {
stroke_ui(ui, window_stroke, "Outline");
rounding_ui(ui, window_rounding);
shadow_ui(ui, window_shadow, "Shadow");
ui.checkbox(window_highlight_topmost, "Highlight topmost Window");
});
ui.collapsing("Menus and popups", |ui| {