chore: refactor chat panel
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
use gpui::{
|
||||
div, prelude::FluentBuilder as _, px, AnyView, App, AppContext, Axis, Context, Element, Entity,
|
||||
InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels,
|
||||
Point, Render, StatefulInteractiveElement, Style, Styled as _, WeakEntity, Window,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{DockArea, DockItem};
|
||||
use crate::{
|
||||
dock_area::{panel::PanelView, tab_panel::TabPanel},
|
||||
@@ -5,14 +13,6 @@ use crate::{
|
||||
theme::{scale::ColorScaleStep, ActiveTheme as _},
|
||||
AxisExt as _, StyledExt,
|
||||
};
|
||||
use gpui::{
|
||||
div, prelude::FluentBuilder as _, px, AnyView, App, AppContext, Axis, Context, Element, Entity,
|
||||
InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels,
|
||||
Point, Render, StatefulInteractiveElement, Style, StyleRefinement, Styled as _, WeakEntity,
|
||||
Window,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Render)]
|
||||
struct ResizePanel;
|
||||
@@ -296,6 +296,7 @@ impl Dock {
|
||||
.upgrade()
|
||||
.expect("DockArea is missing")
|
||||
.read(cx);
|
||||
|
||||
let area_bounds = dock_area.bounds;
|
||||
let mut left_dock_size = Pixels(0.0);
|
||||
let mut right_dock_size = Pixels(0.0);
|
||||
@@ -326,6 +327,7 @@ impl Dock {
|
||||
DockPlacement::Bottom => area_bounds.bottom() - mouse_position.y,
|
||||
DockPlacement::Center => unreachable!(),
|
||||
};
|
||||
|
||||
match self.placement {
|
||||
DockPlacement::Left => {
|
||||
let max_size = area_bounds.size.width - PANEL_MIN_SIZE - right_dock_size;
|
||||
@@ -356,7 +358,7 @@ impl Render for Dock {
|
||||
return div();
|
||||
}
|
||||
|
||||
let cache_style = StyleRefinement::default().v_flex().size_full();
|
||||
let cache_style = gpui::StyleRefinement::default().v_flex().size_full();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{button::Button, popup_menu::PopupMenu};
|
||||
use gpui::{
|
||||
AnyElement, AnyView, App, Entity, EventEmitter, FocusHandle, Focusable, Hsla, IntoElement,
|
||||
Render, SharedString, Window,
|
||||
AnyElement, AnyView, App, Element, Entity, EventEmitter, FocusHandle, Focusable, Hsla, Render,
|
||||
SharedString, Window,
|
||||
};
|
||||
|
||||
pub enum PanelEvent {
|
||||
@@ -31,14 +31,9 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
|
||||
/// Once you have defined a panel id, this must not be changed.
|
||||
fn panel_id(&self) -> SharedString;
|
||||
|
||||
/// The optional facepile of the panel
|
||||
fn panel_facepile(&self, _cx: &App) -> Option<Vec<String>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// The title of the panel
|
||||
fn title(&self, _cx: &App) -> AnyElement {
|
||||
SharedString::from("Unamed").into_any_element()
|
||||
SharedString::from("Unnamed").into_any()
|
||||
}
|
||||
|
||||
/// Whether the panel can be closed, default is `true`.
|
||||
@@ -85,7 +80,6 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
|
||||
|
||||
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 closable(&self, cx: &App) -> bool;
|
||||
fn zoomable(&self, cx: &App) -> bool;
|
||||
@@ -103,10 +97,6 @@ impl<T: Panel> PanelView for Entity<T> {
|
||||
self.read(cx).panel_id()
|
||||
}
|
||||
|
||||
fn panel_facepile(&self, cx: &App) -> Option<Vec<String>> {
|
||||
self.read(cx).panel_facepile(cx)
|
||||
}
|
||||
|
||||
fn title(&self, cx: &App) -> AnyElement {
|
||||
self.read(cx).title(cx)
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@ use crate::{
|
||||
v_flex, AxisExt, IconName, Placement, Selectable, Sizable, StyledExt,
|
||||
};
|
||||
use gpui::{
|
||||
div, img, prelude::FluentBuilder, px, rems, App, AppContext, Context, Corner, DefiniteLength,
|
||||
div, prelude::FluentBuilder, px, rems, App, AppContext, Context, Corner, DefiniteLength,
|
||||
DismissEvent, DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, Focusable,
|
||||
InteractiveElement as _, IntoElement, ObjectFit, ParentElement, Pixels, Render, ScrollHandle,
|
||||
SharedString, StatefulInteractiveElement, StyleRefinement, Styled, StyledImage, WeakEntity,
|
||||
Window,
|
||||
InteractiveElement as _, IntoElement, ParentElement, Pixels, Render, ScrollHandle,
|
||||
SharedString, StatefulInteractiveElement, Styled, WeakEntity, Window,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -591,30 +590,8 @@ impl TabPanel {
|
||||
.child(
|
||||
div()
|
||||
.w_full()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.text_ellipsis()
|
||||
.text_xs()
|
||||
.when_some(panel.panel_facepile(cx), |this, facepill| {
|
||||
this.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row_reverse()
|
||||
.items_center()
|
||||
.justify_start()
|
||||
.children(facepill.into_iter().enumerate().rev().map(
|
||||
|(ix, face)| {
|
||||
div().when(ix > 0, |div| div.ml_neg_1()).child(
|
||||
img(face)
|
||||
.size_4()
|
||||
.rounded_full()
|
||||
.object_fit(ObjectFit::Cover),
|
||||
)
|
||||
},
|
||||
)),
|
||||
)
|
||||
})
|
||||
.child(panel.title(cx)),
|
||||
)
|
||||
.when(state.draggable, |this| {
|
||||
@@ -675,7 +652,7 @@ impl TabPanel {
|
||||
}
|
||||
|
||||
Some(
|
||||
Tab::new(("tab", ix), panel.title(cx), panel.panel_facepile(cx))
|
||||
Tab::new(("tab", ix), panel.title(cx))
|
||||
.py_2()
|
||||
.selected(active)
|
||||
.disabled(disabled)
|
||||
@@ -783,7 +760,7 @@ impl TabPanel {
|
||||
.child(
|
||||
active_panel
|
||||
.view()
|
||||
.cached(StyleRefinement::default().v_flex().size_full()),
|
||||
.cached(gpui::StyleRefinement::default().v_flex().size_full()),
|
||||
),
|
||||
)
|
||||
.when(state.droppable, |this| {
|
||||
|
||||
@@ -11,7 +11,6 @@ pub struct Tab {
|
||||
id: ElementId,
|
||||
base: Stateful<Div>,
|
||||
label: AnyElement,
|
||||
facepill: Option<Vec<String>>,
|
||||
prefix: Option<AnyElement>,
|
||||
suffix: Option<AnyElement>,
|
||||
disabled: bool,
|
||||
@@ -19,11 +18,7 @@ pub struct Tab {
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
pub fn new(
|
||||
id: impl Into<ElementId>,
|
||||
label: impl IntoElement,
|
||||
facepill: Option<Vec<String>>,
|
||||
) -> Self {
|
||||
pub fn new(id: impl Into<ElementId>, label: impl IntoElement) -> Self {
|
||||
let id: ElementId = id.into();
|
||||
|
||||
Self {
|
||||
@@ -34,7 +29,6 @@ impl Tab {
|
||||
selected: false,
|
||||
prefix: None,
|
||||
suffix: None,
|
||||
facepill,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,25 +126,6 @@ impl RenderOnce for Tab {
|
||||
.gap_1()
|
||||
.text_ellipsis()
|
||||
.text_xs()
|
||||
.when_some(self.facepill, |this, facepill| {
|
||||
this.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row_reverse()
|
||||
.items_center()
|
||||
.justify_start()
|
||||
.children(facepill.into_iter().enumerate().rev().map(
|
||||
|(ix, face)| {
|
||||
div().when(ix > 0, |div| div.ml_neg_1()).child(
|
||||
img(face)
|
||||
.size_4()
|
||||
.rounded_full()
|
||||
.object_fit(ObjectFit::Cover),
|
||||
)
|
||||
},
|
||||
)),
|
||||
)
|
||||
})
|
||||
.child(self.label),
|
||||
)
|
||||
.when_some(self.suffix, |this, suffix| this.child(suffix))
|
||||
|
||||
Reference in New Issue
Block a user