@@ -168,12 +168,13 @@ pub struct NavigationEntry {
impl Pane {
pub fn new(cx: &mut ViewContext<Self>) -> Self {
+ let handle = cx.weak_handle();
Self {
items: Vec::new(),
active_item_index: 0,
autoscroll: false,
nav_history: Default::default(),
- toolbar: cx.add_view(|_| Toolbar::new()),
+ toolbar: cx.add_view(|_| Toolbar::new(handle)),
}
}
@@ -1,7 +1,7 @@
-use crate::ItemHandle;
+use crate::{ItemHandle, Pane};
use gpui::{
- elements::*, AnyViewHandle, AppContext, ElementBox, Entity, MutableAppContext, RenderContext,
- View, ViewContext, ViewHandle,
+ elements::*, platform::CursorStyle, Action, AnyViewHandle, AppContext, ElementBox, Entity,
+ MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
@@ -42,6 +42,7 @@ pub enum ToolbarItemLocation {
pub struct Toolbar {
active_pane_item: Option<Box<dyn ItemHandle>>,
+ pane: WeakViewHandle<Pane>,
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
}
@@ -60,6 +61,7 @@ impl View for Toolbar {
let mut primary_left_items = Vec::new();
let mut primary_right_items = Vec::new();
let mut secondary_item = None;
+ let spacing = theme.item_spacing;
for (item, position) in &self.items {
match *position {
@@ -68,7 +70,7 @@ impl View for Toolbar {
let left_item = ChildView::new(item.as_ref())
.aligned()
.contained()
- .with_margin_right(theme.item_spacing);
+ .with_margin_right(spacing);
if let Some((flex, expanded)) = flex {
primary_left_items.push(left_item.flex(flex, expanded).boxed());
} else {
@@ -79,7 +81,7 @@ impl View for Toolbar {
let right_item = ChildView::new(item.as_ref())
.aligned()
.contained()
- .with_margin_left(theme.item_spacing)
+ .with_margin_left(spacing)
.flex_float();
if let Some((flex, expanded)) = flex {
primary_right_items.push(right_item.flex(flex, expanded).boxed());
@@ -98,26 +100,78 @@ impl View for Toolbar {
}
}
+ let pane = self.pane.clone();
+ let container_style = theme.container;
+ let height = theme.height;
+ let button_style = theme.nav_button;
+
Flex::column()
.with_child(
Flex::row()
+ .with_child(nav_button(
+ "icons/arrow-left.svg",
+ button_style,
+ spacing,
+ super::GoBack {
+ pane: Some(pane.clone()),
+ },
+ cx,
+ ))
+ .with_child(nav_button(
+ "icons/arrow-right.svg",
+ button_style,
+ spacing,
+ super::GoForward {
+ pane: Some(pane.clone()),
+ },
+ cx,
+ ))
.with_children(primary_left_items)
.with_children(primary_right_items)
.constrained()
- .with_height(theme.height)
+ .with_height(height)
.boxed(),
)
.with_children(secondary_item)
.contained()
- .with_style(theme.container)
+ .with_style(container_style)
.boxed()
}
}
+fn nav_button<A: Action + Clone>(
+ svg_path: &'static str,
+ style: theme::Interactive<theme::IconButton>,
+ spacing: f32,
+ action: A,
+ cx: &mut RenderContext<Toolbar>,
+) -> ElementBox {
+ MouseEventHandler::new::<A, _, _>(0, cx, |state, _| {
+ let style = style.style_for(state, false);
+ Svg::new(svg_path)
+ .with_color(style.color)
+ .constrained()
+ .with_width(style.icon_width)
+ .aligned()
+ .contained()
+ .with_style(style.container)
+ .constrained()
+ .with_width(style.button_width)
+ .with_height(style.button_width)
+ .boxed()
+ })
+ .with_cursor_style(CursorStyle::PointingHand)
+ .on_mouse_down(move |_, cx| cx.dispatch_action(action.clone()))
+ .contained()
+ .with_margin_right(spacing)
+ .boxed()
+}
+
impl Toolbar {
- pub fn new() -> Self {
+ pub fn new(pane: WeakViewHandle<Pane>) -> Self {
Self {
active_pane_item: None,
+ pane,
items: Default::default(),
}
}
@@ -139,6 +139,15 @@ export default function workspace(theme: Theme) {
background: backgroundColor(theme, 500),
border: border(theme, "secondary", { bottom: true }),
itemSpacing: 8,
+ navButton: {
+ color: iconColor(theme, "secondary"),
+ iconWidth: 8,
+ buttonWidth: 12,
+ margin: { left: 8, right: 8 },
+ hover: {
+ color: iconColor(theme, "active"),
+ },
+ },
padding: { left: 16, right: 8, top: 4, bottom: 4 },
},
breadcrumbs: {