mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-04 10:12:47 +00:00
Provide tooltips for pane buttons
This commit is contained in:
parent
1a353ad25d
commit
e5fd953b4f
2 changed files with 32 additions and 16 deletions
|
@ -68,6 +68,10 @@ impl TerminalPanel {
|
||||||
.with_child(Pane::render_tab_bar_button(
|
.with_child(Pane::render_tab_bar_button(
|
||||||
0,
|
0,
|
||||||
"icons/plus_12.svg",
|
"icons/plus_12.svg",
|
||||||
|
Some((
|
||||||
|
"New Terminal".into(),
|
||||||
|
Some(Box::new(workspace::NewTerminal)),
|
||||||
|
)),
|
||||||
cx,
|
cx,
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
let this = this.clone();
|
let this = this.clone();
|
||||||
|
@ -88,6 +92,7 @@ impl TerminalPanel {
|
||||||
} else {
|
} else {
|
||||||
"icons/maximize_8.svg"
|
"icons/maximize_8.svg"
|
||||||
},
|
},
|
||||||
|
Some(("Toggle Zoom".into(), Some(Box::new(workspace::ToggleZoom)))),
|
||||||
cx,
|
cx,
|
||||||
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -285,6 +285,7 @@ impl Pane {
|
||||||
.with_child(Self::render_tab_bar_button(
|
.with_child(Self::render_tab_bar_button(
|
||||||
0,
|
0,
|
||||||
"icons/plus_12.svg",
|
"icons/plus_12.svg",
|
||||||
|
Some(("New...".into(), None)),
|
||||||
cx,
|
cx,
|
||||||
|pane, cx| pane.deploy_new_menu(cx),
|
|pane, cx| pane.deploy_new_menu(cx),
|
||||||
pane.tab_bar_context_menu
|
pane.tab_bar_context_menu
|
||||||
|
@ -293,6 +294,7 @@ impl Pane {
|
||||||
.with_child(Self::render_tab_bar_button(
|
.with_child(Self::render_tab_bar_button(
|
||||||
1,
|
1,
|
||||||
"icons/split_12.svg",
|
"icons/split_12.svg",
|
||||||
|
Some(("Split Pane".into(), None)),
|
||||||
cx,
|
cx,
|
||||||
|pane, cx| pane.deploy_split_menu(cx),
|
|pane, cx| pane.deploy_split_menu(cx),
|
||||||
pane.tab_bar_context_menu
|
pane.tab_bar_context_menu
|
||||||
|
@ -305,6 +307,7 @@ impl Pane {
|
||||||
} else {
|
} else {
|
||||||
"icons/maximize_8.svg"
|
"icons/maximize_8.svg"
|
||||||
},
|
},
|
||||||
|
Some(("Toggle Zoom".into(), Some(Box::new(ToggleZoom)))),
|
||||||
cx,
|
cx,
|
||||||
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
||||||
None,
|
None,
|
||||||
|
@ -1589,29 +1592,37 @@ impl Pane {
|
||||||
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
|
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
|
||||||
index: usize,
|
index: usize,
|
||||||
icon: &'static str,
|
icon: &'static str,
|
||||||
|
tooltip: Option<(String, Option<Box<dyn Action>>)>,
|
||||||
cx: &mut ViewContext<Pane>,
|
cx: &mut ViewContext<Pane>,
|
||||||
on_click: F,
|
on_click: F,
|
||||||
context_menu: Option<ViewHandle<ContextMenu>>,
|
context_menu: Option<ViewHandle<ContextMenu>>,
|
||||||
) -> AnyElement<Pane> {
|
) -> AnyElement<Pane> {
|
||||||
enum TabBarButton {}
|
enum TabBarButton {}
|
||||||
|
|
||||||
|
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
|
||||||
|
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
|
||||||
|
let style = theme.pane_button.style_for(mouse_state, false);
|
||||||
|
Svg::new(icon)
|
||||||
|
.with_color(style.color)
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.icon_width)
|
||||||
|
.aligned()
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.button_width)
|
||||||
|
.with_height(style.button_width)
|
||||||
|
})
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, move |_, pane, cx| on_click(pane, cx))
|
||||||
|
.into_any();
|
||||||
|
if let Some((tooltip, action)) = tooltip {
|
||||||
|
let tooltip_style = settings::get::<ThemeSettings>(cx).theme.tooltip.clone();
|
||||||
|
button = button
|
||||||
|
.with_tooltip::<TabBarButton>(index, tooltip, action, tooltip_style, cx)
|
||||||
|
.into_any();
|
||||||
|
}
|
||||||
|
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(button)
|
||||||
MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
|
|
||||||
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
|
|
||||||
let style = theme.pane_button.style_for(mouse_state, false);
|
|
||||||
Svg::new(icon)
|
|
||||||
.with_color(style.color)
|
|
||||||
.constrained()
|
|
||||||
.with_width(style.icon_width)
|
|
||||||
.aligned()
|
|
||||||
.constrained()
|
|
||||||
.with_width(style.button_width)
|
|
||||||
.with_height(style.button_width)
|
|
||||||
})
|
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
.on_click(MouseButton::Left, move |_, pane, cx| on_click(pane, cx)),
|
|
||||||
)
|
|
||||||
.with_children(
|
.with_children(
|
||||||
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()),
|
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue