wip: refactor

This commit is contained in:
2025-02-03 08:23:03 +07:00
parent c982c802e2
commit d921720042
29 changed files with 534 additions and 265 deletions

View File

@@ -244,7 +244,8 @@ impl Dock {
.right(px(1.))
.h_full()
.w(HANDLE_SIZE)
.py_10()
.pt_12()
.pb_4()
})
.when(self.placement.is_right(), |this| {
this.cursor_col_resize()
@@ -252,7 +253,8 @@ impl Dock {
.left(px(1.))
.h_full()
.w(HANDLE_SIZE)
.py_10()
.pt_12()
.pb_4()
})
.when(self.placement.is_bottom(), |this| {
this.cursor_row_resize()

View File

@@ -5,7 +5,7 @@ use crate::dock_area::{
tab_panel::TabPanel,
};
use gpui::{
actions, canvas, div, prelude::FluentBuilder, AnyElement, AnyView, App, AppContext, Axis,
actions, canvas, div, prelude::FluentBuilder, px, AnyElement, AnyView, App, AppContext, Axis,
Bounds, Context, Edges, Entity, EntityId, EventEmitter, InteractiveElement as _, IntoElement,
ParentElement as _, Pixels, Render, SharedString, Styled, Subscription, WeakEntity, Window,
};
@@ -543,7 +543,7 @@ impl DockArea {
} else {
self.set_left_dock(
DockItem::tabs(vec![panel], None, &weak_self, window, cx),
None,
Some(px(320.)),
true,
window,
cx,
@@ -569,7 +569,7 @@ impl DockArea {
} else {
self.set_right_dock(
DockItem::tabs(vec![panel], None, &weak_self, window, cx),
None,
Some(px(320.)),
true,
window,
cx,

View File

@@ -42,7 +42,7 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
}
/// Whether the panel can be closed, default is `true`.
fn closeable(&self, _cx: &App) -> bool {
fn closable(&self, _cx: &App) -> bool {
true
}
@@ -66,7 +66,7 @@ pub trait PanelView: 'static + Send + Sync {
fn panel_id(&self, cx: &App) -> SharedString;
fn panel_facepile(&self, cx: &App) -> Option<Vec<String>>;
fn title(&self, cx: &App) -> AnyElement;
fn closeable(&self, cx: &App) -> bool;
fn closable(&self, cx: &App) -> bool;
fn zoomable(&self, cx: &App) -> bool;
fn popup_menu(&self, menu: PopupMenu, cx: &App) -> PopupMenu;
fn toolbar_buttons(&self, window: &Window, cx: &App) -> Vec<Button>;
@@ -87,8 +87,8 @@ impl<T: Panel> PanelView for Entity<T> {
self.read(cx).title(cx)
}
fn closeable(&self, cx: &App) -> bool {
self.read(cx).closeable(cx)
fn closable(&self, cx: &App) -> bool {
self.read(cx).closable(cx)
}
fn zoomable(&self, cx: &App) -> bool {

View File

@@ -89,14 +89,14 @@ impl Panel for TabPanel {
.unwrap_or("Empty Tab".into_any_element())
}
fn closeable(&self, cx: &App) -> bool {
fn closable(&self, cx: &App) -> bool {
if !self.closeable {
return false;
}
self.active_panel()
.map(|panel| panel.closeable(cx))
.unwrap_or(false)
.map(|panel| panel.closable(cx))
.unwrap_or(true)
}
fn zoomable(&self, cx: &App) -> bool {
@@ -409,6 +409,7 @@ impl TabPanel {
}
let dock_area = self.dock_area.upgrade()?.read(cx);
if !dock_area.is_dock_collapsible(placement, cx) {
return None;
}
@@ -651,6 +652,7 @@ impl TabPanel {
.h_full()
.flex_grow()
.min_w_16()
.rounded(px(cx.theme().radius))
.when(state.droppable, |this| {
this.drag_over::<DragPanel>(|this, _, _, cx| {
this.bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
@@ -1013,7 +1015,7 @@ impl Render for TabPanel {
let focus_handle = self.focus_handle(cx);
let mut state = TabState {
closeable: self.closeable(cx),
closeable: self.closable(cx),
draggable: self.draggable(cx),
droppable: self.droppable(cx),
zoomable: self.zoomable(cx),

View File

@@ -51,7 +51,8 @@ impl RenderOnce for ResizeHandle {
.left(px(-1.))
.w(HANDLE_SIZE)
.h_full()
.py_10()
.pt_12()
.pb_4()
})
.when(self.axis.is_vertical(), |this| {
this.cursor_row_resize()
@@ -59,7 +60,7 @@ impl RenderOnce for ResizeHandle {
.left_0()
.w_full()
.h(HANDLE_SIZE)
.px_10()
.px_6()
})
.child(
div()

View File

@@ -1,7 +1,7 @@
use crate::theme::{scale::ColorScaleStep, ActiveTheme};
use gpui::{
div, px, App, AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString,
Styled, Window,
div, px, relative, App, AppContext, Context, Entity, IntoElement, ParentElement, Render,
SharedString, Styled, Window,
};
pub struct Tooltip {
@@ -21,13 +21,15 @@ impl Render for Tooltip {
div()
.font_family(".SystemUIFont")
.m_3()
.bg(cx.theme().base.step(cx, ColorScaleStep::TWELVE))
.text_color(cx.theme().base.step(cx, ColorScaleStep::ONE))
.border_1()
.border_color(cx.theme().base.step(cx, ColorScaleStep::FIVE))
.bg(cx.theme().base.step(cx, ColorScaleStep::THREE))
.shadow_md()
.rounded(px(6.))
.py_0p5()
.py_1()
.px_2()
.text_sm()
.text_xs()
.line_height(relative(1.))
.child(self.text.clone()),
)
}