Skip to content

Commit

Permalink
Fix context menu styling
Browse files Browse the repository at this point in the history
  • Loading branch information
lampsitter committed Jan 5, 2022
1 parent 01015ac commit 5c6f9c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
### Changed 🔧
* Renamed `Ui::visible` to `Ui::is_visible`.

### Fixed 🐛
* Context menu now respects the theme ([#1043](/~https://github.com/emilk/egui/pull/1043))

## 0.16.1 - 2021-12-31 - Add back `CtxRef::begin_frame,end_frame`

Expand Down
57 changes: 28 additions & 29 deletions egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use super::{
style::{Spacing, WidgetVisuals},
Align, CtxRef, Id, InnerResponse, PointerState, Pos2, Rect, Response, Sense, Style, TextStyle,
Ui, Vec2,
Align, CtxRef, Id, InnerResponse, PointerState, Pos2, Rect, Response, Sense, TextStyle, Ui,
Vec2,
};
use crate::{widgets::*, *};
use epaint::{mutex::RwLock, Stroke};
Expand Down Expand Up @@ -120,37 +120,44 @@ pub(crate) fn menu_ui<'c, R>(
ctx: &CtxRef,
menu_id: impl std::hash::Hash,
menu_state_arc: &Arc<RwLock<MenuState>>,
mut style: Style,
add_contents: impl FnOnce(&mut Ui) -> R + 'c,
) -> InnerResponse<R> {
let pos = {
let mut menu_state = menu_state_arc.write();
menu_state.entry_count = 0;
menu_state.rect.min
};
// style.visuals.widgets.active.bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.active.bg_stroke = Stroke::none();
// style.visuals.widgets.hovered.bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.hovered.bg_stroke = Stroke::none();
style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.inactive.bg_stroke = Stroke::none();

let area = Area::new(menu_id)
.order(Order::Foreground)
.fixed_pos(pos)
.interactable(false)
.drag_bounds(Rect::EVERYTHING);
let frame = Frame::menu(&style);
let inner_response = area.show(ctx, |ui| {
frame
.show(ui, |ui| {
const DEFAULT_MENU_WIDTH: f32 = 150.0; // TODO: add to ui.spacing
ui.set_max_width(DEFAULT_MENU_WIDTH);
ui.set_style(style);
ui.set_menu_state(Some(menu_state_arc.clone()));
ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents)
.inner
})
.inner
ui.scope(|ui| {
let style = ui.style_mut();
style.spacing = Spacing {
item_spacing: Vec2::ZERO,
button_padding: crate::vec2(2.0, 0.0),
..Default::default()
};

style.visuals.widgets.active.bg_stroke = Stroke::none();
style.visuals.widgets.hovered.bg_stroke = Stroke::none();
style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.inactive.bg_stroke = Stroke::none();

Frame::menu(style)
.show(ui, |ui| {
const DEFAULT_MENU_WIDTH: f32 = 150.0; // TODO: add to ui.spacing
ui.set_max_width(DEFAULT_MENU_WIDTH);
ui.set_menu_state(Some(menu_state_arc.clone()));
ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents)
.inner
})
.inner
})
.inner
});
menu_state_arc.write().rect = inner_response.response.rect;
inner_response
Expand Down Expand Up @@ -522,15 +529,7 @@ impl MenuState {
id: Id,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let style = Style {
spacing: Spacing {
item_spacing: Vec2::ZERO,
button_padding: crate::vec2(2.0, 0.0),
..Default::default()
},
..Default::default()
};
crate::menu::menu_ui(ctx, id, menu_state, style, add_contents)
crate::menu::menu_ui(ctx, id, menu_state, add_contents)
}
fn show_submenu<R>(
&mut self,
Expand Down

0 comments on commit 5c6f9c4

Please sign in to comment.