Show maximize/minimize icon for panes and terminal panel (#2521)

Closes
https://linear.app/zed-industries/issue/Z-1790/show-zoomunzoom-icons-for-panes-and-terminal-panel

![CleanShot 2023-05-24 at 11 07
04@2x](https://github.com/zed-industries/zed/assets/482957/b27d002c-6443-440b-88d0-cfa06d902477)
This commit is contained in:
Antonio Scandurra
2023-05-24 11:44:39 +02:00
committed by GitHub
2 changed files with 77 additions and 34 deletions
+35 -17
View File
@@ -62,24 +62,42 @@ impl TerminalPanel {
item.handle.act_as::<TerminalView>(cx).is_some()
})
});
pane.set_render_tab_bar_buttons(cx, move |_, cx| {
pane.set_render_tab_bar_buttons(cx, move |pane, cx| {
let this = weak_self.clone();
Pane::render_tab_bar_button(
0,
"icons/plus_12.svg",
cx,
move |_, cx| {
let this = this.clone();
cx.window_context().defer(move |cx| {
if let Some(this) = this.upgrade(cx) {
this.update(cx, |this, cx| {
this.add_terminal(&Default::default(), cx);
});
}
})
},
None,
)
Flex::row()
.with_child(Pane::render_tab_bar_button(
0,
"icons/plus_12.svg",
Some((
"New Terminal".into(),
Some(Box::new(workspace::NewTerminal)),
)),
cx,
move |_, cx| {
let this = this.clone();
cx.window_context().defer(move |cx| {
if let Some(this) = this.upgrade(cx) {
this.update(cx, |this, cx| {
this.add_terminal(&Default::default(), cx);
});
}
})
},
None,
))
.with_child(Pane::render_tab_bar_button(
1,
if pane.is_zoomed() {
"icons/minimize_8.svg"
} else {
"icons/maximize_8.svg"
},
Some(("Toggle Zoom".into(), Some(Box::new(workspace::ToggleZoom)))),
cx,
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
None,
))
.into_any()
});
pane
});
+42 -17
View File
@@ -285,19 +285,33 @@ impl Pane {
.with_child(Self::render_tab_bar_button(
0,
"icons/plus_12.svg",
Some(("New...".into(), None)),
cx,
|pane, cx| pane.deploy_new_menu(cx),
pane.tab_bar_context_menu
.handle_if_kind(TabBarContextMenuKind::New),
))
.with_child(Self::render_tab_bar_button(
2,
1,
"icons/split_12.svg",
Some(("Split Pane".into(), None)),
cx,
|pane, cx| pane.deploy_split_menu(cx),
pane.tab_bar_context_menu
.handle_if_kind(TabBarContextMenuKind::Split),
))
.with_child(Pane::render_tab_bar_button(
2,
if pane.is_zoomed() {
"icons/minimize_8.svg"
} else {
"icons/maximize_8.svg"
},
Some(("Toggle Zoom".into(), Some(Box::new(ToggleZoom)))),
cx,
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
None,
))
.into_any()
}),
}
@@ -684,6 +698,9 @@ impl Pane {
if self.zoomed {
cx.emit(Event::ZoomOut);
} else if !self.items.is_empty() {
if !self.has_focus {
cx.focus_self();
}
cx.emit(Event::ZoomIn);
}
}
@@ -1575,29 +1592,37 @@ impl Pane {
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
index: usize,
icon: &'static str,
tooltip: Option<(String, Option<Box<dyn Action>>)>,
cx: &mut ViewContext<Pane>,
on_click: F,
context_menu: Option<ViewHandle<ContextMenu>>,
) -> AnyElement<Pane> {
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()
.with_child(
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_child(button)
.with_children(
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()),
)