Skip to content

Commit

Permalink
Fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBircksZR committed Jul 9, 2024
1 parent dc5f146 commit fea0e06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
18 changes: 18 additions & 0 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ pub fn menu_custom_button<R>(
stationary_menu_button_impl(ui, button, Box::new(add_contents))
}

/// Construct a top level menu with an image in a menu bar. This would be e.g. "File", "Edit" etc.
///
/// Responds to primary clicks.
///
/// Returns `None` if the menu is not open.
#[deprecated = "Use `menu_custom_button` instead"]
pub fn menu_image_button<R>(
ui: &mut Ui,
image_button: ImageButton<'_>,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<Option<R>> {
stationary_menu_button_impl(
ui,
Button::image(image_button.image),
Box::new(add_contents),
)
}

/// Construct a nested sub menu in another menu.
///
/// Opens on hover.
Expand Down
11 changes: 8 additions & 3 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,16 +2543,19 @@ impl Ui {
/// If called from within a menu this will instead create a button for a sub-menu.
///
/// ```ignore
/// # egui::__run_test_ui(|ui| {
/// let img = egui::include_image!("../assets/ferris.png");
///
/// ui.menu_image_button(img, |ui| {
/// ui.menu_image_button(title, img, |ui| {
/// ui.menu_button("My sub-menu", |ui| {
/// if ui.button("Close the menu").clicked() {
/// ui.close_menu();
/// }
/// });
/// });
/// # });
/// ```
///
///
/// See also: [`Self::close_menu`] and [`Response::context_menu`].
#[inline]
Expand All @@ -2572,17 +2575,19 @@ impl Ui {
///
/// If called from within a menu this will instead create a button for a sub-menu.
///
/// ```ignore
/// ```
/// # egui::__run_test_ui(|ui| {
/// let img = egui::include_image!("../assets/ferris.png");
/// let title = "My Menu";
///
/// ui.menu_text_image_button(title, img, |ui| {
/// ui.menu_image_text_button(img, title, |ui| {
/// ui.menu_button("My sub-menu", |ui| {
/// if ui.button("Close the menu").clicked() {
/// ui.close_menu();
/// }
/// });
/// });
/// # });
/// ```
///
/// See also: [`Self::close_menu`] and [`Response::context_menu`].
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/image_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::*;
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
#[derive(Clone, Debug)]
pub struct ImageButton<'a> {
image: Image<'a>,
pub(crate) image: Image<'a>,
sense: Sense,
frame: bool,
selected: bool,
Expand Down

0 comments on commit fea0e06

Please sign in to comment.