Allow styling sidebar's resize handle

This commit is contained in:
Antonio Scandurra 2021-08-27 14:57:47 +02:00
parent 7f5cd017cb
commit 30ce7f6122
4 changed files with 24 additions and 11 deletions

View file

@ -13,9 +13,12 @@ extends = "$workspace.tab"
background = "$surface.1" background = "$surface.1"
text = "$text.0" text = "$text.0"
[workspace.sidebar] [workspace.sidebar.icons]
padding = { left = 10, right = 10 } padding = { left = 10, right = 10 }
[workspace.sidebar.resize_handle]
margin = { left = 6 }
[workspace.sidebar_icon] [workspace.sidebar_icon]
color = "$text.2.color" color = "$text.2.color"

View file

@ -36,7 +36,7 @@ pub struct Workspace {
pub background: Color, pub background: Color,
pub tab: Tab, pub tab: Tab,
pub active_tab: Tab, pub active_tab: Tab,
pub sidebar: ContainerStyle, pub sidebar: Sidebar,
pub sidebar_icon: SidebarIcon, pub sidebar_icon: SidebarIcon,
pub active_sidebar_icon: SidebarIcon, pub active_sidebar_icon: SidebarIcon,
} }
@ -52,6 +52,12 @@ pub struct Tab {
pub icon_conflict: Color, pub icon_conflict: Color,
} }
#[derive(Deserialize)]
pub struct Sidebar {
pub icons: ContainerStyle,
pub resize_handle: ContainerStyle,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct SidebarIcon { pub struct SidebarIcon {
pub color: Color, pub color: Color,

View file

@ -960,11 +960,15 @@ impl View for Workspace {
.with_child({ .with_child({
let mut content = Flex::row(); let mut content = Flex::row();
content.add_child(self.left_sidebar.render(&settings, cx)); content.add_child(self.left_sidebar.render(&settings, cx));
if let Some(element) = self.left_sidebar.render_active_item(cx) { if let Some(element) =
self.left_sidebar.render_active_item(&settings, cx)
{
content.add_child(element); content.add_child(element);
} }
content.add_child(Expanded::new(1.0, self.center.render()).boxed()); content.add_child(Expanded::new(1.0, self.center.render()).boxed());
if let Some(element) = self.right_sidebar.render_active_item(cx) { if let Some(element) =
self.right_sidebar.render_active_item(&settings, cx)
{
content.add_child(element); content.add_child(element);
} }
content.add_child(self.right_sidebar.render(&settings, cx)); content.add_child(self.right_sidebar.render(&settings, cx));

View file

@ -1,5 +1,5 @@
use crate::Settings; use crate::Settings;
use gpui::{action, color::Color, elements::*, AnyViewHandle, AppContext, Border}; use gpui::{action, elements::*, AnyViewHandle, AppContext};
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
pub struct Sidebar { pub struct Sidebar {
@ -94,15 +94,15 @@ impl Sidebar {
})) }))
.boxed(), .boxed(),
) )
.with_style(&settings.theme.workspace.sidebar) .with_style(&settings.theme.workspace.sidebar.icons)
.boxed() .boxed()
} }
pub fn render_active_item(&self, cx: &AppContext) -> Option<ElementBox> { pub fn render_active_item(&self, settings: &Settings, cx: &AppContext) -> Option<ElementBox> {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
let mut container = Flex::row(); let mut container = Flex::row();
if matches!(self.side, Side::Right) { if matches!(self.side, Side::Right) {
container.add_child(self.render_resize_handle(cx)); container.add_child(self.render_resize_handle(settings, cx));
} }
container.add_child( container.add_child(
ConstrainedBox::new(ChildView::new(active_item.id()).boxed()) ConstrainedBox::new(ChildView::new(active_item.id()).boxed())
@ -110,7 +110,7 @@ impl Sidebar {
.boxed(), .boxed(),
); );
if matches!(self.side, Side::Left) { if matches!(self.side, Side::Left) {
container.add_child(self.render_resize_handle(cx)); container.add_child(self.render_resize_handle(settings, cx));
} }
Some(container.boxed()) Some(container.boxed())
} else { } else {
@ -118,12 +118,12 @@ impl Sidebar {
} }
} }
fn render_resize_handle(&self, cx: &AppContext) -> ElementBox { fn render_resize_handle(&self, settings: &Settings, cx: &AppContext) -> ElementBox {
let width = self.width.clone(); let width = self.width.clone();
let side = self.side; let side = self.side;
MouseEventHandler::new::<Self, _>(self.side.id(), cx, |_| { MouseEventHandler::new::<Self, _>(self.side.id(), cx, |_| {
Container::new(Empty::new().boxed()) Container::new(Empty::new().boxed())
.with_border(Border::left(3., Color::white())) .with_style(&settings.theme.workspace.sidebar.resize_handle)
.boxed() .boxed()
}) })
.on_drag(move |delta, cx| { .on_drag(move |delta, cx| {