chore: Upgrade to GPUI3 (#6)

* wip: gpui3

* wip: gpui3

* chore: fix clippy
This commit is contained in:
reya
2025-01-28 08:25:49 +07:00
committed by GitHub
parent 3c15e74e56
commit 72a6d79bc5
62 changed files with 2572 additions and 2511 deletions

View File

@@ -1,17 +1,14 @@
use crate::views::sidebar::inbox::Inbox;
use compose::Compose;
use gpui::{
div, px, AnyElement, AppContext, BorrowAppContext, Entity, EntityId, EventEmitter, FocusHandle,
FocusableView, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
StatefulInteractiveElement, Styled, View, ViewContext, VisualContext, WindowContext,
div, px, AnyElement, App, AppContext, BorrowAppContext, Context, Entity, EntityId,
EventEmitter, FocusHandle, Focusable, InteractiveElement, IntoElement, ParentElement, Render,
SharedString, StatefulInteractiveElement, Styled, Window,
};
use registry::chat::ChatRegistry;
use ui::{
button::{Button, ButtonRounded, ButtonVariants},
dock_area::{
panel::{Panel, PanelEvent},
state::PanelState,
},
dock_area::panel::{Panel, PanelEvent},
popup_menu::PopupMenu,
scroll::ScrollbarAxis,
theme::{scale::ColorScaleStep, ActiveTheme},
@@ -28,33 +25,33 @@ pub struct Sidebar {
zoomable: bool,
focus_handle: FocusHandle,
// Dock
inbox: View<Inbox>,
inbox: Entity<Inbox>,
view_id: EntityId,
}
impl Sidebar {
pub fn new(cx: &mut WindowContext) -> View<Self> {
cx.new_view(Self::view)
pub fn new(window: &mut Window, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self::view(window, cx))
}
fn view(cx: &mut ViewContext<Self>) -> Self {
let inbox = cx.new_view(Inbox::new);
fn view(window: &mut Window, cx: &mut Context<Self>) -> Self {
let inbox = cx.new(|cx| Inbox::new(window, cx));
Self {
name: "Sidebar".into(),
closeable: true,
zoomable: true,
focus_handle: cx.focus_handle(),
view_id: cx.view().entity_id(),
view_id: cx.model().entity_id(),
inbox,
}
}
fn show_compose(&mut self, cx: &mut ViewContext<Self>) {
let compose = cx.new_view(Compose::new);
fn show_compose(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let compose = cx.new(|cx| Compose::new(window, cx));
cx.open_modal(move |modal, cx| {
let label = compose.read(cx).label(cx);
window.open_modal(cx, move |modal, window, cx| {
let label = compose.read(cx).label(window, cx);
modal
.title("Direct Messages")
@@ -72,13 +69,13 @@ impl Sidebar {
.bold()
.rounded(ButtonRounded::Large)
.w_full()
.on_click(cx.listener_for(&compose, |this, _, cx| {
if let Some(room) = this.room(cx) {
.on_click(window.listener_for(&compose, |this, _, window, cx| {
if let Some(room) = this.room(window, cx) {
cx.update_global::<ChatRegistry, _>(|this, cx| {
this.new_room(room, cx);
});
cx.close_modal();
window.close_modal(cx);
}
})),
),
@@ -92,41 +89,37 @@ impl Panel for Sidebar {
"Sidebar".into()
}
fn title(&self, _cx: &WindowContext) -> AnyElement {
fn title(&self, _cx: &App) -> AnyElement {
self.name.clone().into_any_element()
}
fn closeable(&self, _cx: &WindowContext) -> bool {
fn closeable(&self, _cx: &App) -> bool {
self.closeable
}
fn zoomable(&self, _cx: &WindowContext) -> bool {
fn zoomable(&self, _cx: &App) -> bool {
self.zoomable
}
fn popup_menu(&self, menu: PopupMenu, _cx: &WindowContext) -> PopupMenu {
fn popup_menu(&self, menu: PopupMenu, _cx: &App) -> PopupMenu {
menu.track_focus(&self.focus_handle)
}
fn toolbar_buttons(&self, _cx: &WindowContext) -> Vec<Button> {
fn toolbar_buttons(&self, _window: &Window, _cx: &App) -> Vec<Button> {
vec![]
}
fn dump(&self, _cx: &AppContext) -> PanelState {
PanelState::new(self)
}
}
impl EventEmitter<PanelEvent> for Sidebar {}
impl FocusableView for Sidebar {
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
impl Focusable for Sidebar {
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
impl Render for Sidebar {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.scrollable(self.view_id, ScrollbarAxis::Vertical)
.py_3()
@@ -159,7 +152,7 @@ impl Render for Sidebar {
)
.child("New Message")
.hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::THREE)))
.on_click(cx.listener(|this, _, cx| this.show_compose(cx))),
.on_click(cx.listener(|this, _, window, cx| this.show_compose(window, cx))),
),
)
.child(self.inbox.clone())