In progress, working on building out the dock UI experience

This commit is contained in:
Mikayla Maki 2022-09-07 10:53:50 -07:00 committed by K Simmons
parent b9a6336995
commit d87fb20170
2 changed files with 65 additions and 10 deletions

View file

@ -1,18 +1,20 @@
use gpui::{elements::ChildView, Element, ElementBox, ViewContext, ViewHandle}; use std::sync::Arc;
use gpui::{elements::ChildView, Element, ElementBox, Entity, View, ViewContext, ViewHandle};
use theme::Theme; use theme::Theme;
use crate::{Pane, Workspace}; use crate::{Pane, StatusItemView, Workspace};
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq, Default, Copy, Clone)]
pub enum DockPosition { pub enum DockPosition {
#[default]
Bottom, Bottom,
Right, Right,
Fullscreen, Fullscreen,
Hidden,
} }
pub struct Dock { pub struct Dock {
position: DockPosition, position: Option<DockPosition>,
pane: ViewHandle<Pane>, pane: ViewHandle<Pane>,
} }
@ -21,15 +23,66 @@ impl Dock {
let pane = cx.add_view(Pane::new); let pane = cx.add_view(Pane::new);
Self { Self {
pane, pane,
position: DockPosition::Bottom, position: None,
} }
} }
pub fn render(&self, _theme: &Theme, position: DockPosition) -> Option<ElementBox> { pub fn render(&self, _theme: &Theme, position: DockPosition) -> Option<ElementBox> {
if position == self.position { if self.position.is_some() && self.position.unwrap() == position {
Some(ChildView::new(self.pane.clone()).boxed()) Some(ChildView::new(self.pane.clone()).boxed())
} else { } else {
None None
} }
} }
} }
pub struct ToggleDock {
dock: Arc<Dock>,
}
impl ToggleDock {
pub fn new(dock: Arc<Dock>, _cx: &mut ViewContext<Self>) -> Self {
Self { dock }
}
}
impl Entity for ToggleDock {
type Event = ();
}
impl View for ToggleDock {
fn ui_name() -> &'static str {
"Dock Toggle"
}
// Shift-escape ON
// Get or insert the dock's last focused terminal
// Open the dock in fullscreen
// Focus that terminal
// Shift-escape OFF
// Close the dock
// Return focus to center
// Behaviors:
// If the dock is shown, hide it
// If the dock is hidden, show it
// If the dock was full screen, open it in last position (bottom or right)
// If the dock was bottom or right, re-open it in that context (and with the previous % width)
// On hover, change color and background
// On shown, change color and background
// On hidden, change color and background
// Show tool tip
fn render(&mut self, _cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
todo!()
}
}
impl StatusItemView for ToggleDock {
fn set_active_pane_item(
&mut self,
_active_pane_item: Option<&dyn crate::ItemHandle>,
_cx: &mut ViewContext<Self>,
) {
//Not applicable
}
}

View file

@ -18,7 +18,7 @@ use client::{
}; };
use clock::ReplicaId; use clock::ReplicaId;
use collections::{hash_map, HashMap, HashSet}; use collections::{hash_map, HashMap, HashSet};
use dock::{Dock, DockPosition}; use dock::{Dock, DockPosition, ToggleDock};
use drag_and_drop::DragAndDrop; use drag_and_drop::DragAndDrop;
use futures::{channel::oneshot, FutureExt}; use futures::{channel::oneshot, FutureExt};
use gpui::{ use gpui::{
@ -980,15 +980,19 @@ impl Workspace {
cx.emit_global(WorkspaceCreated(weak_self.clone())); cx.emit_global(WorkspaceCreated(weak_self.clone()));
let dock = Dock::new(cx);
let left_sidebar = cx.add_view(|_| Sidebar::new(Side::Left)); let left_sidebar = cx.add_view(|_| Sidebar::new(Side::Left));
let right_sidebar = cx.add_view(|_| Sidebar::new(Side::Right)); let right_sidebar = cx.add_view(|_| Sidebar::new(Side::Right));
let left_sidebar_buttons = cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), cx)); let left_sidebar_buttons = cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), cx));
let toggle_dock = cx.add_view(|cx| ToggleDock::new(Arc::new(dock), cx));
let right_sidebar_buttons = let right_sidebar_buttons =
cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), cx)); cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), cx));
let status_bar = cx.add_view(|cx| { let status_bar = cx.add_view(|cx| {
let mut status_bar = StatusBar::new(&pane.clone(), cx); let mut status_bar = StatusBar::new(&pane.clone(), cx);
status_bar.add_left_item(left_sidebar_buttons, cx); status_bar.add_left_item(left_sidebar_buttons, cx);
status_bar.add_right_item(right_sidebar_buttons, cx); status_bar.add_right_item(right_sidebar_buttons, cx);
status_bar.add_right_item(toggle_dock, cx);
status_bar status_bar
}); });
@ -996,8 +1000,6 @@ impl Workspace {
drag_and_drop.register_container(weak_self.clone()); drag_and_drop.register_container(weak_self.clone());
}); });
let dock = Dock::new(cx);
let mut this = Workspace { let mut this = Workspace {
modal: None, modal: None,
weak_self, weak_self,