Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4848eff
Add `Ui::close` and `Response::should_close`
lucasmerlin Feb 19, 2025
7e8d4f7
Fixes
lucasmerlin Feb 19, 2025
1b749fb
Replace `close_menu` with `close`
lucasmerlin Feb 19, 2025
06f607a
Snapshots
lucasmerlin Feb 19, 2025
51cf5e8
Fix log
lucasmerlin Feb 19, 2025
b0747c5
New menu based on egui::Popup
lucasmerlin Feb 13, 2025
7c162d9
Split SubMenuButton
lucasmerlin Feb 19, 2025
91f39af
Handle Ui::close
lucasmerlin Feb 19, 2025
b9c1a1f
Handle clicked_outside and fix sub menus staying open
lucasmerlin Feb 19, 2025
830bead
Add `Button::right_text` and use it in menu
lucasmerlin Feb 20, 2025
0e33213
Apply open style to opened submenu button
lucasmerlin Feb 20, 2025
7bd3750
Correct menu offset
lucasmerlin Feb 20, 2025
3410269
Correctly handle all close behaviors
lucasmerlin Feb 20, 2025
910faaa
Always add popups to the layers open_popups (prevents tooltip from sh…
lucasmerlin Feb 20, 2025
b1d206a
Ensure submenus are closed when the menu wasn't shown for any reason
lucasmerlin Feb 20, 2025
eb9b9be
Add `Bar` and `MenuButton`, migrate the `Ui` helpers to use the new m…
lucasmerlin Feb 20, 2025
e3dfe20
Add is_popup_open
lucasmerlin Feb 20, 2025
58e4c95
Make the popup demo nicer and remove old context menu demo
lucasmerlin Feb 20, 2025
db9b149
Documentation improvements
lucasmerlin Feb 20, 2025
3e2a3df
Merge branch 'master' into lucas/popup-based-menu
lucasmerlin Feb 20, 2025
b9c8e00
Small improvements
lucasmerlin Feb 20, 2025
56e9e6f
Fixes after self-review
lucasmerlin Feb 20, 2025
1158c49
Replace icon
lucasmerlin Feb 20, 2025
ab0f83d
Merge remote-tracking branch 'origin/lucas/popup-based-menu' into luc…
lucasmerlin Feb 20, 2025
fdcc6dc
Properly support setting a different PopupCloseBehavior in a submenu.…
lucasmerlin Feb 21, 2025
a312478
Fix panel resizing not working (I forgot to return the old widget_rect)
lucasmerlin Feb 28, 2025
b4600ce
Remove some unnecessary close calls
lucasmerlin Feb 28, 2025
a820418
Add StyleModifier
lucasmerlin Feb 28, 2025
1d073de
Fix egui crashing when menu is shown on first frame
lucasmerlin Mar 2, 2025
669afa6
Add reset button
lucasmerlin Mar 3, 2025
d6b1e09
Close docs
lucasmerlin Mar 3, 2025
c2c9872
Remove unnecessary close call
lucasmerlin Mar 3, 2025
11277da
Rename `Ui::will_close` to `will_parent_close`
lucasmerlin Mar 3, 2025
0a5887b
Remove Button::right_text_weak
lucasmerlin Mar 3, 2025
bd3aacd
Small changes
lucasmerlin Mar 3, 2025
be048af
Update snapshot
lucasmerlin Mar 3, 2025
86ffb6d
Merge branch 'master' into lucas/popup-based-menu
lucasmerlin Mar 3, 2025
44d9efe
Use Response::interact_rect
lucasmerlin Mar 3, 2025
c3a0da2
Fix menu alignment
lucasmerlin Mar 3, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ dependencies = [
"eframe",
"egui",
"egui-wgpu",
"egui_extras",
"image",
"kittest",
"pollster 0.4.0",
Expand Down
31 changes: 20 additions & 11 deletions crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl AreaState {
///
/// The previous rectangle used by this area can be obtained through [`crate::Memory::area_rect()`].
#[must_use = "You should call .show()"]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Debug)]
pub struct Area {
pub(crate) id: Id,
kind: UiKind,
info: UiStackInfo,
sense: Option<Sense>,
movable: bool,
interactable: bool,
Expand All @@ -132,7 +132,7 @@ impl Area {
pub fn new(id: Id) -> Self {
Self {
id,
kind: UiKind::GenericArea,
info: UiStackInfo::new(UiKind::GenericArea),
sense: None,
movable: true,
interactable: true,
Expand Down Expand Up @@ -164,7 +164,16 @@ impl Area {
/// Default to [`UiKind::GenericArea`].
#[inline]
pub fn kind(mut self, kind: UiKind) -> Self {
self.kind = kind;
self.info = UiStackInfo::new(kind);
self
}

/// Set the [`UiStackInfo`] of the area's [`Ui`].
///
/// Default to [`UiStackInfo::new(UiKind::GenericArea)`].
#[inline]
pub fn info(mut self, info: UiStackInfo) -> Self {
self.info = info;
self
}

Expand Down Expand Up @@ -351,7 +360,7 @@ impl Area {
}

pub(crate) struct Prepared {
kind: UiKind,
info: Option<UiStackInfo>,
layer_id: LayerId,
state: AreaState,
move_response: Response,
Expand All @@ -376,7 +385,7 @@ impl Area {
ctx: &Context,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let prepared = self.begin(ctx);
let mut prepared = self.begin(ctx);
let mut content_ui = prepared.content_ui(ctx);
let inner = add_contents(&mut content_ui);
let response = prepared.end(ctx, content_ui);
Expand All @@ -386,7 +395,7 @@ impl Area {
pub(crate) fn begin(self, ctx: &Context) -> Prepared {
let Self {
id,
kind,
info,
sense,
movable,
order,
Expand Down Expand Up @@ -518,7 +527,7 @@ impl Area {
move_response.interact_rect = state.rect();

Prepared {
kind,
info: Some(info),
layer_id,
state,
move_response,
Expand Down Expand Up @@ -549,11 +558,11 @@ impl Prepared {
self.constrain_rect
}

pub(crate) fn content_ui(&self, ctx: &Context) -> Ui {
pub(crate) fn content_ui(&mut self, ctx: &Context) -> Ui {
let max_rect = self.state.rect();

let mut ui_builder = UiBuilder::new()
.ui_stack_info(UiStackInfo::new(self.kind))
.ui_stack_info(self.info.take().unwrap_or_default())
.layer_id(self.layer_id)
.max_rect(max_rect)
.layout(self.layout)
Expand Down Expand Up @@ -596,7 +605,7 @@ impl Prepared {
#[allow(clippy::needless_pass_by_value)] // intentional to swallow up `content_ui`.
pub(crate) fn end(self, ctx: &Context, content_ui: Ui) -> Response {
let Self {
kind: _,
info: _,
layer_id,
mut state,
move_response: mut response,
Expand Down
7 changes: 4 additions & 3 deletions crates/egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use epaint::Shape;

use crate::{
epaint, style::WidgetVisuals, vec2, Align2, Context, Id, InnerResponse, NumExt, Painter, Popup,
PopupCloseBehavior, Rect, Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui,
UiBuilder, Vec2, WidgetInfo, WidgetText, WidgetType,
epaint, style::StyleModifier, style::WidgetVisuals, vec2, Align2, Context, Id, InnerResponse,
NumExt, Painter, Popup, PopupCloseBehavior, Rect, Response, ScrollArea, Sense, Stroke,
TextStyle, TextWrapMode, Ui, UiBuilder, Vec2, WidgetInfo, WidgetText, WidgetType,
};

#[allow(unused_imports)] // Documentation
Expand Down Expand Up @@ -374,6 +374,7 @@ fn combo_box_dyn<'c, R>(

let inner = Popup::menu(&button_response)
.id(popup_id)
.style(StyleModifier::default())
.width(button_response.rect.width())
.close_behavior(close_behavior)
.show(|ui| {
Expand Down
Loading