Mainline GPUI2 UI work (#3062)
This PR mainlines the current state of new GPUI2-based UI from the `gpui2-ui` branch. Release Notes: - N/A --------- Co-authored-by: Nate Butler <iamnbutler@gmail.com> Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com> Co-authored-by: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Nate <nate@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e7ee8a95f6
commit
f26ca0866c
85 changed files with 4658 additions and 1623 deletions
|
@ -1,142 +1,153 @@
|
|||
mod assistant_panel;
|
||||
mod breadcrumb;
|
||||
mod buffer;
|
||||
mod chat_panel;
|
||||
mod collab_panel;
|
||||
mod command_palette;
|
||||
mod context_menu;
|
||||
mod editor;
|
||||
mod facepile;
|
||||
mod follow_group;
|
||||
mod icon_button;
|
||||
mod keybinding;
|
||||
mod list;
|
||||
mod list_item;
|
||||
mod list_section_header;
|
||||
mod palette;
|
||||
mod palette_item;
|
||||
mod panel;
|
||||
mod panes;
|
||||
mod player_stack;
|
||||
mod project_panel;
|
||||
mod status_bar;
|
||||
mod tab;
|
||||
mod tab_bar;
|
||||
mod terminal;
|
||||
mod title_bar;
|
||||
mod toolbar;
|
||||
mod traffic_lights;
|
||||
mod workspace;
|
||||
|
||||
pub use assistant_panel::*;
|
||||
pub use breadcrumb::*;
|
||||
pub use buffer::*;
|
||||
pub use chat_panel::*;
|
||||
pub use collab_panel::*;
|
||||
pub use command_palette::*;
|
||||
pub use context_menu::*;
|
||||
pub use editor::*;
|
||||
pub use facepile::*;
|
||||
pub use follow_group::*;
|
||||
pub use icon_button::*;
|
||||
pub use keybinding::*;
|
||||
pub use list::*;
|
||||
pub use list_item::*;
|
||||
pub use list_section_header::*;
|
||||
pub use palette::*;
|
||||
pub use palette_item::*;
|
||||
pub use panel::*;
|
||||
pub use panes::*;
|
||||
pub use player_stack::*;
|
||||
pub use project_panel::*;
|
||||
pub use status_bar::*;
|
||||
pub use tab::*;
|
||||
pub use tab_bar::*;
|
||||
pub use terminal::*;
|
||||
pub use title_bar::*;
|
||||
pub use toolbar::*;
|
||||
pub use traffic_lights::*;
|
||||
pub use workspace::*;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
// Nate: Commenting this out for now, unsure if we need it.
|
||||
|
||||
use gpui2::elements::div;
|
||||
use gpui2::interactive::Interactive;
|
||||
use gpui2::platform::MouseButton;
|
||||
use gpui2::style::StyleHelpers;
|
||||
use gpui2::{ArcCow, Element, EventContext, IntoElement, ParentElement, ViewContext};
|
||||
// use std::marker::PhantomData;
|
||||
// use std::rc::Rc;
|
||||
|
||||
struct ButtonHandlers<V, D> {
|
||||
click: Option<Rc<dyn Fn(&mut V, &D, &mut EventContext<V>)>>,
|
||||
}
|
||||
// use gpui2::elements::div;
|
||||
// use gpui2::interactive::Interactive;
|
||||
// use gpui2::platform::MouseButton;
|
||||
// use gpui2::{ArcCow, Element, EventContext, IntoElement, ParentElement, ViewContext};
|
||||
|
||||
impl<V, D> Default for ButtonHandlers<V, D> {
|
||||
fn default() -> Self {
|
||||
Self { click: None }
|
||||
}
|
||||
}
|
||||
// struct ButtonHandlers<V, D> {
|
||||
// click: Option<Rc<dyn Fn(&mut V, &D, &mut EventContext<V>)>>,
|
||||
// }
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct Button<V: 'static, D: 'static> {
|
||||
handlers: ButtonHandlers<V, D>,
|
||||
label: Option<ArcCow<'static, str>>,
|
||||
icon: Option<ArcCow<'static, str>>,
|
||||
data: Rc<D>,
|
||||
view_type: PhantomData<V>,
|
||||
}
|
||||
// impl<V, D> Default for ButtonHandlers<V, D> {
|
||||
// fn default() -> Self {
|
||||
// Self { click: None }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Impl block for buttons without data.
|
||||
// See below for an impl block for any button.
|
||||
impl<V: 'static> Button<V, ()> {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
handlers: ButtonHandlers::default(),
|
||||
label: None,
|
||||
icon: None,
|
||||
data: Rc::new(()),
|
||||
view_type: PhantomData,
|
||||
}
|
||||
}
|
||||
// #[derive(Element)]
|
||||
// pub struct Button<V: 'static, D: 'static> {
|
||||
// handlers: ButtonHandlers<V, D>,
|
||||
// label: Option<ArcCow<'static, str>>,
|
||||
// icon: Option<ArcCow<'static, str>>,
|
||||
// data: Rc<D>,
|
||||
// view_type: PhantomData<V>,
|
||||
// }
|
||||
|
||||
pub fn data<D: 'static>(self, data: D) -> Button<V, D> {
|
||||
Button {
|
||||
handlers: ButtonHandlers::default(),
|
||||
label: self.label,
|
||||
icon: self.icon,
|
||||
data: Rc::new(data),
|
||||
view_type: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Impl block for buttons without data.
|
||||
// // See below for an impl block for any button.
|
||||
// impl<V: 'static> Button<V, ()> {
|
||||
// fn new() -> Self {
|
||||
// Self {
|
||||
// handlers: ButtonHandlers::default(),
|
||||
// label: None,
|
||||
// icon: None,
|
||||
// data: Rc::new(()),
|
||||
// view_type: PhantomData,
|
||||
// }
|
||||
// }
|
||||
|
||||
// Impl block for button regardless of its data type.
|
||||
impl<V: 'static, D: 'static> Button<V, D> {
|
||||
pub fn label(mut self, label: impl Into<ArcCow<'static, str>>) -> Self {
|
||||
self.label = Some(label.into());
|
||||
self
|
||||
}
|
||||
// pub fn data<D: 'static>(self, data: D) -> Button<V, D> {
|
||||
// Button {
|
||||
// handlers: ButtonHandlers::default(),
|
||||
// label: self.label,
|
||||
// icon: self.icon,
|
||||
// data: Rc::new(data),
|
||||
// view_type: PhantomData,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn icon(mut self, icon: impl Into<ArcCow<'static, str>>) -> Self {
|
||||
self.icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
// // Impl block for button regardless of its data type.
|
||||
// impl<V: 'static, D: 'static> Button<V, D> {
|
||||
// pub fn label(mut self, label: impl Into<ArcCow<'static, str>>) -> Self {
|
||||
// self.label = Some(label.into());
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl Fn(&mut V, &D, &mut EventContext<V>) + 'static,
|
||||
) -> Self {
|
||||
self.handlers.click = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
}
|
||||
// pub fn icon(mut self, icon: impl Into<ArcCow<'static, str>>) -> Self {
|
||||
// self.icon = Some(icon.into());
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn button<V>() -> Button<V, ()> {
|
||||
Button::new()
|
||||
}
|
||||
// pub fn on_click(
|
||||
// mut self,
|
||||
// handler: impl Fn(&mut V, &D, &mut EventContext<V>) + 'static,
|
||||
// ) -> Self {
|
||||
// self.handlers.click = Some(Rc::new(handler));
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<V: 'static, D: 'static> Button<V, D> {
|
||||
fn render(
|
||||
&mut self,
|
||||
view: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> impl IntoElement<V> + Interactive<V> {
|
||||
// let colors = &cx.theme::<Theme>().colors;
|
||||
// pub fn button<V>() -> Button<V, ()> {
|
||||
// Button::new()
|
||||
// }
|
||||
|
||||
let button = div()
|
||||
// .fill(colors.error(0.5))
|
||||
.h_4()
|
||||
.children(self.label.clone());
|
||||
// impl<V: 'static, D: 'static> Button<V, D> {
|
||||
// fn render(
|
||||
// &mut self,
|
||||
// view: &mut V,
|
||||
// cx: &mut ViewContext<V>,
|
||||
// ) -> impl IntoElement<V> + Interactive<V> {
|
||||
// // let colors = &cx.theme::<Theme>().colors;
|
||||
|
||||
if let Some(handler) = self.handlers.click.clone() {
|
||||
let data = self.data.clone();
|
||||
button.on_mouse_down(MouseButton::Left, move |view, event, cx| {
|
||||
handler(view, data.as_ref(), cx)
|
||||
})
|
||||
} else {
|
||||
button
|
||||
}
|
||||
}
|
||||
}
|
||||
// let button = div()
|
||||
// // .fill(colors.error(0.5))
|
||||
// .h_4()
|
||||
// .children(self.label.clone());
|
||||
|
||||
// if let Some(handler) = self.handlers.click.clone() {
|
||||
// let data = self.data.clone();
|
||||
// button.on_mouse_down(MouseButton::Left, move |view, event, cx| {
|
||||
// handler(view, data.as_ref(), cx)
|
||||
// })
|
||||
// } else {
|
||||
// button
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue