This commit is contained in:
Antonio Scandurra 2023-10-31 14:04:59 +01:00
parent 14a6199b4b
commit bbe2dd1f8f
3 changed files with 293 additions and 332 deletions

View file

@ -1,14 +1,13 @@
use crate::{StatusItemView, Workspace, WorkspaceBounds}; use crate::{Axis, Workspace};
use gpui2::{ use gpui2::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyViewHandle, AppContext, Action, AnyElement, AnyView, AppContext, Render, Subscription, View, ViewContext, WeakView,
Axis, Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, WindowContext,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::rc::Rc; use std::sync::Arc;
use theme2::ThemeSettings;
pub trait Panel: View { pub trait Panel: Render {
fn position(&self, cx: &WindowContext) -> DockPosition; fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition) -> bool; fn position_is_valid(&self, position: DockPosition) -> bool;
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>); fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
@ -55,10 +54,10 @@ pub trait PanelHandle {
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>); fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);
fn icon_label(&self, cx: &WindowContext) -> Option<String>; fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool; fn has_focus(&self, cx: &WindowContext) -> bool;
fn as_any(&self) -> &AnyViewHandle; fn to_any(&self) -> AnyView;
} }
impl<T> PanelHandle for ViewHandle<T> impl<T> PanelHandle for View<T>
where where
T: Panel, T: Panel,
{ {
@ -114,14 +113,14 @@ where
self.read(cx).has_focus(cx) self.read(cx).has_focus(cx)
} }
fn as_any(&self) -> &AnyViewHandle { fn to_any(&self) -> AnyView {
self self.clone().into_any()
} }
} }
impl From<&dyn PanelHandle> for AnyViewHandle { impl From<&dyn PanelHandle> for AnyView {
fn from(val: &dyn PanelHandle) -> Self { fn from(val: &dyn PanelHandle) -> Self {
val.as_any().clone() val.to_any()
} }
} }
@ -149,13 +148,14 @@ impl DockPosition {
} }
} }
fn to_resize_handle_side(self) -> HandleSide { // todo!()
match self { // fn to_resize_handle_side(self) -> HandleSide {
Self::Left => HandleSide::Right, // match self {
Self::Bottom => HandleSide::Top, // Self::Left => HandleSide::Right,
Self::Right => HandleSide::Left, // Self::Bottom => HandleSide::Top,
} // Self::Right => HandleSide::Left,
} // }
// }
pub fn axis(&self) -> Axis { pub fn axis(&self) -> Axis {
match self { match self {
@ -166,14 +166,15 @@ impl DockPosition {
} }
struct PanelEntry { struct PanelEntry {
panel: Rc<dyn PanelHandle>, panel: Arc<dyn PanelHandle>,
context_menu: ViewHandle<ContextMenu>, // todo!()
// context_menu: View<ContextMenu>,
_subscriptions: [Subscription; 2], _subscriptions: [Subscription; 2],
} }
pub struct PanelButtons { pub struct PanelButtons {
dock: ViewHandle<Dock>, dock: View<Dock>,
workspace: WeakViewHandle<Workspace>, workspace: WeakView<Workspace>,
} }
impl Dock { impl Dock {
@ -199,7 +200,7 @@ impl Dock {
.map_or(false, |panel| panel.has_focus(cx)) .map_or(false, |panel| panel.has_focus(cx))
} }
pub fn panel<T: Panel>(&self) -> Option<ViewHandle<T>> { pub fn panel<T: Panel>(&self) -> Option<View<T>> {
self.panel_entries self.panel_entries
.iter() .iter()
.find_map(|entry| entry.panel.as_any().clone().downcast()) .find_map(|entry| entry.panel.as_any().clone().downcast())
@ -212,10 +213,11 @@ impl Dock {
} }
pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> { pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {
self.panel_entries.iter().position(|entry| { todo!()
let panel = entry.panel.as_any(); // self.panel_entries.iter().position(|entry| {
cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name) // let panel = entry.panel.as_any();
}) // cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name)
// })
} }
pub fn active_panel_index(&self) -> usize { pub fn active_panel_index(&self) -> usize {
@ -233,12 +235,7 @@ impl Dock {
} }
} }
pub fn set_panel_zoomed( pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
&mut self,
panel: &AnyViewHandle,
zoomed: bool,
cx: &mut ViewContext<Self>,
) {
for entry in &mut self.panel_entries { for entry in &mut self.panel_entries {
if entry.panel.as_any() == panel { if entry.panel.as_any() == panel {
if zoomed != entry.panel.is_zoomed(cx) { if zoomed != entry.panel.is_zoomed(cx) {
@ -260,7 +257,7 @@ impl Dock {
} }
} }
pub(crate) fn add_panel<T: Panel>(&mut self, panel: ViewHandle<T>, cx: &mut ViewContext<Self>) { pub(crate) fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {
let subscriptions = [ let subscriptions = [
cx.observe(&panel, |_, _, cx| cx.notify()), cx.observe(&panel, |_, _, cx| cx.notify()),
cx.subscribe(&panel, |this, panel, event, cx| { cx.subscribe(&panel, |this, panel, event, cx| {
@ -284,18 +281,19 @@ impl Dock {
let dock_view_id = cx.view_id(); let dock_view_id = cx.view_id();
self.panel_entries.push(PanelEntry { self.panel_entries.push(PanelEntry {
panel: Rc::new(panel), panel: Arc::new(panel),
context_menu: cx.add_view(|cx| { // todo!()
let mut menu = ContextMenu::new(dock_view_id, cx); // context_menu: cx.add_view(|cx| {
menu.set_position_mode(OverlayPositionMode::Local); // let mut menu = ContextMenu::new(dock_view_id, cx);
menu // menu.set_position_mode(OverlayPositionMode::Local);
}), // menu
// }),
_subscriptions: subscriptions, _subscriptions: subscriptions,
}); });
cx.notify() cx.notify()
} }
pub fn remove_panel<T: Panel>(&mut self, panel: &ViewHandle<T>, cx: &mut ViewContext<Self>) { pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
if let Some(panel_ix) = self if let Some(panel_ix) = self
.panel_entries .panel_entries
.iter() .iter()
@ -331,12 +329,12 @@ impl Dock {
} }
} }
pub fn visible_panel(&self) -> Option<&Rc<dyn PanelHandle>> { pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
let entry = self.visible_entry()?; let entry = self.visible_entry()?;
Some(&entry.panel) Some(&entry.panel)
} }
pub fn active_panel(&self) -> Option<&Rc<dyn PanelHandle>> { pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
Some(&self.panel_entries.get(self.active_panel_index)?.panel) Some(&self.panel_entries.get(self.active_panel_index)?.panel)
} }
@ -348,7 +346,7 @@ impl Dock {
} }
} }
pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Rc<dyn PanelHandle>> { pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {
let entry = self.visible_entry()?; let entry = self.visible_entry()?;
if entry.panel.is_zoomed(cx) { if entry.panel.is_zoomed(cx) {
Some(entry.panel.clone()) Some(entry.panel.clone())
@ -382,227 +380,218 @@ impl Dock {
} }
pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> { pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {
if let Some(active_entry) = self.visible_entry() { todo!()
Empty::new() // if let Some(active_entry) = self.visible_entry() {
.into_any() // Empty::new()
.contained() // .into_any()
.with_style(self.style(cx)) // .contained()
.resizable::<WorkspaceBounds>( // .with_style(self.style(cx))
self.position.to_resize_handle_side(), // .resizable::<WorkspaceBounds>(
active_entry.panel.size(cx), // self.position.to_resize_handle_side(),
|_, _, _| {}, // active_entry.panel.size(cx),
) // |_, _, _| {},
.into_any() // )
} else { // .into_any()
Empty::new().into_any() // } else {
} // Empty::new().into_any()
} // }
fn style(&self, cx: &WindowContext) -> ContainerStyle {
let theme = &settings::get::<ThemeSettings>(cx).theme;
let style = match self.position {
DockPosition::Left => theme.workspace.dock.left,
DockPosition::Bottom => theme.workspace.dock.bottom,
DockPosition::Right => theme.workspace.dock.right,
};
style
} }
} }
impl Entity for Dock { // todo!()
type Event = (); // impl View for Dock {
} // fn ui_name() -> &'static str {
// "Dock"
// }
impl View for Dock { // fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
fn ui_name() -> &'static str { // if let Some(active_entry) = self.visible_entry() {
"Dock" // let style = self.style(cx);
} // ChildView::new(active_entry.panel.as_any(), cx)
// .contained()
// .with_style(style)
// .resizable::<WorkspaceBounds>(
// self.position.to_resize_handle_side(),
// active_entry.panel.size(cx),
// |dock: &mut Self, size, cx| dock.resize_active_panel(size, cx),
// )
// .into_any()
// } else {
// Empty::new().into_any()
// }
// }
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { // fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
if let Some(active_entry) = self.visible_entry() { // if cx.is_self_focused() {
let style = self.style(cx); // if let Some(active_entry) = self.visible_entry() {
ChildView::new(active_entry.panel.as_any(), cx) // cx.focus(active_entry.panel.as_any());
.contained() // } else {
.with_style(style) // cx.focus_parent();
.resizable::<WorkspaceBounds>( // }
self.position.to_resize_handle_side(), // }
active_entry.panel.size(cx), // }
|dock: &mut Self, size, cx| dock.resize_active_panel(size, cx), // }
)
.into_any()
} else {
Empty::new().into_any()
}
}
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { // todo!()
if cx.is_self_focused() { // impl PanelButtons {
if let Some(active_entry) = self.visible_entry() { // pub fn new(
cx.focus(active_entry.panel.as_any()); // dock: View<Dock>,
} else { // workspace: WeakViewHandle<Workspace>,
cx.focus_parent(); // cx: &mut ViewContext<Self>,
} // ) -> Self {
} // cx.observe(&dock, |_, _, cx| cx.notify()).detach();
} // Self { dock, workspace }
} // }
// }
impl PanelButtons { // todo!()
pub fn new( // impl Entity for PanelButtons {
dock: ViewHandle<Dock>, // type Event = ();
workspace: WeakViewHandle<Workspace>, // }
cx: &mut ViewContext<Self>,
) -> Self {
cx.observe(&dock, |_, _, cx| cx.notify()).detach();
Self { dock, workspace }
}
}
impl Entity for PanelButtons { // todo!()
type Event = (); // impl View for PanelButtons {
} // fn ui_name() -> &'static str {
// "PanelButtons"
// }
impl View for PanelButtons { // fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
fn ui_name() -> &'static str { // let theme = &settings::get::<ThemeSettings>(cx).theme;
"PanelButtons" // let tooltip_style = theme.tooltip.clone();
} // let theme = &theme.workspace.status_bar.panel_buttons;
// let button_style = theme.button.clone();
// let dock = self.dock.read(cx);
// let active_ix = dock.active_panel_index;
// let is_open = dock.is_open;
// let dock_position = dock.position;
// let group_style = match dock_position {
// DockPosition::Left => theme.group_left,
// DockPosition::Bottom => theme.group_bottom,
// DockPosition::Right => theme.group_right,
// };
// let menu_corner = match dock_position {
// DockPosition::Left => AnchorCorner::BottomLeft,
// DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,
// };
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { // let panels = dock
let theme = &settings::get::<ThemeSettings>(cx).theme; // .panel_entries
let tooltip_style = theme.tooltip.clone(); // .iter()
let theme = &theme.workspace.status_bar.panel_buttons; // .map(|item| (item.panel.clone(), item.context_menu.clone()))
let button_style = theme.button.clone(); // .collect::<Vec<_>>();
let dock = self.dock.read(cx); // Flex::row()
let active_ix = dock.active_panel_index; // .with_children(panels.into_iter().enumerate().filter_map(
let is_open = dock.is_open; // |(panel_ix, (view, context_menu))| {
let dock_position = dock.position; // let icon_path = view.icon_path(cx)?;
let group_style = match dock_position { // let is_active = is_open && panel_ix == active_ix;
DockPosition::Left => theme.group_left, // let (tooltip, tooltip_action) = if is_active {
DockPosition::Bottom => theme.group_bottom, // (
DockPosition::Right => theme.group_right, // format!("Close {} dock", dock_position.to_label()),
}; // Some(match dock_position {
let menu_corner = match dock_position { // DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
DockPosition::Left => AnchorCorner::BottomLeft, // DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),
DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight, // DockPosition::Right => crate::ToggleRightDock.boxed_clone(),
}; // }),
// )
// } else {
// view.icon_tooltip(cx)
// };
// Some(
// Stack::new()
// .with_child(
// MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| {
// let style = button_style.in_state(is_active);
let panels = dock // let style = style.style_for(state);
.panel_entries // Flex::row()
.iter() // .with_child(
.map(|item| (item.panel.clone(), item.context_menu.clone())) // Svg::new(icon_path)
.collect::<Vec<_>>(); // .with_color(style.icon_color)
Flex::row() // .constrained()
.with_children(panels.into_iter().enumerate().filter_map( // .with_width(style.icon_size)
|(panel_ix, (view, context_menu))| { // .aligned(),
let icon_path = view.icon_path(cx)?; // )
let is_active = is_open && panel_ix == active_ix; // .with_children(if let Some(label) = view.icon_label(cx) {
let (tooltip, tooltip_action) = if is_active { // Some(
( // Label::new(label, style.label.text.clone())
format!("Close {} dock", dock_position.to_label()), // .contained()
Some(match dock_position { // .with_style(style.label.container)
DockPosition::Left => crate::ToggleLeftDock.boxed_clone(), // .aligned(),
DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(), // )
DockPosition::Right => crate::ToggleRightDock.boxed_clone(), // } else {
}), // None
) // })
} else { // .constrained()
view.icon_tooltip(cx) // .with_height(style.icon_size)
}; // .contained()
Some( // .with_style(style.container)
Stack::new() // })
.with_child( // .with_cursor_style(CursorStyle::PointingHand)
MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| { // .on_click(MouseButton::Left, {
let style = button_style.in_state(is_active); // let tooltip_action =
// tooltip_action.as_ref().map(|action| action.boxed_clone());
// move |_, this, cx| {
// if let Some(tooltip_action) = &tooltip_action {
// let window = cx.window();
// let view_id = this.workspace.id();
// let tooltip_action = tooltip_action.boxed_clone();
// cx.spawn(|_, mut cx| async move {
// window.dispatch_action(
// view_id,
// &*tooltip_action,
// &mut cx,
// );
// })
// .detach();
// }
// }
// })
// .on_click(MouseButton::Right, {
// let view = view.clone();
// let menu = context_menu.clone();
// move |_, _, cx| {
// const POSITIONS: [DockPosition; 3] = [
// DockPosition::Left,
// DockPosition::Right,
// DockPosition::Bottom,
// ];
let style = style.style_for(state); // menu.update(cx, |menu, cx| {
Flex::row() // let items = POSITIONS
.with_child( // .into_iter()
Svg::new(icon_path) // .filter(|position| {
.with_color(style.icon_color) // *position != dock_position
.constrained() // && view.position_is_valid(*position, cx)
.with_width(style.icon_size) // })
.aligned(), // .map(|position| {
) // let view = view.clone();
.with_children(if let Some(label) = view.icon_label(cx) { // ContextMenuItem::handler(
Some( // format!("Dock {}", position.to_label()),
Label::new(label, style.label.text.clone()) // move |cx| view.set_position(position, cx),
.contained() // )
.with_style(style.label.container) // })
.aligned(), // .collect();
) // menu.show(Default::default(), menu_corner, items, cx);
} else { // })
None // }
}) // })
.constrained() // .with_tooltip::<Self>(
.with_height(style.icon_size) // panel_ix,
.contained() // tooltip,
.with_style(style.container) // tooltip_action,
}) // tooltip_style.clone(),
.with_cursor_style(CursorStyle::PointingHand) // cx,
.on_click(MouseButton::Left, { // ),
let tooltip_action = // )
tooltip_action.as_ref().map(|action| action.boxed_clone()); // .with_child(ChildView::new(&context_menu, cx)),
move |_, this, cx| { // )
if let Some(tooltip_action) = &tooltip_action { // },
let window = cx.window(); // ))
let view_id = this.workspace.id(); // .contained()
let tooltip_action = tooltip_action.boxed_clone(); // .with_style(group_style)
cx.spawn(|_, mut cx| async move { // .into_any()
window.dispatch_action( // }
view_id, // }
&*tooltip_action,
&mut cx,
);
})
.detach();
}
}
})
.on_click(MouseButton::Right, {
let view = view.clone();
let menu = context_menu.clone();
move |_, _, cx| {
const POSITIONS: [DockPosition; 3] = [
DockPosition::Left,
DockPosition::Right,
DockPosition::Bottom,
];
menu.update(cx, |menu, cx| {
let items = POSITIONS
.into_iter()
.filter(|position| {
*position != dock_position
&& view.position_is_valid(*position, cx)
})
.map(|position| {
let view = view.clone();
ContextMenuItem::handler(
format!("Dock {}", position.to_label()),
move |cx| view.set_position(position, cx),
)
})
.collect();
menu.show(Default::default(), menu_corner, items, cx);
})
}
})
.with_tooltip::<Self>(
panel_ix,
tooltip,
tooltip_action,
tooltip_style.clone(),
cx,
),
)
.with_child(ChildView::new(&context_menu, cx)),
)
},
))
.contained()
.with_style(group_style)
.into_any()
}
}
impl StatusItemView for PanelButtons { impl StatusItemView for PanelButtons {
fn set_active_pane_item( fn set_active_pane_item(
@ -616,7 +605,7 @@ impl StatusItemView for PanelButtons {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub mod test { pub mod test {
use super::*; use super::*;
use gpui2::{ViewContext, WindowContext}; use gpui2::{div, Div, ViewContext, WindowContext};
#[derive(Debug)] #[derive(Debug)]
pub enum TestPanelEvent { pub enum TestPanelEvent {
@ -648,31 +637,16 @@ pub mod test {
} }
} }
impl Entity for TestPanel { impl Render for TestPanel {
type Event = TestPanelEvent; type Element = Div<Self>;
}
impl View for TestPanel { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn ui_name() -> &'static str { div()
"TestPanel"
}
fn render(&mut self, _: &mut ViewContext<'_, '_, Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.has_focus = true;
cx.emit(TestPanelEvent::Focus);
}
fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {
self.has_focus = false;
} }
} }
impl Panel for TestPanel { impl Panel for TestPanel {
fn position(&self, _: &gpui::WindowContext) -> super::DockPosition { fn position(&self, _: &gpui2::WindowContext) -> super::DockPosition {
self.position self.position
} }

View file

@ -1,18 +1,8 @@
use crate::{ItemHandle, Pane};
use gpui2::{AnyView, Render, Subscription, View, ViewContext, WindowContext};
use std::ops::Range; use std::ops::Range;
use crate::{ItemHandle, Pane}; pub trait StatusItemView: Render {
use gpui::{
elements::*,
geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
AnyElement, AnyViewHandle, Entity, SizeConstraint, Subscription, View, ViewContext, ViewHandle,
WindowContext,
};
pub trait StatusItemView: View {
fn set_active_pane_item( fn set_active_pane_item(
&mut self, &mut self,
active_pane_item: Option<&dyn crate::ItemHandle>, active_pane_item: Option<&dyn crate::ItemHandle>,
@ -21,7 +11,7 @@ pub trait StatusItemView: View {
} }
trait StatusItemViewHandle { trait StatusItemViewHandle {
fn as_any(&self) -> &AnyViewHandle; fn to_any(&self) -> AnyView;
fn set_active_pane_item( fn set_active_pane_item(
&self, &self,
active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
@ -33,50 +23,47 @@ trait StatusItemViewHandle {
pub struct StatusBar { pub struct StatusBar {
left_items: Vec<Box<dyn StatusItemViewHandle>>, left_items: Vec<Box<dyn StatusItemViewHandle>>,
right_items: Vec<Box<dyn StatusItemViewHandle>>, right_items: Vec<Box<dyn StatusItemViewHandle>>,
active_pane: ViewHandle<Pane>, active_pane: View<Pane>,
_observe_active_pane: Subscription, _observe_active_pane: Subscription,
} }
impl Entity for StatusBar { // todo!()
type Event = (); // impl View for StatusBar {
} // fn ui_name() -> &'static str {
// "StatusBar"
// }
impl View for StatusBar { // fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
fn ui_name() -> &'static str { // let theme = &theme::current(cx).workspace.status_bar;
"StatusBar"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { // StatusBarElement {
let theme = &theme::current(cx).workspace.status_bar; // left: Flex::row()
// .with_children(self.left_items.iter().map(|i| {
StatusBarElement { // ChildView::new(i.as_any(), cx)
left: Flex::row() // .aligned()
.with_children(self.left_items.iter().map(|i| { // .contained()
ChildView::new(i.as_any(), cx) // .with_margin_right(theme.item_spacing)
.aligned() // }))
.contained() // .into_any(),
.with_margin_right(theme.item_spacing) // right: Flex::row()
})) // .with_children(self.right_items.iter().rev().map(|i| {
.into_any(), // ChildView::new(i.as_any(), cx)
right: Flex::row() // .aligned()
.with_children(self.right_items.iter().rev().map(|i| { // .contained()
ChildView::new(i.as_any(), cx) // .with_margin_left(theme.item_spacing)
.aligned() // }))
.contained() // .into_any(),
.with_margin_left(theme.item_spacing) // }
})) // .contained()
.into_any(), // .with_style(theme.container)
} // .constrained()
.contained() // .with_height(theme.height)
.with_style(theme.container) // .into_any()
.constrained() // }
.with_height(theme.height) // }
.into_any()
}
}
impl StatusBar { impl StatusBar {
pub fn new(active_pane: &ViewHandle<Pane>, cx: &mut ViewContext<Self>) -> Self { pub fn new(active_pane: &View<Pane>, cx: &mut ViewContext<Self>) -> Self {
let mut this = Self { let mut this = Self {
left_items: Default::default(), left_items: Default::default(),
right_items: Default::default(), right_items: Default::default(),
@ -88,7 +75,7 @@ impl StatusBar {
this this
} }
pub fn add_left_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>) pub fn add_left_item<T>(&mut self, item: View<T>, cx: &mut ViewContext<Self>)
where where
T: 'static + StatusItemView, T: 'static + StatusItemView,
{ {
@ -96,7 +83,7 @@ impl StatusBar {
cx.notify(); cx.notify();
} }
pub fn item_of_type<T: StatusItemView>(&self) -> Option<ViewHandle<T>> { pub fn item_of_type<T: StatusItemView>(&self) -> Option<View<T>> {
self.left_items self.left_items
.iter() .iter()
.chain(self.right_items.iter()) .chain(self.right_items.iter())
@ -146,7 +133,7 @@ impl StatusBar {
cx.notify(); cx.notify();
} }
pub fn add_right_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>) pub fn add_right_item<T>(&mut self, item: View<T>, cx: &mut ViewContext<Self>)
where where
T: 'static + StatusItemView, T: 'static + StatusItemView,
{ {

View file

@ -1,4 +1,4 @@
// pub mod dock; pub mod dock;
pub mod item; pub mod item;
// pub mod notifications; // pub mod notifications;
pub mod pane; pub mod pane;
@ -6,7 +6,7 @@ pub mod pane_group;
mod persistence; mod persistence;
pub mod searchable; pub mod searchable;
// pub mod shared_screen; // pub mod shared_screen;
// mod status_bar; mod status_bar;
mod toolbar; mod toolbar;
mod workspace_settings; mod workspace_settings;
@ -37,7 +37,7 @@ pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
use util::ResultExt; use util::ResultExt;
use crate::persistence::model::{ use crate::persistence::model::{
DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup, DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup, SerializedWorkspace,
}; };
// lazy_static! { // lazy_static! {