ZIm/crates/ui/src/components/stories/context_menu.rs
Anthony Eid 7bc3f74cab
Fix panel button context menu overlap with tooltip hint (#30108)
This fix works by disabling the tooltip whenever the menu is being
rendered.

### Before

![image](https://github.com/user-attachments/assets/0b275931-fd1f-4748-88dd-cb76a52f8810)
### After

![image](https://github.com/user-attachments/assets/7260eb48-3a24-43ee-8df7-b6c48e8a4024)


Release Notes:

- Fix panel button tooltip overlapping with the panel button's right
click menu
2025-05-07 12:33:13 +00:00

81 lines
2.9 KiB
Rust

use gpui::{Corner, Entity, Render, actions};
use story::Story;
use crate::prelude::*;
use crate::{ContextMenu, Label, right_click_menu};
actions!(context_menu, [PrintCurrentDate, PrintBestFood]);
fn build_menu(
window: &mut Window,
cx: &mut App,
header: impl Into<SharedString>,
) -> Entity<ContextMenu> {
ContextMenu::build(window, cx, |menu, _, _| {
menu.header(header)
.separator()
.action("Print current time", Box::new(PrintCurrentDate))
.entry(
"Print best food",
Some(Box::new(PrintBestFood)),
|window, cx| window.dispatch_action(Box::new(PrintBestFood), cx),
)
})
}
pub struct ContextMenuStory;
impl Render for ContextMenuStory {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
Story::container()
.on_action(|_: &PrintCurrentDate, _, _| {
println!("printing unix time!");
if let Ok(unix_time) = std::time::UNIX_EPOCH.elapsed() {
println!("Current Unix time is {:?}", unix_time.as_secs());
}
})
.on_action(|_: &PrintBestFood, _, _| {
println!("burrito");
})
.flex()
.flex_row()
.justify_between()
.child(
div()
.flex()
.flex_col()
.justify_between()
.child(
right_click_menu("test2")
.trigger(|_| Label::new("TOP LEFT"))
.menu(move |window, cx| build_menu(window, cx, "top left")),
)
.child(
right_click_menu("test1")
.trigger(|_| Label::new("BOTTOM LEFT"))
.anchor(Corner::BottomLeft)
.attach(Corner::TopLeft)
.menu(move |window, cx| build_menu(window, cx, "bottom left")),
),
)
.child(
div()
.flex()
.flex_col()
.justify_between()
.child(
right_click_menu("test3")
.trigger(|_| Label::new("TOP RIGHT"))
.anchor(Corner::TopRight)
.menu(move |window, cx| build_menu(window, cx, "top right")),
)
.child(
right_click_menu("test4")
.trigger(|_| Label::new("BOTTOM RIGHT"))
.anchor(Corner::BottomRight)
.attach(Corner::TopRight)
.menu(move |window, cx| build_menu(window, cx, "bottom right")),
),
)
}
}