Skip to content

Commit

Permalink
Changing menu_image_button to use ImageButton builder (emilk#3288)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivy <[email protected]>
  • Loading branch information
v-kat and Ivy authored Sep 4, 2023
1 parent 5f742b9 commit 59235ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ pub fn menu_button<R>(
/// Returns `None` if the menu is not open.
pub fn menu_image_button<R>(
ui: &mut Ui,
texture_id: TextureId,
image_size: impl Into<Vec2>,
image_button: ImageButton,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<Option<R>> {
stationary_menu_image_impl(ui, texture_id, image_size, Box::new(add_contents))
stationary_menu_image_impl(ui, image_button, Box::new(add_contents))
}

/// Construct a nested sub menu in another menu.
Expand Down Expand Up @@ -202,14 +201,13 @@ fn stationary_menu_impl<'c, R>(
/// Responds to primary clicks.
fn stationary_menu_image_impl<'c, R>(
ui: &mut Ui,
texture_id: TextureId,
image_size: impl Into<Vec2>,
image_button: ImageButton,
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> InnerResponse<Option<R>> {
let bar_id = ui.id();

let mut bar_state = BarState::load(ui.ctx(), bar_id);
let button_response = ui.add(ImageButton::new(texture_id, image_size));
let button_response = ui.add(image_button);
let inner = bar_state.bar_menu(&button_response, add_contents);

bar_state.store(ui.ctx(), bar_id);
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ impl Ui {
if let Some(menu_state) = self.menu_state.clone() {
menu::submenu_button(self, menu_state, String::new(), add_contents)
} else {
menu::menu_image_button(self, texture_id, image_size, add_contents)
menu::menu_image_button(self, ImageButton::new(texture_id, image_size), add_contents)
}
}
}
Expand Down

0 comments on commit 59235ff

Please sign in to comment.