Remove lock from element states

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-08-27 18:04:21 +02:00
co-authored by Nathan Sobo
parent d5b7e2d4e3
commit 53dc08dfc5
14 changed files with 143 additions and 104 deletions
+6 -7
View File
@@ -6,8 +6,7 @@ use gpui::{
elements::*,
geometry::{rect::RectF, vector::vec2f},
keymap::Binding,
AppContext, Border, Entity, MutableAppContext, Quad, RenderContext, View, ViewContext,
ViewHandle,
Border, Entity, MutableAppContext, Quad, RenderContext, View, ViewContext, ViewHandle,
};
use postage::watch;
use std::{cmp, path::Path, sync::Arc};
@@ -175,7 +174,7 @@ impl Pane {
cx.emit(Event::Split(direction));
}
fn render_tabs(&self, cx: &AppContext) -> ElementBox {
fn render_tabs(&self, cx: &mut RenderContext<Self>) -> ElementBox {
let settings = self.settings.borrow();
let theme = &settings.theme;
let line_height = cx.font_cache().line_height(
@@ -194,7 +193,7 @@ impl Pane {
row.add_child(
Expanded::new(
1.0,
MouseEventHandler::new::<Tab, _>(item.id(), cx, |mouse_state| {
MouseEventHandler::new::<Tab, _, _>(item.id(), cx, |mouse_state, cx| {
let title = item.title(cx);
let mut border = border.clone();
@@ -299,7 +298,7 @@ impl Pane {
is_dirty: bool,
has_conflict: bool,
theme: &theme::Theme,
cx: &AppContext,
cx: &mut RenderContext<Self>,
) -> ElementBox {
enum TabCloseButton {}
@@ -318,7 +317,7 @@ impl Pane {
let close_color = current_color.unwrap_or(theme.workspace.tab.icon_close);
let icon = Svg::new("icons/x.svg").with_color(close_color);
MouseEventHandler::new::<TabCloseButton, _>(item_id, cx, |mouse_state| {
MouseEventHandler::new::<TabCloseButton, _, _>(item_id, cx, |mouse_state, _| {
if mouse_state.hovered {
Container::new(icon.with_color(Color::white()).boxed())
.with_background_color(if mouse_state.clicked {
@@ -370,7 +369,7 @@ impl View for Pane {
"Pane"
}
fn render<'a>(&self, cx: &RenderContext<Self>) -> ElementBox {
fn render(&self, cx: &mut RenderContext<Self>) -> ElementBox {
if let Some(active_item) = self.active_item() {
Flex::column()
.with_child(self.render_tabs(cx))
+15 -6
View File
@@ -1,5 +1,6 @@
use super::Workspace;
use crate::Settings;
use gpui::{action, elements::*, AnyViewHandle, AppContext};
use gpui::{action, elements::*, AnyViewHandle, MutableAppContext, RenderContext};
use std::{cell::RefCell, rc::Rc};
pub struct Sidebar {
@@ -56,7 +57,7 @@ impl Sidebar {
.map(|item| &item.view)
}
pub fn render(&self, settings: &Settings, cx: &AppContext) -> ElementBox {
pub fn render(&self, settings: &Settings, cx: &mut RenderContext<Workspace>) -> ElementBox {
let side = self.side;
let theme = &settings.theme;
let line_height = cx.font_cache().line_height(
@@ -73,7 +74,7 @@ impl Sidebar {
&settings.theme.workspace.sidebar_icon
};
enum SidebarButton {}
MouseEventHandler::new::<SidebarButton, _>(item.view.id(), cx, |_| {
MouseEventHandler::new::<SidebarButton, _, _>(item.view.id(), cx, |_, _| {
ConstrainedBox::new(
Align::new(
ConstrainedBox::new(
@@ -98,7 +99,11 @@ impl Sidebar {
.boxed()
}
pub fn render_active_item(&self, settings: &Settings, cx: &AppContext) -> Option<ElementBox> {
pub fn render_active_item(
&self,
settings: &Settings,
cx: &mut MutableAppContext,
) -> Option<ElementBox> {
if let Some(active_item) = self.active_item() {
let mut container = Flex::row();
if matches!(self.side, Side::Right) {
@@ -118,10 +123,14 @@ impl Sidebar {
}
}
fn render_resize_handle(&self, settings: &Settings, cx: &AppContext) -> ElementBox {
fn render_resize_handle(
&self,
settings: &Settings,
mut cx: &mut MutableAppContext,
) -> ElementBox {
let width = self.width.clone();
let side = self.side;
MouseEventHandler::new::<Self, _>(self.side.id(), cx, |_| {
MouseEventHandler::new::<Self, _, _>(self.side.id(), &mut cx, |_, _| {
Container::new(Empty::new().boxed())
.with_style(&settings.theme.workspace.sidebar.resize_handle)
.boxed()