From 1a353ad25d6e3600bf23bac304cfa23dbb96d1f6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 24 May 2023 11:00:12 +0200 Subject: [PATCH 1/2] Show maximize/minimize icon for panes and terminal panel --- crates/terminal_view/src/terminal_panel.rs | 47 ++++++++++++++-------- crates/workspace/src/pane.rs | 16 +++++++- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index f265c535524352ac7de3284f8accdebef7bb7190..90334f94490ab183e069d5328add7077a78236ca 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -62,24 +62,37 @@ impl TerminalPanel { item.handle.act_as::(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", + 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" + }, + cx, + move |pane, cx| pane.toggle_zoom(&Default::default(), cx), + None, + )) + .into_any() }); pane }); diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index a2b13eb0ccce3b41bf08abfa3d5c45a7a9f6dbcf..4302c6b3903777b3187d5155b34be023fc41ad9c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -291,13 +291,24 @@ impl Pane { .handle_if_kind(TabBarContextMenuKind::New), )) .with_child(Self::render_tab_bar_button( - 2, + 1, "icons/split_12.svg", 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" + }, + cx, + move |pane, cx| pane.toggle_zoom(&Default::default(), cx), + None, + )) .into_any() }), } @@ -684,6 +695,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); } } From e5fd953b4f78f604d3bb39d88d32d43644fc3dfc Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 24 May 2023 11:18:30 +0200 Subject: [PATCH 2/2] Provide tooltips for pane buttons --- crates/terminal_view/src/terminal_panel.rs | 5 +++ crates/workspace/src/pane.rs | 43 ++++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 90334f94490ab183e069d5328add7077a78236ca..766736d70e4c6bdd5a713afd0aee29c3967a4250 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -68,6 +68,10 @@ impl TerminalPanel { .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(); @@ -88,6 +92,7 @@ impl TerminalPanel { } 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, diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 4302c6b3903777b3187d5155b34be023fc41ad9c..26f3d17453c66566d5dfe64b5f711dc945796c39 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -285,6 +285,7 @@ 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 @@ -293,6 +294,7 @@ impl Pane { .with_child(Self::render_tab_bar_button( 1, "icons/split_12.svg", + Some(("Split Pane".into(), None)), cx, |pane, cx| pane.deploy_split_menu(cx), pane.tab_bar_context_menu @@ -305,6 +307,7 @@ impl Pane { } else { "icons/maximize_8.svg" }, + Some(("Toggle Zoom".into(), Some(Box::new(ToggleZoom)))), cx, move |pane, cx| pane.toggle_zoom(&Default::default(), cx), None, @@ -1589,29 +1592,37 @@ impl Pane { pub fn render_tab_bar_button)>( index: usize, icon: &'static str, + tooltip: Option<(String, Option>)>, cx: &mut ViewContext, on_click: F, context_menu: Option>, ) -> AnyElement { enum TabBarButton {} + let mut button = MouseEventHandler::::new(index, cx, |mouse_state, cx| { + let theme = &settings::get::(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::(cx).theme.tooltip.clone(); + button = button + .with_tooltip::(index, tooltip, action, tooltip_style, cx) + .into_any(); + } + Stack::new() - .with_child( - MouseEventHandler::::new(index, cx, |mouse_state, cx| { - let theme = &settings::get::(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()), )