WIP
co-authored-by: conrad <conrad@zed.dev> co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
@@ -7,10 +7,10 @@ pub struct Avatar {
|
||||
shape: Shape,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Avatar {
|
||||
type Rendered = Img<V>;
|
||||
impl Component for Avatar {
|
||||
type Rendered = Img;
|
||||
|
||||
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, _: &mut WindowContext) -> Self::Rendered {
|
||||
let mut img = img();
|
||||
|
||||
if self.shape == Shape::Circle {
|
||||
@@ -51,12 +51,12 @@ mod stories {
|
||||
|
||||
pub struct AvatarStory;
|
||||
|
||||
impl Render<Self> for AvatarStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for AvatarStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Avatar>(cx))
|
||||
.child(Story::title_for::<Avatar>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Avatar::new(
|
||||
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
DefiniteLength, DefiniteLength, Div, Hsla, MouseButton, RenderOnce, Stateful,
|
||||
StatefulInteractiveElement, WindowContext,
|
||||
DefiniteLength, Div, Hsla, MouseButton, MouseDownEvent, RenderOnce, StatefulInteractiveElement,
|
||||
WindowContext,
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
@@ -64,9 +64,10 @@ impl ButtonVariant {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Button {
|
||||
disabled: bool,
|
||||
click_handler: Option<CallbackHandle<()>>,
|
||||
click_handler: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext)>>,
|
||||
icon: Option<Icon>,
|
||||
icon_position: Option<IconPosition>,
|
||||
label: SharedString,
|
||||
@@ -75,10 +76,10 @@ pub struct Button {
|
||||
color: Option<TextColor>,
|
||||
}
|
||||
|
||||
impl RenderOnce for Button {
|
||||
type Element = Stateful<Div>;
|
||||
impl Component for Button {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let (icon_color, label_color) = match (self.disabled, self.color) {
|
||||
(true, _) => (TextColor::Disabled, TextColor::Disabled),
|
||||
(_, None) => (TextColor::Default, TextColor::Default),
|
||||
@@ -116,9 +117,9 @@ impl RenderOnce for Button {
|
||||
button = button.w(width).justify_center();
|
||||
}
|
||||
|
||||
if let Some(click_handler) = self.handlers.click.clone() {
|
||||
button = button.on_mouse_down(MouseButton::Left, move |state, event, cx| {
|
||||
click_handler(state, cx);
|
||||
if let Some(click_handler) = self.click_handler.clone() {
|
||||
button = button.on_mouse_down(MouseButton::Left, move |event, cx| {
|
||||
click_handler(event, cx);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,8 +168,11 @@ impl Button {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_click(mut self, handler: CallbackHandle<()>) -> Self {
|
||||
self.handlers.click = Some(handler);
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
|
||||
) -> Self {
|
||||
self.click_handler = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
@@ -215,15 +219,15 @@ impl Component for ButtonGroup {
|
||||
let mut group = h_stack();
|
||||
|
||||
for button in self.buttons.into_iter() {
|
||||
group = group.child(button.render(view, cx));
|
||||
group = group.child(button.render(cx));
|
||||
}
|
||||
|
||||
group
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ButtonGroup<V> {
|
||||
pub fn new(buttons: Vec<Button<V>>) -> Self {
|
||||
impl ButtonGroup {
|
||||
pub fn new(buttons: Vec<Button>) -> Self {
|
||||
Self { buttons }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use gpui::{div, prelude::*, Div, Element, ElementId, RenderOnce, Stateful, Styled, ViewContext};
|
||||
use std::sync::Arc;
|
||||
use gpui::{div, prelude::*, Div, Element, ElementId, RenderOnce, Styled, WindowContext};
|
||||
|
||||
use theme2::ActiveTheme;
|
||||
|
||||
use crate::{Icon, IconElement, Selection, TextColor};
|
||||
|
||||
pub type CheckHandler<V> = Arc<dyn Fn(Selection, &mut V, &mut ViewContext<V>) + Send + Sync>;
|
||||
pub type CheckHandler = Box<dyn Fn(&Selection, &mut WindowContext) + 'static>;
|
||||
|
||||
/// # Checkbox
|
||||
///
|
||||
@@ -12,17 +12,17 @@ pub type CheckHandler<V> = Arc<dyn Fn(Selection, &mut V, &mut ViewContext<V>) +
|
||||
/// Each checkbox works independently from other checkboxes in the list,
|
||||
/// therefore checking an additional box does not affect any other selections.
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Checkbox<V: 'static> {
|
||||
pub struct Checkbox {
|
||||
id: ElementId,
|
||||
checked: Selection,
|
||||
disabled: bool,
|
||||
on_click: Option<CheckHandler<V>>,
|
||||
on_click: Option<CheckHandler>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Checkbox<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Checkbox {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let group_id = format!("checkbox_group_{:?}", self.id);
|
||||
|
||||
let icon = match self.checked {
|
||||
@@ -137,13 +137,11 @@ impl<V: 'static> Component<V> for Checkbox<V> {
|
||||
)
|
||||
.when_some(
|
||||
self.on_click.filter(|_| !self.disabled),
|
||||
|this, on_click| {
|
||||
this.on_click(move |view, _, cx| on_click(self.checked.inverse(), view, cx))
|
||||
},
|
||||
|this, on_click| this.on_click(move |_, cx| on_click(&self.checked.inverse(), cx)),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<V: 'static> Checkbox<V> {
|
||||
impl Checkbox {
|
||||
pub fn new(id: impl Into<ElementId>, checked: Selection) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
@@ -160,13 +158,13 @@ impl<V: 'static> Checkbox<V> {
|
||||
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl 'static + Fn(Selection, &mut V, &mut ViewContext<V>) + Send + Sync,
|
||||
handler: impl 'static + Fn(&Selection, &mut WindowContext) + Send + Sync,
|
||||
) -> Self {
|
||||
self.on_click = Some(Arc::new(handler));
|
||||
self.on_click = Some(Box::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
pub fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let group_id = format!("checkbox_group_{:?}", self.id);
|
||||
|
||||
let icon = match self.checked {
|
||||
@@ -281,9 +279,7 @@ impl<V: 'static> Checkbox<V> {
|
||||
)
|
||||
.when_some(
|
||||
self.on_click.filter(|_| !self.disabled),
|
||||
|this, on_click| {
|
||||
this.on_click(move |view, _, cx| on_click(self.checked.inverse(), view, cx))
|
||||
},
|
||||
|this, on_click| this.on_click(move |_, cx| on_click(&self.checked.inverse(), cx)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -299,8 +295,8 @@ mod stories {
|
||||
|
||||
pub struct CheckboxStory;
|
||||
|
||||
impl Render<Self> for CheckboxStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for CheckboxStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -4,44 +4,39 @@ use std::rc::Rc;
|
||||
use crate::{prelude::*, v_stack, List, ListItem};
|
||||
use crate::{ListEntry, ListSeparator, ListSubHeader};
|
||||
use gpui::{
|
||||
overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, DispatchPhase, Div,
|
||||
EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedView, Manager, MouseButton,
|
||||
MouseDownEvent, Pixels, Point, Render, RenderOnce, View, VisualContext, WeakView,
|
||||
overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, ClickEvent, DispatchPhase,
|
||||
Div, EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedView, Manager, MouseButton,
|
||||
MouseDownEvent, Pixels, Point, Render, RenderOnce, View, VisualContext,
|
||||
};
|
||||
|
||||
pub enum ContextMenuItem<V> {
|
||||
pub enum ContextMenuItem {
|
||||
Separator(ListSeparator),
|
||||
Header(ListSubHeader),
|
||||
Entry(
|
||||
ListEntry<ContextMenu<V>>,
|
||||
Rc<dyn Fn(&mut V, &mut ViewContext<V>)>,
|
||||
),
|
||||
Entry(ListEntry, Rc<dyn Fn(&ClickEvent, &mut WindowContext)>),
|
||||
}
|
||||
|
||||
pub struct ContextMenu<V> {
|
||||
items: Vec<ContextMenuItem<V>>,
|
||||
pub struct ContextMenu {
|
||||
items: Vec<ContextMenuItem>,
|
||||
focus_handle: FocusHandle,
|
||||
handle: WeakView<V>,
|
||||
}
|
||||
|
||||
impl<V: 'static> FocusableView for ContextMenu<V> {
|
||||
impl FocusableView for ContextMenu {
|
||||
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> EventEmitter<Manager> for ContextMenu<V> {}
|
||||
impl EventEmitter<Manager> for ContextMenu {}
|
||||
|
||||
impl<V: 'static> ContextMenu<V> {
|
||||
impl ContextMenu {
|
||||
pub fn build(
|
||||
cx: &mut ViewContext<V>,
|
||||
f: impl FnOnce(Self, &mut ViewContext<Self>) -> Self,
|
||||
cx: &mut WindowContext,
|
||||
f: impl FnOnce(Self, &mut WindowContext) -> Self,
|
||||
) -> View<Self> {
|
||||
let handle = cx.view().downgrade();
|
||||
// let handle = cx.view().downgrade();
|
||||
cx.build_view(|cx| {
|
||||
f(
|
||||
Self {
|
||||
handle,
|
||||
items: Default::default(),
|
||||
focus_handle: cx.focus_handle(),
|
||||
},
|
||||
@@ -63,15 +58,15 @@ impl<V: 'static> ContextMenu<V> {
|
||||
|
||||
pub fn entry(
|
||||
mut self,
|
||||
view: ListEntry<Self>,
|
||||
on_click: impl Fn(&mut V, &mut ViewContext<V>) + 'static,
|
||||
view: ListEntry,
|
||||
on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
||||
) -> Self {
|
||||
self.items
|
||||
.push(ContextMenuItem::Entry(view, Rc::new(on_click)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn action(self, view: ListEntry<Self>, action: Box<dyn Action>) -> Self {
|
||||
pub fn action(self, view: ListEntry, action: Box<dyn Action>) -> Self {
|
||||
// todo: add the keybindings to the list entry
|
||||
self.entry(view, move |_, cx| cx.dispatch_action(action.boxed_clone()))
|
||||
}
|
||||
@@ -86,21 +81,23 @@ impl<V: 'static> ContextMenu<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Render<Self> for ContextMenu<V> {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ContextMenu {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
div().elevation_2(cx).flex().flex_row().child(
|
||||
v_stack()
|
||||
.min_w(px(200.))
|
||||
.track_focus(&self.focus_handle)
|
||||
.on_mouse_down_out(|this: &mut Self, _, cx| this.cancel(&Default::default(), cx))
|
||||
.on_mouse_down_out(
|
||||
cx.listener(|this: &mut Self, _, cx| this.cancel(&Default::default(), cx)),
|
||||
)
|
||||
// .on_action(ContextMenu::select_first)
|
||||
// .on_action(ContextMenu::select_last)
|
||||
// .on_action(ContextMenu::select_next)
|
||||
// .on_action(ContextMenu::select_prev)
|
||||
.on_action(ContextMenu::confirm)
|
||||
.on_action(ContextMenu::cancel)
|
||||
.on_action(cx.listener(ContextMenu::confirm))
|
||||
.on_action(cx.listener(ContextMenu::cancel))
|
||||
.flex_none()
|
||||
// .bg(cx.theme().colors().elevated_surface_background)
|
||||
// .border()
|
||||
@@ -115,10 +112,11 @@ impl<V: 'static> Render<Self> for ContextMenu<V> {
|
||||
ContextMenuItem::Header(header) => ListItem::Header(header.clone()),
|
||||
ContextMenuItem::Entry(entry, callback) => {
|
||||
let callback = callback.clone();
|
||||
let handle = self.handle.clone();
|
||||
ListItem::Entry(entry.clone().on_click(move |this, cx| {
|
||||
handle.update(cx, |view, cx| callback(view, cx)).ok();
|
||||
cx.emit(Manager::Dismiss);
|
||||
let dismiss = cx.listener(|_, _, cx| cx.emit(Manager::Dismiss));
|
||||
|
||||
ListItem::Entry(entry.clone().on_click(move |event, cx| {
|
||||
callback(event, cx);
|
||||
dismiss(event, cx)
|
||||
}))
|
||||
}
|
||||
})
|
||||
@@ -128,22 +126,21 @@ impl<V: 'static> Render<Self> for ContextMenu<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MenuHandle<V: 'static, M: ManagedView> {
|
||||
pub struct MenuHandle<M: ManagedView> {
|
||||
id: ElementId,
|
||||
child_builder: Option<Box<dyn FnOnce(bool) -> AnyElement<V> + 'static>>,
|
||||
menu_builder: Option<Rc<dyn Fn(&mut V, &mut ViewContext<V>) -> View<M> + 'static>>,
|
||||
|
||||
child_builder: Option<Box<dyn FnOnce(bool) -> AnyElement + 'static>>,
|
||||
menu_builder: Option<Rc<dyn Fn(&mut WindowContext) -> View<M> + 'static>>,
|
||||
anchor: Option<AnchorCorner>,
|
||||
attach: Option<AnchorCorner>,
|
||||
}
|
||||
|
||||
impl<V: 'static, M: ManagedView> MenuHandle<V, M> {
|
||||
pub fn menu(mut self, f: impl Fn(&mut V, &mut ViewContext<V>) -> View<M> + 'static) -> Self {
|
||||
impl<M: ManagedView> MenuHandle<M> {
|
||||
pub fn menu(mut self, f: impl Fn(&mut WindowContext) -> View<M> + 'static) -> Self {
|
||||
self.menu_builder = Some(Rc::new(f));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn child<R: RenderOnce<V>>(mut self, f: impl FnOnce(bool) -> R + 'static) -> Self {
|
||||
pub fn child<R: RenderOnce>(mut self, f: impl FnOnce(bool) -> R + 'static) -> Self {
|
||||
self.child_builder = Some(Box::new(|b| f(b).render_once().into_any()));
|
||||
self
|
||||
}
|
||||
@@ -162,7 +159,7 @@ impl<V: 'static, M: ManagedView> MenuHandle<V, M> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn menu_handle<V: 'static, M: ManagedView>(id: impl Into<ElementId>) -> MenuHandle<V, M> {
|
||||
pub fn menu_handle<M: ManagedView>(id: impl Into<ElementId>) -> MenuHandle<M> {
|
||||
MenuHandle {
|
||||
id: id.into(),
|
||||
child_builder: None,
|
||||
@@ -172,21 +169,20 @@ pub fn menu_handle<V: 'static, M: ManagedView>(id: impl Into<ElementId>) -> Menu
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MenuHandleState<V, M> {
|
||||
pub struct MenuHandleState<M> {
|
||||
menu: Rc<RefCell<Option<View<M>>>>,
|
||||
position: Rc<RefCell<Point<Pixels>>>,
|
||||
child_layout_id: Option<LayoutId>,
|
||||
child_element: Option<AnyElement<V>>,
|
||||
menu_element: Option<AnyElement<V>>,
|
||||
child_element: Option<AnyElement>,
|
||||
menu_element: Option<AnyElement>,
|
||||
}
|
||||
impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
type State = MenuHandleState<V, M>;
|
||||
impl<M: ManagedView> Element for MenuHandle<M> {
|
||||
type State = MenuHandleState<M>;
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
view_state: &mut V,
|
||||
element_state: Option<Self::State>,
|
||||
cx: &mut crate::ViewContext<V>,
|
||||
cx: &mut WindowContext,
|
||||
) -> (gpui::LayoutId, Self::State) {
|
||||
let (menu, position) = if let Some(element_state) = element_state {
|
||||
(element_state.menu, element_state.position)
|
||||
@@ -197,14 +193,14 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
let mut menu_layout_id = None;
|
||||
|
||||
let menu_element = menu.borrow_mut().as_mut().map(|menu| {
|
||||
let mut overlay = overlay::<V>().snap_to_window();
|
||||
let mut overlay = overlay().snap_to_window();
|
||||
if let Some(anchor) = self.anchor {
|
||||
overlay = overlay.anchor(anchor);
|
||||
}
|
||||
overlay = overlay.position(*position.borrow());
|
||||
|
||||
let mut element = overlay.child(menu.clone()).into_any();
|
||||
menu_layout_id = Some(element.layout(view_state, cx));
|
||||
menu_layout_id = Some(element.layout(cx));
|
||||
element
|
||||
});
|
||||
|
||||
@@ -215,7 +211,7 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
|
||||
let child_layout_id = child_element
|
||||
.as_mut()
|
||||
.map(|child_element| child_element.layout(view_state, cx));
|
||||
.map(|child_element| child_element.layout(cx));
|
||||
|
||||
let layout_id = cx.request_layout(
|
||||
&gpui::Style::default(),
|
||||
@@ -237,16 +233,15 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
fn paint(
|
||||
self,
|
||||
bounds: Bounds<gpui::Pixels>,
|
||||
view_state: &mut V,
|
||||
element_state: &mut Self::State,
|
||||
cx: &mut crate::ViewContext<V>,
|
||||
cx: &mut WindowContext,
|
||||
) {
|
||||
if let Some(child) = element_state.child_element.take() {
|
||||
child.paint(view_state, cx);
|
||||
child.paint(cx);
|
||||
}
|
||||
|
||||
if let Some(menu) = element_state.menu_element.take() {
|
||||
menu.paint(view_state, cx);
|
||||
menu.paint(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -258,7 +253,7 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
let attach = self.attach.clone();
|
||||
let child_layout_id = element_state.child_layout_id.clone();
|
||||
|
||||
cx.on_mouse_event(move |view_state, event: &MouseDownEvent, phase, cx| {
|
||||
cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
|
||||
if phase == DispatchPhase::Bubble
|
||||
&& event.button == MouseButton::Right
|
||||
&& bounds.contains_point(&event.position)
|
||||
@@ -266,9 +261,9 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
cx.stop_propagation();
|
||||
cx.prevent_default();
|
||||
|
||||
let new_menu = (builder)(view_state, cx);
|
||||
let new_menu = (builder)(cx);
|
||||
let menu2 = menu.clone();
|
||||
cx.subscribe(&new_menu, move |this, modal, e, cx| match e {
|
||||
cx.subscribe(&new_menu, move |modal, e, cx| match e {
|
||||
&Manager::Dismiss => {
|
||||
*menu2.borrow_mut() = None;
|
||||
cx.notify();
|
||||
@@ -291,7 +286,7 @@ impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static, M: ManagedView> RenderOnce<V> for MenuHandle<V, M> {
|
||||
impl<M: ManagedView> RenderOnce for MenuHandle<M> {
|
||||
type Element = Self;
|
||||
|
||||
fn element_id(&self) -> Option<gpui::ElementId> {
|
||||
@@ -314,11 +309,10 @@ mod stories {
|
||||
|
||||
actions!(PrintCurrentDate, PrintBestFood);
|
||||
|
||||
fn build_menu<V: Render<V>>(
|
||||
cx: &mut ViewContext<V>,
|
||||
fn build_menu<V: Render>(
|
||||
cx: &mut WindowContext,
|
||||
header: impl Into<SharedString>,
|
||||
) -> View<ContextMenu<V>> {
|
||||
let handle = cx.view().clone();
|
||||
) -> View<ContextMenu> {
|
||||
ContextMenu::build(cx, |menu, _| {
|
||||
menu.header(header)
|
||||
.separator()
|
||||
@@ -334,8 +328,8 @@ mod stories {
|
||||
|
||||
pub struct ContextMenuStory;
|
||||
|
||||
impl Render<Self> for ContextMenuStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ContextMenuStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -2,16 +2,16 @@ use crate::prelude::*;
|
||||
use crate::{v_stack, ButtonGroup};
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Details<V: 'static> {
|
||||
pub struct Details {
|
||||
text: &'static str,
|
||||
meta: Option<&'static str>,
|
||||
actions: Option<ButtonGroup<V>>,
|
||||
actions: Option<ButtonGroup>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Details<V> {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Details {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
v_stack()
|
||||
.p_1()
|
||||
.gap_0p5()
|
||||
@@ -24,7 +24,7 @@ impl<V: 'static> Component<V> for Details<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Details<V> {
|
||||
impl Details {
|
||||
pub fn new(text: &'static str) -> Self {
|
||||
Self {
|
||||
text,
|
||||
@@ -38,7 +38,7 @@ impl<V: 'static> Details<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn actions(mut self, actions: ButtonGroup<V>) -> Self {
|
||||
pub fn actions(mut self, actions: ButtonGroup) -> Self {
|
||||
self.actions = Some(actions);
|
||||
self
|
||||
}
|
||||
@@ -56,8 +56,8 @@ mod stories {
|
||||
|
||||
pub struct DetailsStory;
|
||||
|
||||
impl Render<Self> for DetailsStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for DetailsStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -13,10 +13,10 @@ pub struct Divider {
|
||||
inset: bool,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Divider {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Divider {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.map(|this| match self.direction {
|
||||
DividerDirection::Horizontal => {
|
||||
@@ -50,7 +50,7 @@ impl Divider {
|
||||
self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
div()
|
||||
.map(|this| match self.direction {
|
||||
DividerDirection::Horizontal => {
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{prelude::*, v_stack};
|
||||
/// Create an elevated surface.
|
||||
///
|
||||
/// Must be used inside of a relative parent element
|
||||
pub fn elevated_surface<V: 'static>(level: ElevationIndex, cx: &mut ViewContext<V>) -> Div<V> {
|
||||
pub fn elevated_surface(level: ElevationIndex, cx: &mut WindowContext) -> Div {
|
||||
let colors = cx.theme().colors();
|
||||
|
||||
// let shadow = BoxShadow {
|
||||
@@ -23,6 +23,6 @@ pub fn elevated_surface<V: 'static>(level: ElevationIndex, cx: &mut ViewContext<
|
||||
.shadow(level.shadow())
|
||||
}
|
||||
|
||||
pub fn modal<V: 'static>(cx: &mut ViewContext<V>) -> Div<V> {
|
||||
pub fn modal(cx: &mut WindowContext) -> Div {
|
||||
elevated_surface(ElevationIndex::ModalSurface, cx)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ pub struct Facepile {
|
||||
players: Vec<Player>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Facepile {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Facepile {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let player_count = self.players.len();
|
||||
let player_list = self.players.iter().enumerate().map(|(ix, player)| {
|
||||
let isnt_last = ix < player_count - 1;
|
||||
@@ -42,8 +42,8 @@ mod stories {
|
||||
|
||||
pub struct FacepileStory;
|
||||
|
||||
impl Render<Self> for FacepileStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for FacepileStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let players = static_players();
|
||||
|
||||
@@ -136,10 +136,10 @@ pub struct IconElement {
|
||||
size: IconSize,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for IconElement {
|
||||
type Rendered = Svg<V>;
|
||||
impl Component for IconElement {
|
||||
type Rendered = Svg;
|
||||
|
||||
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let svg_size = match self.size {
|
||||
IconSize::Small => rems(0.75),
|
||||
IconSize::Medium => rems(0.9375),
|
||||
@@ -180,7 +180,7 @@ impl IconElement {
|
||||
self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let svg_size = match self.size {
|
||||
IconSize::Small => rems(0.75),
|
||||
IconSize::Medium => rems(0.9375),
|
||||
@@ -208,8 +208,8 @@ mod stories {
|
||||
|
||||
pub struct IconStory;
|
||||
|
||||
impl Render<Self> for IconStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for IconStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let icons = Icon::iter();
|
||||
|
||||
@@ -1,33 +1,22 @@
|
||||
use crate::{h_stack, prelude::*, ClickHandler, Icon, IconElement};
|
||||
use gpui::{prelude::*, Action, AnyView, Div, MouseButton, Stateful};
|
||||
use std::sync::Arc;
|
||||
|
||||
struct IconButtonHandlers<V: 'static> {
|
||||
click: Option<ClickHandler<V>>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Default for IconButtonHandlers<V> {
|
||||
fn default() -> Self {
|
||||
Self { click: None }
|
||||
}
|
||||
}
|
||||
use crate::{h_stack, prelude::*, Icon, IconElement};
|
||||
use gpui::{prelude::*, Action, AnyView, Div, MouseButton, MouseDownEvent, Stateful};
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct IconButton<V: 'static> {
|
||||
pub struct IconButton {
|
||||
id: ElementId,
|
||||
icon: Icon,
|
||||
color: TextColor,
|
||||
variant: ButtonVariant,
|
||||
state: InteractionState,
|
||||
selected: bool,
|
||||
tooltip: Option<Box<dyn Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static>>,
|
||||
handlers: IconButtonHandlers<V>,
|
||||
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
||||
on_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for IconButton<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for IconButton {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let icon_color = match (self.state, self.color) {
|
||||
(InteractionState::Disabled, _) => TextColor::Disabled,
|
||||
(InteractionState::Active, _) => TextColor::Selected,
|
||||
@@ -65,16 +54,16 @@ impl<V: 'static> Component<V> for IconButton<V> {
|
||||
.active(|style| style.bg(bg_active_color))
|
||||
.child(IconElement::new(self.icon).color(icon_color));
|
||||
|
||||
if let Some(click_handler) = self.handlers.click.clone() {
|
||||
button = button.on_mouse_down(MouseButton::Left, move |state, event, cx| {
|
||||
if let Some(click_handler) = self.on_mouse_down {
|
||||
button = button.on_mouse_down(MouseButton::Left, move |event, cx| {
|
||||
cx.stop_propagation();
|
||||
click_handler(state, cx);
|
||||
click_handler(event, cx);
|
||||
})
|
||||
}
|
||||
|
||||
if let Some(tooltip) = self.tooltip {
|
||||
if !self.selected {
|
||||
button = button.tooltip(move |view: &mut V, cx| (tooltip)(view, cx))
|
||||
button = button.tooltip(move |cx| tooltip(cx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +71,7 @@ impl<V: 'static> Component<V> for IconButton<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> IconButton<V> {
|
||||
impl IconButton {
|
||||
pub fn new(id: impl Into<ElementId>, icon: Icon) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
@@ -92,7 +81,7 @@ impl<V: 'static> IconButton<V> {
|
||||
state: InteractionState::default(),
|
||||
selected: false,
|
||||
tooltip: None,
|
||||
handlers: IconButtonHandlers::default(),
|
||||
on_mouse_down: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,16 +110,16 @@ impl<V: 'static> IconButton<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tooltip(
|
||||
mut self,
|
||||
tooltip: impl Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static,
|
||||
) -> Self {
|
||||
pub fn tooltip(mut self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self {
|
||||
self.tooltip = Some(Box::new(tooltip));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_click(mut self, handler: impl 'static + Fn(&mut V, &mut ViewContext<V>)) -> Self {
|
||||
self.handlers.click = Some(Arc::new(handler));
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl 'static + Fn(&MouseDownEvent, &mut WindowContext),
|
||||
) -> Self {
|
||||
self.on_mouse_down = Some(Box::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ use gpui::{px, Div, RenderOnce};
|
||||
#[derive(RenderOnce)]
|
||||
pub struct UnreadIndicator;
|
||||
|
||||
impl<V: 'static> Component<V> for UnreadIndicator {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for UnreadIndicator {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.rounded_full()
|
||||
.border_2()
|
||||
@@ -24,7 +24,7 @@ impl UnreadIndicator {
|
||||
Self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
div()
|
||||
.rounded_full()
|
||||
.border_2()
|
||||
|
||||
@@ -18,10 +18,10 @@ pub struct Input {
|
||||
is_active: bool,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Input {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Input {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let (input_bg, input_hover_bg, input_active_bg) = match self.variant {
|
||||
InputVariant::Ghost => (
|
||||
cx.theme().colors().ghost_element_background,
|
||||
@@ -118,8 +118,8 @@ mod stories {
|
||||
|
||||
pub struct InputStory;
|
||||
|
||||
impl Render<Self> for InputStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for InputStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -10,10 +10,10 @@ pub struct KeyBinding {
|
||||
key_binding: gpui::KeyBinding,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for KeyBinding {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for KeyBinding {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.flex()
|
||||
.gap_2()
|
||||
@@ -49,11 +49,10 @@ pub struct Key {
|
||||
key: SharedString,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Key {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Key {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
let _view: &mut V = view;
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.px_2()
|
||||
.py_0()
|
||||
@@ -89,8 +88,8 @@ mod stories {
|
||||
gpui::KeyBinding::new(key, NoAction {}, None)
|
||||
}
|
||||
|
||||
impl Render<Self> for KeybindingStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for KeybindingStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let all_modifier_permutations =
|
||||
|
||||
@@ -68,10 +68,10 @@ pub struct Label {
|
||||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Label {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Label {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.when(self.strikethrough, |this| {
|
||||
this.relative().child(
|
||||
@@ -136,10 +136,10 @@ pub struct HighlightedLabel {
|
||||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for HighlightedLabel {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for HighlightedLabel {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let highlight_color = cx.theme().colors().text_accent;
|
||||
let mut text_style = cx.text_style().clone();
|
||||
|
||||
@@ -242,8 +242,8 @@ mod stories {
|
||||
|
||||
pub struct LabelStory;
|
||||
|
||||
impl Render<Self> for LabelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for LabelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use gpui::{div, Div, RenderOnce, Stateful, StatefulInteractiveElement};
|
||||
use gpui::{div, ClickEvent, Div, RenderOnce, Stateful, StatefulInteractiveElement};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::settings::user_settings;
|
||||
@@ -32,10 +32,10 @@ pub struct ListHeader {
|
||||
toggle: Toggle,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ListHeader {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for ListHeader {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let disclosure_control = disclosure_control(self.toggle);
|
||||
|
||||
let meta = match self.meta {
|
||||
@@ -198,7 +198,7 @@ impl ListSubHeader {
|
||||
self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
h_stack().flex_1().w_full().relative().py_1().child(
|
||||
div()
|
||||
.h_6()
|
||||
@@ -233,36 +233,36 @@ pub enum ListEntrySize {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ListItem<V: 'static> {
|
||||
Entry(ListEntry<V>),
|
||||
pub enum ListItem {
|
||||
Entry(ListEntry),
|
||||
Separator(ListSeparator),
|
||||
Header(ListSubHeader),
|
||||
}
|
||||
|
||||
impl<V: 'static> From<ListEntry<V>> for ListItem<V> {
|
||||
fn from(entry: ListEntry<V>) -> Self {
|
||||
impl From<ListEntry> for ListItem {
|
||||
fn from(entry: ListEntry) -> Self {
|
||||
Self::Entry(entry)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> From<ListSeparator> for ListItem<V> {
|
||||
impl From<ListSeparator> for ListItem {
|
||||
fn from(entry: ListSeparator) -> Self {
|
||||
Self::Separator(entry)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> From<ListSubHeader> for ListItem<V> {
|
||||
impl From<ListSubHeader> for ListItem {
|
||||
fn from(entry: ListSubHeader) -> Self {
|
||||
Self::Header(entry)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ListItem<V> {
|
||||
impl ListItem {
|
||||
pub fn new(label: Label) -> Self {
|
||||
Self::Entry(ListEntry::new(label))
|
||||
}
|
||||
|
||||
pub fn as_entry(&mut self) -> Option<&mut ListEntry<V>> {
|
||||
pub fn as_entry(&mut self) -> Option<&mut ListEntry> {
|
||||
if let Self::Entry(entry) = self {
|
||||
Some(entry)
|
||||
} else {
|
||||
@@ -270,17 +270,17 @@ impl<V: 'static> ListItem<V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render(self, view: &mut V, ix: usize, cx: &mut ViewContext<V>) -> Div<V> {
|
||||
fn render(self, ix: usize, cx: &mut WindowContext) -> Div {
|
||||
match self {
|
||||
ListItem::Entry(entry) => div().child(entry.render(ix, cx)),
|
||||
ListItem::Separator(separator) => div().child(separator.render(view, cx)),
|
||||
ListItem::Header(header) => div().child(header.render(view, cx)),
|
||||
ListItem::Separator(separator) => div().child(separator.render(cx)),
|
||||
ListItem::Header(header) => div().child(header.render(cx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(RenderOnce)]
|
||||
pub struct ListEntry<V> {
|
||||
pub struct ListEntry {
|
||||
disabled: bool,
|
||||
// TODO: Reintroduce this
|
||||
// disclosure_control_style: DisclosureControlVisibility,
|
||||
@@ -291,10 +291,10 @@ pub struct ListEntry<V> {
|
||||
size: ListEntrySize,
|
||||
toggle: Toggle,
|
||||
variant: ListItemVariant,
|
||||
on_click: Option<Rc<dyn Fn(&mut V, &mut ViewContext<V>) + 'static>>,
|
||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
impl<V> Clone for ListEntry<V> {
|
||||
impl Clone for ListEntry {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
disabled: self.disabled,
|
||||
@@ -310,7 +310,7 @@ impl<V> Clone for ListEntry<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ListEntry<V> {
|
||||
impl ListEntry {
|
||||
pub fn new(label: Label) -> Self {
|
||||
Self {
|
||||
disabled: false,
|
||||
@@ -325,7 +325,7 @@ impl<V: 'static> ListEntry<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_click(mut self, handler: impl Fn(&mut V, &mut ViewContext<V>) + 'static) -> Self {
|
||||
pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
||||
self.on_click = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
@@ -365,7 +365,7 @@ impl<V: 'static> ListEntry<V> {
|
||||
self
|
||||
}
|
||||
|
||||
fn render(self, ix: usize, cx: &mut ViewContext<V>) -> Stateful<V, Div<V>> {
|
||||
fn render(self, ix: usize, cx: &mut WindowContext) -> Stateful<Div> {
|
||||
let settings = user_settings(cx);
|
||||
|
||||
let left_content = match self.left_slot.clone() {
|
||||
@@ -392,13 +392,11 @@ impl<V: 'static> ListEntry<V> {
|
||||
style.background = Some(cx.theme().colors().editor_background.into());
|
||||
style
|
||||
})
|
||||
.on_click({
|
||||
let on_click = self.on_click.clone();
|
||||
|
||||
move |view: &mut V, event, cx| {
|
||||
if let Some(on_click) = &on_click {
|
||||
(on_click)(view, cx)
|
||||
}
|
||||
.map(|div| {
|
||||
if let Some(on_click) = self.on_click.clone() {
|
||||
div.on_click(move |e, cx| on_click(e, cx))
|
||||
} else {
|
||||
div
|
||||
}
|
||||
})
|
||||
.bg(cx.theme().colors().surface_background)
|
||||
@@ -444,17 +442,17 @@ impl ListSeparator {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ListSeparator {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for ListSeparator {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().h_px().w_full().bg(cx.theme().colors().border_variant)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct List<V: 'static> {
|
||||
items: Vec<ListItem<V>>,
|
||||
pub struct List {
|
||||
items: Vec<ListItem>,
|
||||
/// Message to display when the list is empty
|
||||
/// Defaults to "No items"
|
||||
empty_message: SharedString,
|
||||
@@ -462,16 +460,16 @@ pub struct List<V: 'static> {
|
||||
toggle: Toggle,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for List<V> {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for List {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let list_content = match (self.items.is_empty(), self.toggle) {
|
||||
(false, _) => div().children(
|
||||
self.items
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(ix, item)| item.render(view, ix, cx)),
|
||||
.map(|(ix, item)| item.render(ix, cx)),
|
||||
),
|
||||
(true, Toggle::Toggled(false)) => div(),
|
||||
(true, _) => {
|
||||
@@ -487,8 +485,8 @@ impl<V: 'static> Component<V> for List<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> List<V> {
|
||||
pub fn new(items: Vec<ListItem<V>>) -> Self {
|
||||
impl List {
|
||||
pub fn new(items: Vec<ListItem>) -> Self {
|
||||
Self {
|
||||
items,
|
||||
empty_message: "No items".into(),
|
||||
@@ -512,13 +510,13 @@ impl<V: 'static> List<V> {
|
||||
self
|
||||
}
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let list_content = match (self.items.is_empty(), self.toggle) {
|
||||
(false, _) => div().children(
|
||||
self.items
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(ix, item)| item.render(view, ix, cx)),
|
||||
.map(|(ix, item)| item.render(ix, cx)),
|
||||
),
|
||||
(true, Toggle::Toggled(false)) => div(),
|
||||
(true, _) => {
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
use gpui::{AnyElement, Div, RenderOnce, Stateful};
|
||||
use gpui::{AnyElement, Div, RenderOnce};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label};
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Modal<V: 'static> {
|
||||
pub struct Modal {
|
||||
id: ElementId,
|
||||
title: Option<SharedString>,
|
||||
primary_action: Option<Button<V>>,
|
||||
secondary_action: Option<Button<V>>,
|
||||
children: SmallVec<[AnyElement<V>; 2]>,
|
||||
primary_action: Option<Button>,
|
||||
secondary_action: Option<Button>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Modal<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Modal {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
let _view: &mut V = view;
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
v_stack()
|
||||
.id(self.id.clone())
|
||||
.w_96()
|
||||
@@ -52,7 +51,7 @@ impl<V: 'static> Component<V> for Modal<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Modal<V> {
|
||||
impl Modal {
|
||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
@@ -68,19 +67,19 @@ impl<V: 'static> Modal<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn primary_action(mut self, action: Button<V>) -> Self {
|
||||
pub fn primary_action(mut self, action: Button) -> Self {
|
||||
self.primary_action = Some(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn secondary_action(mut self, action: Button<V>) -> Self {
|
||||
pub fn secondary_action(mut self, action: Button) -> Self {
|
||||
self.secondary_action = Some(action);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ParentElement<V> for Modal<V> {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
|
||||
impl ParentElement for Modal {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
||||
&mut self.children
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl NotificationToast {
|
||||
self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
h_stack()
|
||||
.z_index(5)
|
||||
.absolute()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{h_stack, prelude::*, v_stack, KeyBinding, Label};
|
||||
use gpui::prelude::*;
|
||||
use gpui::Div;
|
||||
use gpui::Stateful;
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Palette {
|
||||
@@ -12,10 +11,10 @@ pub struct Palette {
|
||||
default_order: OrderMethod,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Palette {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Palette {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
v_stack()
|
||||
.id(self.id)
|
||||
.w_96()
|
||||
@@ -116,10 +115,10 @@ pub struct PaletteItem {
|
||||
pub key_binding: Option<KeyBinding>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for PaletteItem {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for PaletteItem {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.flex()
|
||||
.flex_row()
|
||||
@@ -173,8 +172,8 @@ mod stories {
|
||||
|
||||
pub struct PaletteStory;
|
||||
|
||||
impl Render<Self> for PaletteStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for PaletteStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use gpui::{prelude::*, AbsoluteLength, AnyElement, Div, RenderOnce, Stateful};
|
||||
use gpui::{prelude::*, AbsoluteLength, AnyElement, Div, RenderOnce};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::prelude::*;
|
||||
@@ -39,20 +39,20 @@ pub enum PanelSide {
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Panel<V: 'static> {
|
||||
pub struct Panel {
|
||||
id: ElementId,
|
||||
current_side: PanelSide,
|
||||
/// Defaults to PanelAllowedSides::LeftAndRight
|
||||
allowed_sides: PanelAllowedSides,
|
||||
initial_width: AbsoluteLength,
|
||||
width: Option<AbsoluteLength>,
|
||||
children: SmallVec<[AnyElement<V>; 2]>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Panel<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Panel {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let current_size = self.width.unwrap_or(self.initial_width);
|
||||
|
||||
v_stack()
|
||||
@@ -73,7 +73,7 @@ impl<V: 'static> Component<V> for Panel<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Panel<V> {
|
||||
impl Panel {
|
||||
pub fn new(id: impl Into<ElementId>, cx: &mut WindowContext) -> Self {
|
||||
let settings = user_settings(cx);
|
||||
|
||||
@@ -117,8 +117,8 @@ impl<V: 'static> Panel<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ParentElement<V> for Panel<V> {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
|
||||
impl ParentElement for Panel {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
||||
&mut self.children
|
||||
}
|
||||
}
|
||||
@@ -134,12 +134,12 @@ mod stories {
|
||||
|
||||
pub struct PanelStory;
|
||||
|
||||
impl Render<Self> for PanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for PanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Panel<Self>>(cx))
|
||||
.child(Story::title_for::<Panel<Self>>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(
|
||||
Panel::new("panel", cx).child(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use gpui::{Hsla, ViewContext};
|
||||
use gpui::Hsla;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
@@ -156,11 +156,11 @@ impl Player {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cursor_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
|
||||
pub fn cursor_color(&self, cx: &mut WindowContext) -> Hsla {
|
||||
cx.theme().styles.player.0[self.index % cx.theme().styles.player.0.len()].cursor
|
||||
}
|
||||
|
||||
pub fn selection_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
|
||||
pub fn selection_color(&self, cx: &mut WindowContext) -> Hsla {
|
||||
cx.theme().styles.player.0[self.index % cx.theme().styles.player.0.len()].selection
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ pub struct PlayerStack {
|
||||
player_with_call_status: PlayerWithCallStatus,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for PlayerStack {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for PlayerStack {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let player = self.player_with_call_status.get_player();
|
||||
|
||||
let followers = self
|
||||
|
||||
@@ -5,13 +5,13 @@ use crate::StyledExt;
|
||||
/// Horizontally stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_row()`, `items_center()`
|
||||
pub fn h_stack<V: 'static>() -> Div<V> {
|
||||
pub fn h_stack() -> Div {
|
||||
div().h_flex()
|
||||
}
|
||||
|
||||
/// Vertically stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_col()`
|
||||
pub fn v_stack<V: 'static>() -> Div<V> {
|
||||
pub fn v_stack() -> Div {
|
||||
div().v_flex()
|
||||
}
|
||||
|
||||
+250
-250
@@ -1,276 +1,276 @@
|
||||
use crate::prelude::*;
|
||||
use crate::{Icon, IconElement, Label, TextColor};
|
||||
use gpui::{prelude::*, red, Div, ElementId, Render, RenderOnce, Stateful, View};
|
||||
// use crate::prelude::*;
|
||||
// use crate::{Icon, IconElement, Label, TextColor};
|
||||
// use gpui::{prelude::*, red, Div, ElementId, Render, RenderOnce, View};
|
||||
|
||||
#[derive(RenderOnce, Clone)]
|
||||
pub struct Tab {
|
||||
id: ElementId,
|
||||
title: String,
|
||||
icon: Option<Icon>,
|
||||
current: bool,
|
||||
dirty: bool,
|
||||
fs_status: FileSystemStatus,
|
||||
git_status: GitStatus,
|
||||
diagnostic_status: DiagnosticStatus,
|
||||
close_side: IconSide,
|
||||
}
|
||||
// #[derive(RenderOnce, Clone)]
|
||||
// pub struct Tab {
|
||||
// id: ElementId,
|
||||
// title: String,
|
||||
// icon: Option<Icon>,
|
||||
// current: bool,
|
||||
// dirty: bool,
|
||||
// fs_status: FileSystemStatus,
|
||||
// git_status: GitStatus,
|
||||
// diagnostic_status: DiagnosticStatus,
|
||||
// close_side: IconSide,
|
||||
// }
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct TabDragState {
|
||||
title: String,
|
||||
}
|
||||
// #[derive(Clone, Debug)]
|
||||
// struct TabDragState {
|
||||
// title: String,
|
||||
// }
|
||||
|
||||
impl Render<Self> for TabDragState {
|
||||
type Element = Div<Self>;
|
||||
// impl Render for TabDragState {
|
||||
// type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
div().w_8().h_4().bg(red())
|
||||
}
|
||||
}
|
||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
// div().w_8().h_4().bg(red())
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<V: 'static> Component<V> for Tab {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
// impl Component for Tab {
|
||||
// type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict;
|
||||
let is_deleted = self.fs_status == FileSystemStatus::Deleted;
|
||||
// fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
// let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict;
|
||||
// let is_deleted = self.fs_status == FileSystemStatus::Deleted;
|
||||
|
||||
let label = match (self.git_status, is_deleted) {
|
||||
(_, true) | (GitStatus::Deleted, false) => Label::new(self.title.clone())
|
||||
.color(TextColor::Hidden)
|
||||
.set_strikethrough(true),
|
||||
(GitStatus::None, false) => Label::new(self.title.clone()),
|
||||
(GitStatus::Created, false) => Label::new(self.title.clone()).color(TextColor::Created),
|
||||
(GitStatus::Modified, false) => {
|
||||
Label::new(self.title.clone()).color(TextColor::Modified)
|
||||
}
|
||||
(GitStatus::Renamed, false) => Label::new(self.title.clone()).color(TextColor::Accent),
|
||||
(GitStatus::Conflict, false) => Label::new(self.title.clone()),
|
||||
};
|
||||
// let label = match (self.git_status, is_deleted) {
|
||||
// (_, true) | (GitStatus::Deleted, false) => Label::new(self.title.clone())
|
||||
// .color(TextColor::Hidden)
|
||||
// .set_strikethrough(true),
|
||||
// (GitStatus::None, false) => Label::new(self.title.clone()),
|
||||
// (GitStatus::Created, false) => Label::new(self.title.clone()).color(TextColor::Created),
|
||||
// (GitStatus::Modified, false) => {
|
||||
// Label::new(self.title.clone()).color(TextColor::Modified)
|
||||
// }
|
||||
// (GitStatus::Renamed, false) => Label::new(self.title.clone()).color(TextColor::Accent),
|
||||
// (GitStatus::Conflict, false) => Label::new(self.title.clone()),
|
||||
// };
|
||||
|
||||
let close_icon = || IconElement::new(Icon::Close).color(TextColor::Muted);
|
||||
// let close_icon = || IconElement::new(Icon::Close).color(TextColor::Muted);
|
||||
|
||||
let (tab_bg, tab_hover_bg, tab_active_bg) = match self.current {
|
||||
false => (
|
||||
cx.theme().colors().tab_inactive_background,
|
||||
cx.theme().colors().ghost_element_hover,
|
||||
cx.theme().colors().ghost_element_active,
|
||||
),
|
||||
true => (
|
||||
cx.theme().colors().tab_active_background,
|
||||
cx.theme().colors().element_hover,
|
||||
cx.theme().colors().element_active,
|
||||
),
|
||||
};
|
||||
// let (tab_bg, tab_hover_bg, tab_active_bg) = match self.current {
|
||||
// false => (
|
||||
// cx.theme().colors().tab_inactive_background,
|
||||
// cx.theme().colors().ghost_element_hover,
|
||||
// cx.theme().colors().ghost_element_active,
|
||||
// ),
|
||||
// true => (
|
||||
// cx.theme().colors().tab_active_background,
|
||||
// cx.theme().colors().element_hover,
|
||||
// cx.theme().colors().element_active,
|
||||
// ),
|
||||
// };
|
||||
|
||||
let drag_state = TabDragState {
|
||||
title: self.title.clone(),
|
||||
};
|
||||
// let drag_state = TabDragState {
|
||||
// title: self.title.clone(),
|
||||
// };
|
||||
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone()))
|
||||
.drag_over::<TabDragState>(|d| d.bg(cx.theme().colors().drop_target_background))
|
||||
.on_drop(|_view, state: View<TabDragState>, cx| {
|
||||
eprintln!("{:?}", state.read(cx));
|
||||
})
|
||||
.px_2()
|
||||
.py_0p5()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.bg(tab_bg)
|
||||
.hover(|h| h.bg(tab_hover_bg))
|
||||
.active(|a| a.bg(tab_active_bg))
|
||||
.child(
|
||||
div()
|
||||
.px_1()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_1p5()
|
||||
.children(has_fs_conflict.then(|| {
|
||||
IconElement::new(Icon::ExclamationTriangle)
|
||||
.size(crate::IconSize::Small)
|
||||
.color(TextColor::Warning)
|
||||
}))
|
||||
.children(self.icon.map(IconElement::new))
|
||||
.children(if self.close_side == IconSide::Left {
|
||||
Some(close_icon())
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.child(label)
|
||||
.children(if self.close_side == IconSide::Right {
|
||||
Some(close_icon())
|
||||
} else {
|
||||
None
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
// div()
|
||||
// .id(self.id.clone())
|
||||
// .on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone()))
|
||||
// .drag_over::<TabDragState>(|d| d.bg(cx.theme().colors().drop_target_background))
|
||||
// .on_drop(|_view, state: View<TabDragState>, cx| {
|
||||
// eprintln!("{:?}", state.read(cx));
|
||||
// })
|
||||
// .px_2()
|
||||
// .py_0p5()
|
||||
// .flex()
|
||||
// .items_center()
|
||||
// .justify_center()
|
||||
// .bg(tab_bg)
|
||||
// .hover(|h| h.bg(tab_hover_bg))
|
||||
// .active(|a| a.bg(tab_active_bg))
|
||||
// .child(
|
||||
// div()
|
||||
// .px_1()
|
||||
// .flex()
|
||||
// .items_center()
|
||||
// .gap_1p5()
|
||||
// .children(has_fs_conflict.then(|| {
|
||||
// IconElement::new(Icon::ExclamationTriangle)
|
||||
// .size(crate::IconSize::Small)
|
||||
// .color(TextColor::Warning)
|
||||
// }))
|
||||
// .children(self.icon.map(IconElement::new))
|
||||
// .children(if self.close_side == IconSide::Left {
|
||||
// Some(close_icon())
|
||||
// } else {
|
||||
// None
|
||||
// })
|
||||
// .child(label)
|
||||
// .children(if self.close_side == IconSide::Right {
|
||||
// Some(close_icon())
|
||||
// } else {
|
||||
// None
|
||||
// }),
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Tab {
|
||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
title: "untitled".to_string(),
|
||||
icon: None,
|
||||
current: false,
|
||||
dirty: false,
|
||||
fs_status: FileSystemStatus::None,
|
||||
git_status: GitStatus::None,
|
||||
diagnostic_status: DiagnosticStatus::None,
|
||||
close_side: IconSide::Right,
|
||||
}
|
||||
}
|
||||
// impl Tab {
|
||||
// pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
// Self {
|
||||
// id: id.into(),
|
||||
// title: "untitled".to_string(),
|
||||
// icon: None,
|
||||
// current: false,
|
||||
// dirty: false,
|
||||
// fs_status: FileSystemStatus::None,
|
||||
// git_status: GitStatus::None,
|
||||
// diagnostic_status: DiagnosticStatus::None,
|
||||
// close_side: IconSide::Right,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn current(mut self, current: bool) -> Self {
|
||||
self.current = current;
|
||||
self
|
||||
}
|
||||
// pub fn current(mut self, current: bool) -> Self {
|
||||
// self.current = current;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn title(mut self, title: String) -> Self {
|
||||
self.title = title;
|
||||
self
|
||||
}
|
||||
// pub fn title(mut self, title: String) -> Self {
|
||||
// self.title = title;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn icon<I>(mut self, icon: I) -> Self
|
||||
where
|
||||
I: Into<Option<Icon>>,
|
||||
{
|
||||
self.icon = icon.into();
|
||||
self
|
||||
}
|
||||
// pub fn icon<I>(mut self, icon: I) -> Self
|
||||
// where
|
||||
// I: Into<Option<Icon>>,
|
||||
// {
|
||||
// self.icon = icon.into();
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn dirty(mut self, dirty: bool) -> Self {
|
||||
self.dirty = dirty;
|
||||
self
|
||||
}
|
||||
// pub fn dirty(mut self, dirty: bool) -> Self {
|
||||
// self.dirty = dirty;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn fs_status(mut self, fs_status: FileSystemStatus) -> Self {
|
||||
self.fs_status = fs_status;
|
||||
self
|
||||
}
|
||||
// pub fn fs_status(mut self, fs_status: FileSystemStatus) -> Self {
|
||||
// self.fs_status = fs_status;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn git_status(mut self, git_status: GitStatus) -> Self {
|
||||
self.git_status = git_status;
|
||||
self
|
||||
}
|
||||
// pub fn git_status(mut self, git_status: GitStatus) -> Self {
|
||||
// self.git_status = git_status;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn diagnostic_status(mut self, diagnostic_status: DiagnosticStatus) -> Self {
|
||||
self.diagnostic_status = diagnostic_status;
|
||||
self
|
||||
}
|
||||
// pub fn diagnostic_status(mut self, diagnostic_status: DiagnosticStatus) -> Self {
|
||||
// self.diagnostic_status = diagnostic_status;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn close_side(mut self, close_side: IconSide) -> Self {
|
||||
self.close_side = close_side;
|
||||
self
|
||||
}
|
||||
}
|
||||
// pub fn close_side(mut self, close_side: IconSide) -> Self {
|
||||
// self.close_side = close_side;
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
pub use stories::*;
|
||||
// #[cfg(feature = "stories")]
|
||||
// pub use stories::*;
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
mod stories {
|
||||
use super::*;
|
||||
use crate::{h_stack, v_stack, Icon, Story};
|
||||
use strum::IntoEnumIterator;
|
||||
// #[cfg(feature = "stories")]
|
||||
// mod stories {
|
||||
// use super::*;
|
||||
// use crate::{h_stack, v_stack, Icon, Story};
|
||||
// use strum::IntoEnumIterator;
|
||||
|
||||
pub struct TabStory;
|
||||
// pub struct TabStory;
|
||||
|
||||
impl Render<Self> for TabStory {
|
||||
type Element = Div<Self>;
|
||||
// impl Render for TabStory {
|
||||
// type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let git_statuses = GitStatus::iter();
|
||||
let fs_statuses = FileSystemStatus::iter();
|
||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
// let git_statuses = GitStatus::iter();
|
||||
// let fs_statuses = FileSystemStatus::iter();
|
||||
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Tab>(cx))
|
||||
.child(
|
||||
h_stack().child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Tab::new("default")),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_stack().child(
|
||||
v_stack().gap_2().child(Story::label(cx, "Current")).child(
|
||||
h_stack()
|
||||
.gap_4()
|
||||
.child(
|
||||
Tab::new("current")
|
||||
.title("Current".to_string())
|
||||
.current(true),
|
||||
)
|
||||
.child(
|
||||
Tab::new("not_current")
|
||||
.title("Not Current".to_string())
|
||||
.current(false),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_stack().child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "Titled"))
|
||||
.child(Tab::new("titled").title("label".to_string())),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_stack().child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "With Icon"))
|
||||
.child(
|
||||
Tab::new("with_icon")
|
||||
.title("label".to_string())
|
||||
.icon(Some(Icon::Envelope)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_stack().child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "Close Side"))
|
||||
.child(
|
||||
h_stack()
|
||||
.gap_4()
|
||||
.child(
|
||||
Tab::new("left")
|
||||
.title("Left".to_string())
|
||||
.close_side(IconSide::Left),
|
||||
)
|
||||
.child(Tab::new("right").title("Right".to_string())),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "Git Status"))
|
||||
.child(h_stack().gap_4().children(git_statuses.map(|git_status| {
|
||||
Tab::new("git_status")
|
||||
.title(git_status.to_string())
|
||||
.git_status(git_status)
|
||||
}))),
|
||||
)
|
||||
.child(
|
||||
v_stack()
|
||||
.gap_2()
|
||||
.child(Story::label(cx, "File System Status"))
|
||||
.child(h_stack().gap_4().children(fs_statuses.map(|fs_status| {
|
||||
Tab::new("file_system_status")
|
||||
.title(fs_status.to_string())
|
||||
.fs_status(fs_status)
|
||||
}))),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Story::container(cx)
|
||||
// .child(Story::title_for::<_, Tab>(cx))
|
||||
// .child(
|
||||
// h_stack().child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "Default"))
|
||||
// .child(Tab::new("default")),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// h_stack().child(
|
||||
// v_stack().gap_2().child(Story::label(cx, "Current")).child(
|
||||
// h_stack()
|
||||
// .gap_4()
|
||||
// .child(
|
||||
// Tab::new("current")
|
||||
// .title("Current".to_string())
|
||||
// .current(true),
|
||||
// )
|
||||
// .child(
|
||||
// Tab::new("not_current")
|
||||
// .title("Not Current".to_string())
|
||||
// .current(false),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// h_stack().child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "Titled"))
|
||||
// .child(Tab::new("titled").title("label".to_string())),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// h_stack().child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "With Icon"))
|
||||
// .child(
|
||||
// Tab::new("with_icon")
|
||||
// .title("label".to_string())
|
||||
// .icon(Some(Icon::Envelope)),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// h_stack().child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "Close Side"))
|
||||
// .child(
|
||||
// h_stack()
|
||||
// .gap_4()
|
||||
// .child(
|
||||
// Tab::new("left")
|
||||
// .title("Left".to_string())
|
||||
// .close_side(IconSide::Left),
|
||||
// )
|
||||
// .child(Tab::new("right").title("Right".to_string())),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "Git Status"))
|
||||
// .child(h_stack().gap_4().children(git_statuses.map(|git_status| {
|
||||
// Tab::new("git_status")
|
||||
// .title(git_status.to_string())
|
||||
// .git_status(git_status)
|
||||
// }))),
|
||||
// )
|
||||
// .child(
|
||||
// v_stack()
|
||||
// .gap_2()
|
||||
// .child(Story::label(cx, "File System Status"))
|
||||
// .child(h_stack().gap_4().children(fs_statuses.map(|fs_status| {
|
||||
// Tab::new("file_system_status")
|
||||
// .title(fs_status.to_string())
|
||||
// .fs_status(fs_status)
|
||||
// }))),
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -23,15 +23,15 @@ pub enum ToastOrigin {
|
||||
///
|
||||
/// Only one toast may be visible at a time.
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Toast<V: 'static> {
|
||||
pub struct Toast {
|
||||
origin: ToastOrigin,
|
||||
children: SmallVec<[AnyElement<V>; 2]>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Toast<V> {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Toast {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let mut div = div();
|
||||
|
||||
if self.origin == ToastOrigin::Bottom {
|
||||
@@ -54,7 +54,7 @@ impl<V: 'static> Component<V> for Toast<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Toast<V> {
|
||||
impl Toast {
|
||||
pub fn new(origin: ToastOrigin) -> Self {
|
||||
Self {
|
||||
origin,
|
||||
@@ -62,7 +62,7 @@ impl<V: 'static> Toast<V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let mut div = div();
|
||||
|
||||
if self.origin == ToastOrigin::Bottom {
|
||||
@@ -85,8 +85,8 @@ impl<V: 'static> Toast<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ParentElement<V> for Toast<V> {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
|
||||
impl ParentElement for Toast {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
||||
&mut self.children
|
||||
}
|
||||
}
|
||||
@@ -104,12 +104,12 @@ mod stories {
|
||||
|
||||
pub struct ToastStory;
|
||||
|
||||
impl Render<Self> for ToastStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ToastStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Toast<Self>>(cx))
|
||||
.child(Story::title_for::<Toast<Self>>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Toast::new(ToastOrigin::Bottom).child(Label::new("label")))
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl From<bool> for Toggle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disclosure_control<V: 'static>(toggle: Toggle) -> impl Element<V> {
|
||||
pub fn disclosure_control(toggle: Toggle) -> impl Element {
|
||||
match (toggle.is_toggleable(), toggle.is_toggled()) {
|
||||
(false, _) => div(),
|
||||
(_, true) => div().child(
|
||||
|
||||
@@ -4,10 +4,10 @@ use gpui::{Div, RenderOnce};
|
||||
#[derive(RenderOnce)]
|
||||
pub struct ToolDivider;
|
||||
|
||||
impl<V: 'static> Component<V> for ToolDivider {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for ToolDivider {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().w_px().h_3().bg(cx.theme().colors().border)
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ impl ToolDivider {
|
||||
Self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
div().w_px().h_3().bg(cx.theme().colors().border)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ impl Tooltip {
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Self> for Tooltip {
|
||||
type Element = Overlay<Self>;
|
||||
impl Render for Tooltip {
|
||||
type Element = Overlay;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
|
||||
@@ -18,7 +18,7 @@ mod components;
|
||||
mod elevation;
|
||||
pub mod prelude;
|
||||
pub mod settings;
|
||||
mod static_data;
|
||||
// mod static_data;
|
||||
mod styled_ext;
|
||||
mod to_extract;
|
||||
pub mod utils;
|
||||
@@ -26,7 +26,7 @@ pub mod utils;
|
||||
pub use components::*;
|
||||
use gpui::actions;
|
||||
pub use prelude::*;
|
||||
pub use static_data::*;
|
||||
// pub use static_data::*;
|
||||
pub use styled_ext::*;
|
||||
pub use to_extract::*;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::prelude::*;
|
||||
pub struct Story {}
|
||||
|
||||
impl Story {
|
||||
pub fn container<V: 'static>(cx: &mut ViewContext<V>) -> Div<V> {
|
||||
pub fn container(cx: &mut gpui::WindowContext) -> Div {
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
@@ -16,23 +16,23 @@ impl Story {
|
||||
}
|
||||
|
||||
pub fn title<V: 'static>(
|
||||
cx: &mut ViewContext<V>,
|
||||
cx: &mut WindowContext,
|
||||
title: impl Into<SharedString>,
|
||||
) -> impl Element<V> {
|
||||
) -> impl Element {
|
||||
div()
|
||||
.text_xl()
|
||||
.text_color(cx.theme().colors().text)
|
||||
.child(title.into())
|
||||
}
|
||||
|
||||
pub fn title_for<V: 'static, T>(cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
pub fn title_for<T>(cx: &mut WindowContext) -> impl Element {
|
||||
Self::title(cx, std::any::type_name::<T>())
|
||||
}
|
||||
|
||||
pub fn label<V: 'static>(
|
||||
cx: &mut ViewContext<V>,
|
||||
cx: &mut WindowContext,
|
||||
label: impl Into<SharedString>,
|
||||
) -> impl Element<V> {
|
||||
) -> impl Element {
|
||||
div()
|
||||
.mt_4()
|
||||
.mb_2()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use gpui::{Styled, ViewContext};
|
||||
use gpui::{Styled, WindowContext};
|
||||
use theme2::ActiveTheme;
|
||||
|
||||
use crate::{ElevationIndex, UITextSize};
|
||||
|
||||
fn elevated<E: Styled, V: 'static>(this: E, cx: &mut ViewContext<V>, index: ElevationIndex) -> E {
|
||||
fn elevated<E: Styled>(this: E, cx: &mut WindowContext, index: ElevationIndex) -> E {
|
||||
this.bg(cx.theme().colors().elevated_surface_background)
|
||||
.z_index(index.z_index())
|
||||
.rounded_lg()
|
||||
@@ -65,7 +65,7 @@ pub trait StyledExt: Styled + Sized {
|
||||
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
||||
///
|
||||
/// Example Elements: Title Bar, Panel, Tab Bar, Editor
|
||||
fn elevation_1<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
fn elevation_1(self, cx: &mut WindowContext) -> Self {
|
||||
elevated(self, cx, ElevationIndex::Surface)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ pub trait StyledExt: Styled + Sized {
|
||||
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
||||
///
|
||||
/// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels
|
||||
fn elevation_2<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
fn elevation_2(self, cx: &mut WindowContext) -> Self {
|
||||
elevated(self, cx, ElevationIndex::ElevatedSurface)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ pub trait StyledExt: Styled + Sized {
|
||||
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
||||
///
|
||||
/// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs
|
||||
fn elevation_4<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
fn elevation_4(self, cx: &mut WindowContext) -> Self {
|
||||
elevated(self, cx, ElevationIndex::ModalSurface)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,48 @@
|
||||
mod assistant_panel;
|
||||
mod breadcrumb;
|
||||
mod buffer;
|
||||
mod buffer_search;
|
||||
mod chat_panel;
|
||||
mod collab_panel;
|
||||
mod command_palette;
|
||||
mod copilot;
|
||||
mod editor_pane;
|
||||
mod language_selector;
|
||||
mod multi_buffer;
|
||||
mod notifications_panel;
|
||||
mod panes;
|
||||
mod project_panel;
|
||||
mod recent_projects;
|
||||
mod status_bar;
|
||||
mod tab_bar;
|
||||
mod terminal;
|
||||
mod theme_selector;
|
||||
mod title_bar;
|
||||
mod toolbar;
|
||||
mod traffic_lights;
|
||||
mod workspace;
|
||||
//TODO!(Restore later)
|
||||
// mod assistant_panel;
|
||||
// mod breadcrumb;
|
||||
// mod buffer;
|
||||
// mod buffer_search;
|
||||
// mod chat_panel;
|
||||
// mod collab_panel;
|
||||
// mod command_palette;
|
||||
// mod copilot;
|
||||
// mod editor_pane;
|
||||
// mod language_selector;
|
||||
// mod multi_buffer;
|
||||
// mod notifications_panel;
|
||||
// mod panes;
|
||||
// mod project_panel;
|
||||
// mod recent_projects;
|
||||
// mod status_bar;
|
||||
// mod tab_bar;
|
||||
// mod terminal;
|
||||
// mod theme_selector;
|
||||
// mod title_bar;
|
||||
// mod toolbar;
|
||||
// mod traffic_lights;
|
||||
// mod workspace;
|
||||
|
||||
pub use assistant_panel::*;
|
||||
pub use breadcrumb::*;
|
||||
pub use buffer::*;
|
||||
pub use buffer_search::*;
|
||||
pub use chat_panel::*;
|
||||
pub use collab_panel::*;
|
||||
pub use command_palette::*;
|
||||
pub use copilot::*;
|
||||
pub use editor_pane::*;
|
||||
pub use language_selector::*;
|
||||
pub use multi_buffer::*;
|
||||
pub use notifications_panel::*;
|
||||
pub use panes::*;
|
||||
pub use project_panel::*;
|
||||
pub use recent_projects::*;
|
||||
pub use status_bar::*;
|
||||
pub use tab_bar::*;
|
||||
pub use terminal::*;
|
||||
pub use theme_selector::*;
|
||||
pub use title_bar::*;
|
||||
pub use toolbar::*;
|
||||
pub use traffic_lights::*;
|
||||
pub use workspace::*;
|
||||
// pub use assistant_panel::*;
|
||||
// pub use breadcrumb::*;
|
||||
// pub use buffer::*;
|
||||
// pub use buffer_search::*;
|
||||
// pub use chat_panel::*;
|
||||
// pub use collab_panel::*;
|
||||
// pub use command_palette::*;
|
||||
// pub use copilot::*;
|
||||
// pub use editor_pane::*;
|
||||
// pub use language_selector::*;
|
||||
// pub use multi_buffer::*;
|
||||
// pub use notifications_panel::*;
|
||||
// pub use panes::*;
|
||||
// pub use project_panel::*;
|
||||
// pub use recent_projects::*;
|
||||
// pub use status_bar::*;
|
||||
// pub use tab_bar::*;
|
||||
// pub use terminal::*;
|
||||
// pub use theme_selector::*;
|
||||
// pub use title_bar::*;
|
||||
// pub use toolbar::*;
|
||||
// pub use traffic_lights::*;
|
||||
// pub use workspace::*;
|
||||
|
||||
@@ -8,10 +8,10 @@ pub struct AssistantPanel {
|
||||
current_side: PanelSide,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for AssistantPanel {
|
||||
type Rendered = Panel<V>;
|
||||
impl Component for AssistantPanel {
|
||||
type Rendered = Panel;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
Panel::new(self.id.clone(), cx)
|
||||
.children(vec![div()
|
||||
.flex()
|
||||
@@ -84,8 +84,8 @@ mod stories {
|
||||
use gpui::{Div, Render};
|
||||
pub struct AssistantPanelStory;
|
||||
|
||||
impl Render<Self> for AssistantPanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for AssistantPanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -11,10 +11,10 @@ pub struct Breadcrumb {
|
||||
symbols: Vec<Symbol>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Breadcrumb {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Breadcrumb {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view_state: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let symbols_len = self.symbols.len();
|
||||
h_stack()
|
||||
.id("breadcrumb")
|
||||
@@ -62,7 +62,7 @@ impl Breadcrumb {
|
||||
Self { path, symbols }
|
||||
}
|
||||
|
||||
fn render_separator<V: 'static>(&self, cx: &WindowContext) -> Div<V> {
|
||||
fn render_separator(&self, cx: &WindowContext) -> Div {
|
||||
div()
|
||||
.child(" › ")
|
||||
.text_color(cx.theme().colors().text_muted)
|
||||
@@ -81,8 +81,8 @@ mod stories {
|
||||
|
||||
pub struct BreadcrumbStory;
|
||||
|
||||
impl Render<Self> for BreadcrumbStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for BreadcrumbStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -117,10 +117,10 @@ pub struct Buffer {
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Buffer {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Buffer {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let rows = self.render_rows(cx);
|
||||
|
||||
v_stack()
|
||||
@@ -169,7 +169,7 @@ impl Buffer {
|
||||
self
|
||||
}
|
||||
|
||||
fn render_row<V: 'static>(row: BufferRow, cx: &WindowContext) -> impl Element<V> {
|
||||
fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element {
|
||||
let line_background = if row.current {
|
||||
cx.theme().colors().editor_active_line_background
|
||||
} else {
|
||||
@@ -217,7 +217,7 @@ impl Buffer {
|
||||
}))
|
||||
}
|
||||
|
||||
fn render_rows<V: 'static>(&self, cx: &WindowContext) -> Vec<impl Element<V>> {
|
||||
fn render_rows(&self, cx: &WindowContext) -> Vec<impl Element> {
|
||||
match &self.rows {
|
||||
Some(rows) => rows
|
||||
.rows
|
||||
@@ -228,7 +228,7 @@ impl Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let rows = self.render_rows(cx);
|
||||
|
||||
v_stack()
|
||||
@@ -254,8 +254,8 @@ mod stories {
|
||||
|
||||
pub struct BufferStory;
|
||||
|
||||
impl Render<Self> for BufferStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for BufferStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -25,10 +25,10 @@ impl BufferSearch {
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Self> for BufferSearch {
|
||||
type Element = Div<Self>;
|
||||
impl Render for BufferSearch {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Div {
|
||||
h_stack()
|
||||
.bg(cx.theme().colors().toolbar_background)
|
||||
.p_2()
|
||||
|
||||
@@ -8,10 +8,10 @@ pub struct ChatPanel {
|
||||
messages: Vec<ChatMessage>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ChatPanel {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for ChatPanel {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.id(self.element_id.clone())
|
||||
.flex()
|
||||
@@ -78,10 +78,10 @@ pub struct ChatMessage {
|
||||
sent_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ChatMessage {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for ChatMessage {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
@@ -123,8 +123,8 @@ mod stories {
|
||||
|
||||
pub struct ChatPanelStory;
|
||||
|
||||
impl Render<Self> for ChatPanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ChatPanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -9,10 +9,10 @@ pub struct CollabPanel {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for CollabPanel {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for CollabPanel {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
v_stack()
|
||||
.id(self.id.clone())
|
||||
.h_full()
|
||||
@@ -101,8 +101,8 @@ mod stories {
|
||||
|
||||
pub struct CollabPanelStory;
|
||||
|
||||
impl Render<Self> for CollabPanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for CollabPanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -6,10 +6,10 @@ pub struct CommandPalette {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for CommandPalette {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for CommandPalette {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().id(self.id.clone()).child(
|
||||
Palette::new("palette")
|
||||
.items(example_editor_actions())
|
||||
@@ -40,8 +40,8 @@ mod stories {
|
||||
|
||||
pub struct CommandPaletteStory;
|
||||
|
||||
impl Render<Self> for CommandPaletteStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for CommandPaletteStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -5,10 +5,10 @@ pub struct CopilotModal {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for CopilotModal {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for CopilotModal {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().id(self.id.clone()).child(
|
||||
Modal::new("some-id")
|
||||
.title("Connect Copilot to Zed")
|
||||
@@ -36,8 +36,8 @@ mod stories {
|
||||
|
||||
pub struct CopilotModalStory;
|
||||
|
||||
impl Render<Self> for CopilotModalStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for CopilotModalStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -47,10 +47,10 @@ impl EditorPane {
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Self> for EditorPane {
|
||||
type Element = Div<Self>;
|
||||
impl Render for EditorPane {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Div {
|
||||
v_stack()
|
||||
.w_full()
|
||||
.h_full()
|
||||
|
||||
@@ -6,10 +6,10 @@ pub struct LanguageSelector {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for LanguageSelector {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for LanguageSelector {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().id(self.id.clone()).child(
|
||||
Palette::new("palette")
|
||||
.items(vec![
|
||||
@@ -36,7 +36,7 @@ impl LanguageSelector {
|
||||
Self { id: id.into() }
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
div().id(self.id.clone()).child(
|
||||
Palette::new("palette")
|
||||
.items(vec![
|
||||
@@ -58,7 +58,7 @@ impl LanguageSelector {
|
||||
}
|
||||
}
|
||||
|
||||
use gpui::{Div, RenderOnce, Stateful};
|
||||
use gpui::{Div, RenderOnce};
|
||||
#[cfg(feature = "stories")]
|
||||
pub use stories::*;
|
||||
|
||||
@@ -70,8 +70,8 @@ mod stories {
|
||||
|
||||
pub struct LanguageSelectorStory;
|
||||
|
||||
impl Render<Self> for LanguageSelectorStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for LanguageSelectorStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -6,10 +6,10 @@ pub struct MultiBuffer {
|
||||
buffers: Vec<Buffer>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for MultiBuffer {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for MultiBuffer {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
v_stack()
|
||||
.w_full()
|
||||
.h_full()
|
||||
@@ -49,8 +49,8 @@ mod stories {
|
||||
|
||||
pub struct MultiBufferStory;
|
||||
|
||||
impl Render<Self> for MultiBufferStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for MultiBufferStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
use crate::{
|
||||
h_stack, prelude::*, static_new_notification_items_2, utils::naive_format_distance_from_now,
|
||||
v_stack, Avatar, ButtonOrIconButton, ClickHandler, Icon, IconElement, Label, LineHeightStyle,
|
||||
ListHeader, ListHeaderMeta, ListSeparator, PublicPlayer, TextColor, UnreadIndicator,
|
||||
v_stack, Avatar, ButtonOrIconButton, Icon, IconElement, Label, LineHeightStyle, ListHeader,
|
||||
ListHeaderMeta, ListSeparator, PublicPlayer, TextColor, UnreadIndicator,
|
||||
};
|
||||
use gpui::{prelude::*, Div, Stateful};
|
||||
use gpui::{prelude::*, ClickEvent, Div};
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct NotificationsPanel {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for NotificationsPanel {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for NotificationsPanel {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.flex()
|
||||
@@ -60,8 +60,8 @@ impl NotificationsPanel {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NotificationAction<V: 'static> {
|
||||
button: ButtonOrIconButton<V>,
|
||||
pub struct NotificationAction {
|
||||
button: ButtonOrIconButton,
|
||||
tooltip: SharedString,
|
||||
/// Shows after action is chosen
|
||||
///
|
||||
@@ -73,9 +73,9 @@ pub struct NotificationAction<V: 'static> {
|
||||
taken_message: (Option<Icon>, SharedString),
|
||||
}
|
||||
|
||||
impl<V: 'static> NotificationAction<V> {
|
||||
impl NotificationAction {
|
||||
pub fn new(
|
||||
button: impl Into<ButtonOrIconButton<V>>,
|
||||
button: impl Into<ButtonOrIconButton>,
|
||||
tooltip: impl Into<SharedString>,
|
||||
(icon, taken_message): (Option<Icon>, impl Into<SharedString>),
|
||||
) -> Self {
|
||||
@@ -92,38 +92,40 @@ pub enum ActorOrIcon {
|
||||
Icon(Icon),
|
||||
}
|
||||
|
||||
pub struct NotificationMeta<V: 'static> {
|
||||
items: Vec<(Option<Icon>, SharedString, Option<ClickHandler<V>>)>,
|
||||
pub type ClickHandler = Box<dyn Fn(&ClickEvent, &mut WindowContext)>;
|
||||
|
||||
pub struct NotificationMeta {
|
||||
items: Vec<(Option<Icon>, SharedString, Option<ClickHandler>)>,
|
||||
}
|
||||
|
||||
struct NotificationHandlers<V: 'static> {
|
||||
click: Option<ClickHandler<V>>,
|
||||
struct NotificationHandlers {
|
||||
click: Option<ClickHandler>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Default for NotificationHandlers<V> {
|
||||
impl Default for NotificationHandlers {
|
||||
fn default() -> Self {
|
||||
Self { click: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Notification<V: 'static> {
|
||||
pub struct Notification {
|
||||
id: ElementId,
|
||||
slot: ActorOrIcon,
|
||||
message: SharedString,
|
||||
date_received: NaiveDateTime,
|
||||
meta: Option<NotificationMeta<V>>,
|
||||
actions: Option<[NotificationAction<V>; 2]>,
|
||||
meta: Option<NotificationMeta>,
|
||||
actions: Option<[NotificationAction; 2]>,
|
||||
unread: bool,
|
||||
new: bool,
|
||||
action_taken: Option<NotificationAction<V>>,
|
||||
handlers: NotificationHandlers<V>,
|
||||
action_taken: Option<NotificationAction>,
|
||||
handlers: NotificationHandlers,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Notification<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Notification {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.relative()
|
||||
.id(self.id.clone())
|
||||
@@ -199,13 +201,13 @@ impl<V: 'static> Component<V> for Notification<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> Notification<V> {
|
||||
impl Notification {
|
||||
fn new(
|
||||
id: ElementId,
|
||||
message: SharedString,
|
||||
date_received: NaiveDateTime,
|
||||
slot: ActorOrIcon,
|
||||
click_action: Option<ClickHandler<V>>,
|
||||
click_action: Option<ClickHandler>,
|
||||
) -> Self {
|
||||
let handlers = if click_action.is_some() {
|
||||
NotificationHandlers {
|
||||
@@ -237,7 +239,7 @@ impl<V> Notification<V> {
|
||||
message: impl Into<SharedString>,
|
||||
date_received: NaiveDateTime,
|
||||
actor: PublicPlayer,
|
||||
click_action: ClickHandler<V>,
|
||||
click_action: ClickHandler,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
id.into(),
|
||||
@@ -256,7 +258,7 @@ impl<V> Notification<V> {
|
||||
message: impl Into<SharedString>,
|
||||
date_received: NaiveDateTime,
|
||||
icon: Icon,
|
||||
click_action: ClickHandler<V>,
|
||||
click_action: ClickHandler,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
id.into(),
|
||||
@@ -276,7 +278,7 @@ impl<V> Notification<V> {
|
||||
message: impl Into<SharedString>,
|
||||
date_received: NaiveDateTime,
|
||||
actor: PublicPlayer,
|
||||
actions: [NotificationAction<V>; 2],
|
||||
actions: [NotificationAction; 2],
|
||||
) -> Self {
|
||||
Self::new(
|
||||
id.into(),
|
||||
@@ -297,7 +299,7 @@ impl<V> Notification<V> {
|
||||
message: impl Into<SharedString>,
|
||||
date_received: NaiveDateTime,
|
||||
icon: Icon,
|
||||
actions: [NotificationAction<V>; 2],
|
||||
actions: [NotificationAction; 2],
|
||||
) -> Self {
|
||||
Self::new(
|
||||
id.into(),
|
||||
@@ -309,22 +311,22 @@ impl<V> Notification<V> {
|
||||
.actions(actions)
|
||||
}
|
||||
|
||||
fn on_click(mut self, handler: ClickHandler<V>) -> Self {
|
||||
fn on_click(mut self, handler: ClickHandler) -> Self {
|
||||
self.handlers.click = Some(handler);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn actions(mut self, actions: [NotificationAction<V>; 2]) -> Self {
|
||||
pub fn actions(mut self, actions: [NotificationAction; 2]) -> Self {
|
||||
self.actions = Some(actions);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn meta(mut self, meta: NotificationMeta<V>) -> Self {
|
||||
pub fn meta(mut self, meta: NotificationMeta) -> Self {
|
||||
self.meta = Some(meta);
|
||||
self
|
||||
}
|
||||
|
||||
fn render_meta_items(&self, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render_meta_items(&self, cx: &mut WindowContext) -> impl Element {
|
||||
if let Some(meta) = &self.meta {
|
||||
h_stack().children(
|
||||
meta.items
|
||||
@@ -343,7 +345,7 @@ impl<V> Notification<V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_slot(&self, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render_slot(&self, cx: &mut WindowContext) -> impl Element {
|
||||
match &self.slot {
|
||||
ActorOrIcon::Actor(actor) => Avatar::new(actor.avatar.clone()).render_into_any(),
|
||||
ActorOrIcon::Icon(icon) => IconElement::new(icon.clone()).render_into_any(),
|
||||
@@ -364,12 +366,12 @@ mod stories {
|
||||
|
||||
pub struct NotificationsPanelStory;
|
||||
|
||||
impl Render<Self> for NotificationsPanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for NotificationsPanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, NotificationsPanel>(cx))
|
||||
.child(Story::title_for::<NotificationsPanel>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(
|
||||
Panel::new("panel", cx).child(NotificationsPanel::new("notifications_panel")),
|
||||
|
||||
@@ -14,17 +14,17 @@ pub enum SplitDirection {
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Pane<V: 'static> {
|
||||
pub struct Pane {
|
||||
id: ElementId,
|
||||
size: Size<Length>,
|
||||
fill: Hsla,
|
||||
children: SmallVec<[AnyElement<V>; 2]>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Pane<V> {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for Pane {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.flex()
|
||||
@@ -48,7 +48,7 @@ impl<V: 'static> Component<V> for Pane<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Pane<V> {
|
||||
impl Pane {
|
||||
pub fn new(id: impl Into<ElementId>, size: Size<Length>) -> Self {
|
||||
// Fill is only here for debugging purposes, remove before release
|
||||
|
||||
@@ -66,23 +66,23 @@ impl<V: 'static> Pane<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> ParentElement<V> for Pane<V> {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
|
||||
impl ParentElement for Pane {
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
|
||||
&mut self.children
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct PaneGroup<V: 'static> {
|
||||
groups: Vec<PaneGroup<V>>,
|
||||
panes: Vec<Pane<V>>,
|
||||
pub struct PaneGroup {
|
||||
groups: Vec<PaneGroup>,
|
||||
panes: Vec<Pane>,
|
||||
split_direction: SplitDirection,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for PaneGroup<V> {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for PaneGroup {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
if !self.panes.is_empty() {
|
||||
let el = div()
|
||||
.flex()
|
||||
@@ -90,7 +90,7 @@ impl<V: 'static> Component<V> for PaneGroup<V> {
|
||||
.gap_px()
|
||||
.w_full()
|
||||
.h_full()
|
||||
.children(self.panes.into_iter().map(|pane| pane.render(view, cx)));
|
||||
.children(self.panes.into_iter().map(|pane| pane.render(cx)));
|
||||
|
||||
if self.split_direction == SplitDirection::Horizontal {
|
||||
return el;
|
||||
@@ -107,7 +107,7 @@ impl<V: 'static> Component<V> for PaneGroup<V> {
|
||||
.w_full()
|
||||
.h_full()
|
||||
.bg(cx.theme().colors().editor_background)
|
||||
.children(self.groups.into_iter().map(|group| group.render(view, cx)));
|
||||
.children(self.groups.into_iter().map(|group| group.render(cx)));
|
||||
|
||||
if self.split_direction == SplitDirection::Horizontal {
|
||||
return el;
|
||||
@@ -120,8 +120,8 @@ impl<V: 'static> Component<V> for PaneGroup<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> PaneGroup<V> {
|
||||
pub fn new_groups(groups: Vec<PaneGroup<V>>, split_direction: SplitDirection) -> Self {
|
||||
impl PaneGroup {
|
||||
pub fn new_groups(groups: Vec<PaneGroup>, split_direction: SplitDirection) -> Self {
|
||||
Self {
|
||||
groups,
|
||||
panes: Vec::new(),
|
||||
@@ -129,7 +129,7 @@ impl<V: 'static> PaneGroup<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_panes(panes: Vec<Pane<V>>, split_direction: SplitDirection) -> Self {
|
||||
pub fn new_panes(panes: Vec<Pane>, split_direction: SplitDirection) -> Self {
|
||||
Self {
|
||||
groups: Vec::new(),
|
||||
panes,
|
||||
|
||||
@@ -11,10 +11,10 @@ pub struct ProjectPanel {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ProjectPanel {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for ProjectPanel {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.flex()
|
||||
@@ -52,7 +52,7 @@ impl ProjectPanel {
|
||||
Self { id: id.into() }
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.flex()
|
||||
@@ -97,8 +97,8 @@ mod stories {
|
||||
|
||||
pub struct ProjectPanelStory;
|
||||
|
||||
impl Render<Self> for ProjectPanelStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ProjectPanelStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -6,10 +6,10 @@ pub struct RecentProjects {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for RecentProjects {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for RecentProjects {
|
||||
type Rendered = Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().id(self.id.clone()).child(
|
||||
Palette::new("palette")
|
||||
.items(vec![
|
||||
@@ -45,10 +45,10 @@ mod stories {
|
||||
|
||||
pub struct RecentProjectsStory;
|
||||
|
||||
impl Render<Self> for RecentProjectsStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for RecentProjectsStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, RecentProjects>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
|
||||
@@ -328,7 +328,7 @@ pub fn static_players_with_call_status() -> Vec<PlayerWithCallStatus> {
|
||||
]
|
||||
}
|
||||
|
||||
pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||
pub fn static_new_notification_items_2() -> Vec<Notification> {
|
||||
vec![
|
||||
Notification::new_icon_message(
|
||||
"notif-1",
|
||||
@@ -478,7 +478,7 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||
]
|
||||
}
|
||||
|
||||
pub fn static_project_panel_project_items<V>() -> Vec<ListItem<V>> {
|
||||
pub fn static_project_panel_project_items() -> Vec<ListItem> {
|
||||
vec![
|
||||
ListEntry::new(Label::new("zed"))
|
||||
.left_icon(Icon::FolderOpen.into())
|
||||
@@ -605,7 +605,7 @@ pub fn static_project_panel_project_items<V>() -> Vec<ListItem<V>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn static_project_panel_single_items<V>() -> Vec<ListItem<V>> {
|
||||
pub fn static_project_panel_single_items() -> Vec<ListItem> {
|
||||
vec![
|
||||
ListEntry::new(Label::new("todo.md"))
|
||||
.left_icon(Icon::FileDoc.into())
|
||||
@@ -622,7 +622,7 @@ pub fn static_project_panel_single_items<V>() -> Vec<ListItem<V>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn static_collab_panel_current_call<V>() -> Vec<ListItem<V>> {
|
||||
pub fn static_collab_panel_current_call() -> Vec<ListItem> {
|
||||
vec![
|
||||
ListEntry::new(Label::new("as-cii")).left_avatar("http://github.com/as-cii.png?s=50"),
|
||||
ListEntry::new(Label::new("nathansobo"))
|
||||
@@ -635,7 +635,7 @@ pub fn static_collab_panel_current_call<V>() -> Vec<ListItem<V>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn static_collab_panel_channels<V>() -> Vec<ListItem<V>> {
|
||||
pub fn static_collab_panel_channels<V>() -> Vec<ListItem> {
|
||||
vec![
|
||||
ListEntry::new(Label::new("zed"))
|
||||
.left_icon(Icon::Hash.into())
|
||||
@@ -38,8 +38,8 @@ pub struct StatusBar {
|
||||
bottom_tools: Option<ToolGroup>,
|
||||
}
|
||||
|
||||
impl Component<Workspace> for StatusBar {
|
||||
type Rendered = Div<Workspace>;
|
||||
impl Component for StatusBar {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut Workspace, cx: &mut ViewContext<Workspace>) -> Self::Rendered {
|
||||
div()
|
||||
@@ -100,7 +100,7 @@ impl StatusBar {
|
||||
self
|
||||
}
|
||||
|
||||
fn left_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element<Workspace> {
|
||||
fn left_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element {
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
@@ -127,11 +127,7 @@ impl StatusBar {
|
||||
.child(IconButton::new("diagnostics", Icon::XCircle))
|
||||
}
|
||||
|
||||
fn right_tools(
|
||||
&self,
|
||||
workspace: &mut Workspace,
|
||||
cx: &WindowContext,
|
||||
) -> impl Element<Workspace> {
|
||||
fn right_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element {
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
|
||||
@@ -11,10 +11,10 @@ pub struct TabBar {
|
||||
tabs: Vec<Tab>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for TabBar {
|
||||
type Rendered = Stateful<V, Div<V>>;
|
||||
impl Component for TabBar {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let (can_navigate_back, can_navigate_forward) = self.can_navigate;
|
||||
|
||||
div()
|
||||
@@ -110,8 +110,8 @@ mod stories {
|
||||
|
||||
pub struct TabBarStory;
|
||||
|
||||
impl Render<Self> for TabBarStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for TabBarStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -5,10 +5,10 @@ use gpui::{relative, rems, Div, RenderOnce, Size};
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Terminal;
|
||||
|
||||
impl<V: 'static> Component<V> for Terminal {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Terminal {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
let can_navigate_back = true;
|
||||
let can_navigate_forward = false;
|
||||
|
||||
@@ -78,7 +78,7 @@ impl Terminal {
|
||||
Self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
||||
fn render(self, cx: &mut WindowContext) -> impl Element {
|
||||
let can_navigate_back = true;
|
||||
let can_navigate_forward = false;
|
||||
|
||||
@@ -153,8 +153,8 @@ mod stories {
|
||||
use gpui::{Div, Render};
|
||||
pub struct TerminalStory;
|
||||
|
||||
impl Render<Self> for TerminalStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for TerminalStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -6,11 +6,10 @@ pub struct ThemeSelector {
|
||||
id: ElementId,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for ThemeSelector {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for ThemeSelector {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
let cx: &mut ViewContext<V> = cx;
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
div().child(
|
||||
Palette::new(self.id.clone())
|
||||
.items(vec![
|
||||
@@ -53,8 +52,8 @@ mod stories {
|
||||
|
||||
pub struct ThemeSelectorStory;
|
||||
|
||||
impl Render<Self> for ThemeSelectorStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ThemeSelectorStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
|
||||
@@ -85,10 +85,10 @@ impl TitleBar {
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Self> for TitleBar {
|
||||
type Element = Div<Self>;
|
||||
impl Render for TitleBar {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Div {
|
||||
let settings = user_settings(cx);
|
||||
|
||||
// let has_focus = cx.window_is_active();
|
||||
@@ -205,10 +205,10 @@ mod stories {
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Self> for TitleBarStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for TitleBarStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Div {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, TitleBar>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
|
||||
@@ -7,15 +7,15 @@ use crate::prelude::*;
|
||||
pub struct ToolbarItem {}
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct Toolbar<V: 'static> {
|
||||
left_items: SmallVec<[AnyElement<V>; 2]>,
|
||||
right_items: SmallVec<[AnyElement<V>; 2]>,
|
||||
pub struct Toolbar {
|
||||
left_items: SmallVec<[AnyElement; 2]>,
|
||||
right_items: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
|
||||
impl<V: 'static> Component<V> for Toolbar<V> {
|
||||
type Rendered = Div<V>;
|
||||
impl Component for Toolbar {
|
||||
type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
fn render(self, cx: &WindowContext) -> Self::Rendered {
|
||||
div()
|
||||
.bg(cx.theme().colors().toolbar_background)
|
||||
.p_2()
|
||||
@@ -26,7 +26,7 @@ impl<V: 'static> Component<V> for Toolbar<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Toolbar<V> {
|
||||
impl Toolbar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
left_items: SmallVec::new(),
|
||||
@@ -34,7 +34,7 @@ impl<V: 'static> Toolbar<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn left_item(mut self, child: impl RenderOnce<V>) -> Self
|
||||
pub fn left_item(mut self, child: impl RenderOnce) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -42,7 +42,7 @@ impl<V: 'static> Toolbar<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn left_items(mut self, iter: impl IntoIterator<Item = impl RenderOnce<V>>) -> Self
|
||||
pub fn left_items(mut self, iter: impl IntoIterator<Item = impl RenderOnce>) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -51,7 +51,7 @@ impl<V: 'static> Toolbar<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn right_item(mut self, child: impl RenderOnce<V>) -> Self
|
||||
pub fn right_item(mut self, child: impl RenderOnce) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -59,7 +59,7 @@ impl<V: 'static> Toolbar<V> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn right_items(mut self, iter: impl IntoIterator<Item = impl RenderOnce<V>>) -> Self
|
||||
pub fn right_items(mut self, iter: impl IntoIterator<Item = impl RenderOnce>) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -85,10 +85,10 @@ mod stories {
|
||||
|
||||
pub struct ToolbarStory;
|
||||
|
||||
impl Render<Self> for ToolbarStory {
|
||||
type Element = Div<Self>;
|
||||
impl Render for ToolbarStory {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut WindowContext) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Toolbar<Self>>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
use crate::prelude::*;
|
||||
// use crate::prelude::*;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum TrafficLightColor {
|
||||
Red,
|
||||
Yellow,
|
||||
Green,
|
||||
}
|
||||
// #[derive(Clone, Copy)]
|
||||
// enum TrafficLightColor {
|
||||
// Red,
|
||||
// Yellow,
|
||||
// Green,
|
||||
// }
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
struct TrafficLight {
|
||||
color: TrafficLightColor,
|
||||
window_has_focus: bool,
|
||||
}
|
||||
// #[derive(RenderOnce)]
|
||||
// struct TrafficLight {
|
||||
// color: TrafficLightColor,
|
||||
// window_has_focus: bool,
|
||||
// }
|
||||
|
||||
impl<V: 'static> Component<V> for TrafficLight {
|
||||
type Rendered = Div<V>;
|
||||
// impl Component for TrafficLight {
|
||||
// type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
let system_colors = &cx.theme().styles.system;
|
||||
// fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
// let system_colors = &cx.theme().styles.system;
|
||||
|
||||
let fill = match (self.window_has_focus, self.color) {
|
||||
(true, TrafficLightColor::Red) => system_colors.mac_os_traffic_light_red,
|
||||
(true, TrafficLightColor::Yellow) => system_colors.mac_os_traffic_light_yellow,
|
||||
(true, TrafficLightColor::Green) => system_colors.mac_os_traffic_light_green,
|
||||
(false, _) => cx.theme().colors().element_background,
|
||||
};
|
||||
// let fill = match (self.window_has_focus, self.color) {
|
||||
// (true, TrafficLightColor::Red) => system_colors.mac_os_traffic_light_red,
|
||||
// (true, TrafficLightColor::Yellow) => system_colors.mac_os_traffic_light_yellow,
|
||||
// (true, TrafficLightColor::Green) => system_colors.mac_os_traffic_light_green,
|
||||
// (false, _) => cx.theme().colors().element_background,
|
||||
// };
|
||||
|
||||
div().w_3().h_3().rounded_full().bg(fill)
|
||||
}
|
||||
}
|
||||
// div().w_3().h_3().rounded_full().bg(fill)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl TrafficLight {
|
||||
fn new(color: TrafficLightColor, window_has_focus: bool) -> Self {
|
||||
Self {
|
||||
color,
|
||||
window_has_focus,
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl TrafficLight {
|
||||
// fn new(color: TrafficLightColor, window_has_focus: bool) -> Self {
|
||||
// Self {
|
||||
// color,
|
||||
// window_has_focus,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(RenderOnce)]
|
||||
pub struct TrafficLights {
|
||||
window_has_focus: bool,
|
||||
}
|
||||
// #[derive(RenderOnce)]
|
||||
// pub struct TrafficLights {
|
||||
// window_has_focus: bool,
|
||||
// }
|
||||
|
||||
impl<V: 'static> Component<V> for TrafficLights {
|
||||
type Rendered = Div<V>;
|
||||
// impl Component for TrafficLights {
|
||||
// type Rendered = Div;
|
||||
|
||||
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(TrafficLight::new(
|
||||
TrafficLightColor::Red,
|
||||
self.window_has_focus,
|
||||
))
|
||||
.child(TrafficLight::new(
|
||||
TrafficLightColor::Yellow,
|
||||
self.window_has_focus,
|
||||
))
|
||||
.child(TrafficLight::new(
|
||||
TrafficLightColor::Green,
|
||||
self.window_has_focus,
|
||||
))
|
||||
}
|
||||
}
|
||||
// fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
// div()
|
||||
// .flex()
|
||||
// .items_center()
|
||||
// .gap_2()
|
||||
// .child(TrafficLight::new(
|
||||
// TrafficLightColor::Red,
|
||||
// self.window_has_focus,
|
||||
// ))
|
||||
// .child(TrafficLight::new(
|
||||
// TrafficLightColor::Yellow,
|
||||
// self.window_has_focus,
|
||||
// ))
|
||||
// .child(TrafficLight::new(
|
||||
// TrafficLightColor::Green,
|
||||
// self.window_has_focus,
|
||||
// ))
|
||||
// }
|
||||
// }
|
||||
|
||||
impl TrafficLights {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
window_has_focus: true,
|
||||
}
|
||||
}
|
||||
// impl TrafficLights {
|
||||
// pub fn new() -> Self {
|
||||
// Self {
|
||||
// window_has_focus: true,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn window_has_focus(mut self, window_has_focus: bool) -> Self {
|
||||
self.window_has_focus = window_has_focus;
|
||||
self
|
||||
}
|
||||
}
|
||||
// pub fn window_has_focus(mut self, window_has_focus: bool) -> Self {
|
||||
// self.window_has_focus = window_has_focus;
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
|
||||
use gpui::{Div, RenderOnce};
|
||||
#[cfg(feature = "stories")]
|
||||
pub use stories::*;
|
||||
// use gpui::{Div, RenderOnce};
|
||||
// #[cfg(feature = "stories")]
|
||||
// pub use stories::*;
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
mod stories {
|
||||
use gpui::{Div, Render};
|
||||
// #[cfg(feature = "stories")]
|
||||
// mod stories {
|
||||
// use gpui::{Div, Render};
|
||||
|
||||
use crate::Story;
|
||||
// use crate::Story;
|
||||
|
||||
use super::*;
|
||||
// use super::*;
|
||||
|
||||
pub struct TrafficLightsStory;
|
||||
// pub struct TrafficLightsStory;
|
||||
|
||||
impl Render<Self> for TrafficLightsStory {
|
||||
type Element = Div<Self>;
|
||||
// impl Render for TrafficLightsStory {
|
||||
// type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, TrafficLights>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(TrafficLights::new())
|
||||
.child(Story::label(cx, "Unfocused"))
|
||||
.child(TrafficLights::new().window_has_focus(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
// Story::container(cx)
|
||||
// .child(Story::title_for::<TrafficLights>(cx))
|
||||
// .child(Story::label(cx, "Default"))
|
||||
// .child(TrafficLights::new())
|
||||
// .child(Story::label(cx, "Unfocused"))
|
||||
// .child(TrafficLights::new().window_has_focus(false))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,398 +1,398 @@
|
||||
use std::sync::Arc;
|
||||
// use std::sync::Arc;
|
||||
|
||||
use chrono::DateTime;
|
||||
use gpui::{px, relative, Div, Render, RenderOnce, Size, View, VisualContext};
|
||||
use settings2::Settings;
|
||||
use theme2::ThemeSettings;
|
||||
// use chrono::DateTime;
|
||||
// use gpui::{px, relative, Div, Render, RenderOnce, Size, View, VisualContext};
|
||||
// use settings2::Settings;
|
||||
// use theme2::ThemeSettings;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
static_livestream, v_stack, AssistantPanel, Button, ChatMessage, ChatPanel, Checkbox,
|
||||
CollabPanel, EditorPane, Label, LanguageSelector, NotificationsPanel, Pane, PaneGroup, Panel,
|
||||
PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar,
|
||||
Toast, ToastOrigin,
|
||||
};
|
||||
// use crate::prelude::*;
|
||||
// use crate::{
|
||||
// static_livestream, v_stack, AssistantPanel, Button, ChatMessage, ChatPanel, Checkbox,
|
||||
// CollabPanel, EditorPane, Label, LanguageSelector, NotificationsPanel, Pane, PaneGroup, Panel,
|
||||
// PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar,
|
||||
// Toast, ToastOrigin,
|
||||
// };
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Gpui2UiDebug {
|
||||
pub in_livestream: bool,
|
||||
pub enable_user_settings: bool,
|
||||
pub show_toast: bool,
|
||||
}
|
||||
// #[derive(Clone)]
|
||||
// pub struct Gpui2UiDebug {
|
||||
// pub in_livestream: bool,
|
||||
// pub enable_user_settings: bool,
|
||||
// pub show_toast: bool,
|
||||
// }
|
||||
|
||||
impl Default for Gpui2UiDebug {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
in_livestream: false,
|
||||
enable_user_settings: false,
|
||||
show_toast: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl Default for Gpui2UiDebug {
|
||||
// fn default() -> Self {
|
||||
// Self {
|
||||
// in_livestream: false,
|
||||
// enable_user_settings: false,
|
||||
// show_toast: false,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Workspace {
|
||||
title_bar: View<TitleBar>,
|
||||
editor_1: View<EditorPane>,
|
||||
show_project_panel: bool,
|
||||
show_collab_panel: bool,
|
||||
show_chat_panel: bool,
|
||||
show_assistant_panel: bool,
|
||||
show_notifications_panel: bool,
|
||||
show_terminal: bool,
|
||||
show_debug: bool,
|
||||
show_language_selector: bool,
|
||||
test_checkbox_selection: Selection,
|
||||
debug: Gpui2UiDebug,
|
||||
}
|
||||
// #[derive(Clone)]
|
||||
// pub struct Workspace {
|
||||
// title_bar: View<TitleBar>,
|
||||
// editor_1: View<EditorPane>,
|
||||
// show_project_panel: bool,
|
||||
// show_collab_panel: bool,
|
||||
// show_chat_panel: bool,
|
||||
// show_assistant_panel: bool,
|
||||
// show_notifications_panel: bool,
|
||||
// show_terminal: bool,
|
||||
// show_debug: bool,
|
||||
// show_language_selector: bool,
|
||||
// test_checkbox_selection: Selection,
|
||||
// debug: Gpui2UiDebug,
|
||||
// }
|
||||
|
||||
impl Workspace {
|
||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
Self {
|
||||
title_bar: TitleBar::view(cx, None),
|
||||
editor_1: EditorPane::view(cx),
|
||||
show_project_panel: true,
|
||||
show_collab_panel: false,
|
||||
show_chat_panel: false,
|
||||
show_assistant_panel: false,
|
||||
show_terminal: true,
|
||||
show_language_selector: false,
|
||||
show_debug: false,
|
||||
show_notifications_panel: true,
|
||||
test_checkbox_selection: Selection::Unselected,
|
||||
debug: Gpui2UiDebug::default(),
|
||||
}
|
||||
}
|
||||
// impl Workspace {
|
||||
// pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
// Self {
|
||||
// title_bar: TitleBar::view(cx, None),
|
||||
// editor_1: EditorPane::view(cx),
|
||||
// show_project_panel: true,
|
||||
// show_collab_panel: false,
|
||||
// show_chat_panel: false,
|
||||
// show_assistant_panel: false,
|
||||
// show_terminal: true,
|
||||
// show_language_selector: false,
|
||||
// show_debug: false,
|
||||
// show_notifications_panel: true,
|
||||
// test_checkbox_selection: Selection::Unselected,
|
||||
// debug: Gpui2UiDebug::default(),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn is_project_panel_open(&self) -> bool {
|
||||
self.show_project_panel
|
||||
}
|
||||
// pub fn is_project_panel_open(&self) -> bool {
|
||||
// self.show_project_panel
|
||||
// }
|
||||
|
||||
pub fn toggle_project_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_project_panel = !self.show_project_panel;
|
||||
// pub fn toggle_project_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_project_panel = !self.show_project_panel;
|
||||
|
||||
self.show_collab_panel = false;
|
||||
// self.show_collab_panel = false;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn is_collab_panel_open(&self) -> bool {
|
||||
self.show_collab_panel
|
||||
}
|
||||
// pub fn is_collab_panel_open(&self) -> bool {
|
||||
// self.show_collab_panel
|
||||
// }
|
||||
|
||||
pub fn toggle_collab_panel(&mut self) {
|
||||
self.show_collab_panel = !self.show_collab_panel;
|
||||
// pub fn toggle_collab_panel(&mut self) {
|
||||
// self.show_collab_panel = !self.show_collab_panel;
|
||||
|
||||
self.show_project_panel = false;
|
||||
}
|
||||
// self.show_project_panel = false;
|
||||
// }
|
||||
|
||||
pub fn is_terminal_open(&self) -> bool {
|
||||
self.show_terminal
|
||||
}
|
||||
// pub fn is_terminal_open(&self) -> bool {
|
||||
// self.show_terminal
|
||||
// }
|
||||
|
||||
pub fn toggle_terminal(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_terminal = !self.show_terminal;
|
||||
// pub fn toggle_terminal(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_terminal = !self.show_terminal;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn is_chat_panel_open(&self) -> bool {
|
||||
self.show_chat_panel
|
||||
}
|
||||
// pub fn is_chat_panel_open(&self) -> bool {
|
||||
// self.show_chat_panel
|
||||
// }
|
||||
|
||||
pub fn toggle_chat_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_chat_panel = !self.show_chat_panel;
|
||||
// pub fn toggle_chat_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_chat_panel = !self.show_chat_panel;
|
||||
|
||||
self.show_assistant_panel = false;
|
||||
self.show_notifications_panel = false;
|
||||
// self.show_assistant_panel = false;
|
||||
// self.show_notifications_panel = false;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn is_notifications_panel_open(&self) -> bool {
|
||||
self.show_notifications_panel
|
||||
}
|
||||
// pub fn is_notifications_panel_open(&self) -> bool {
|
||||
// self.show_notifications_panel
|
||||
// }
|
||||
|
||||
pub fn toggle_notifications_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_notifications_panel = !self.show_notifications_panel;
|
||||
// pub fn toggle_notifications_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_notifications_panel = !self.show_notifications_panel;
|
||||
|
||||
self.show_chat_panel = false;
|
||||
self.show_assistant_panel = false;
|
||||
// self.show_chat_panel = false;
|
||||
// self.show_assistant_panel = false;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn is_assistant_panel_open(&self) -> bool {
|
||||
self.show_assistant_panel
|
||||
}
|
||||
// pub fn is_assistant_panel_open(&self) -> bool {
|
||||
// self.show_assistant_panel
|
||||
// }
|
||||
|
||||
pub fn toggle_assistant_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_assistant_panel = !self.show_assistant_panel;
|
||||
// pub fn toggle_assistant_panel(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_assistant_panel = !self.show_assistant_panel;
|
||||
|
||||
self.show_chat_panel = false;
|
||||
self.show_notifications_panel = false;
|
||||
// self.show_chat_panel = false;
|
||||
// self.show_notifications_panel = false;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn is_language_selector_open(&self) -> bool {
|
||||
self.show_language_selector
|
||||
}
|
||||
// pub fn is_language_selector_open(&self) -> bool {
|
||||
// self.show_language_selector
|
||||
// }
|
||||
|
||||
pub fn toggle_language_selector(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_language_selector = !self.show_language_selector;
|
||||
// pub fn toggle_language_selector(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_language_selector = !self.show_language_selector;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn toggle_debug(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.show_debug = !self.show_debug;
|
||||
// pub fn toggle_debug(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.show_debug = !self.show_debug;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn debug_toggle_user_settings(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.debug.enable_user_settings = !self.debug.enable_user_settings;
|
||||
// pub fn debug_toggle_user_settings(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.debug.enable_user_settings = !self.debug.enable_user_settings;
|
||||
|
||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||
// let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||
|
||||
if self.debug.enable_user_settings {
|
||||
theme_settings.ui_font_size = 18.0.into();
|
||||
} else {
|
||||
theme_settings.ui_font_size = 16.0.into();
|
||||
}
|
||||
// if self.debug.enable_user_settings {
|
||||
// theme_settings.ui_font_size = 18.0.into();
|
||||
// } else {
|
||||
// theme_settings.ui_font_size = 16.0.into();
|
||||
// }
|
||||
|
||||
ThemeSettings::override_global(theme_settings.clone(), cx);
|
||||
// ThemeSettings::override_global(theme_settings.clone(), cx);
|
||||
|
||||
cx.set_rem_size(theme_settings.ui_font_size);
|
||||
// cx.set_rem_size(theme_settings.ui_font_size);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn debug_toggle_livestream(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.debug.in_livestream = !self.debug.in_livestream;
|
||||
// pub fn debug_toggle_livestream(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.debug.in_livestream = !self.debug.in_livestream;
|
||||
|
||||
self.title_bar = TitleBar::view(
|
||||
cx,
|
||||
Some(static_livestream()).filter(|_| self.debug.in_livestream),
|
||||
);
|
||||
// self.title_bar = TitleBar::view(
|
||||
// cx,
|
||||
// Some(static_livestream()).filter(|_| self.debug.in_livestream),
|
||||
// );
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn debug_toggle_toast(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.debug.show_toast = !self.debug.show_toast;
|
||||
// pub fn debug_toggle_toast(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.debug.show_toast = !self.debug.show_toast;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.build_view(|cx| Self::new(cx))
|
||||
}
|
||||
}
|
||||
// pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
// cx.build_view(|cx| Self::new(cx))
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Render<Self> for Workspace {
|
||||
type Element = Div<Self>;
|
||||
// impl Render for Workspace {
|
||||
// type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
|
||||
let root_group = PaneGroup::new_panes(
|
||||
vec![Pane::new(
|
||||
"pane-0",
|
||||
Size {
|
||||
width: relative(1.).into(),
|
||||
height: relative(1.).into(),
|
||||
},
|
||||
)
|
||||
.child(self.editor_1.clone())],
|
||||
SplitDirection::Horizontal,
|
||||
);
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
// fn render(&mut self, cx: &mut WindowContext) -> Div {
|
||||
// let root_group = PaneGroup::new_panes(
|
||||
// vec![Pane::new(
|
||||
// "pane-0",
|
||||
// Size {
|
||||
// width: relative(1.).into(),
|
||||
// height: relative(1.).into(),
|
||||
// },
|
||||
// )
|
||||
// .child(self.editor_1.clone())],
|
||||
// SplitDirection::Horizontal,
|
||||
// );
|
||||
// let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.font(ui_font)
|
||||
.gap_0()
|
||||
.justify_start()
|
||||
.items_start()
|
||||
.text_color(cx.theme().colors().text)
|
||||
.bg(cx.theme().colors().background)
|
||||
.child(self.title_bar.clone())
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_12()
|
||||
.left_12()
|
||||
.z_index(99)
|
||||
.bg(cx.theme().colors().background)
|
||||
.child(
|
||||
Checkbox::new("test_checkbox", self.test_checkbox_selection).on_click(
|
||||
|selection, workspace: &mut Workspace, cx| {
|
||||
workspace.test_checkbox_selection = selection;
|
||||
// div()
|
||||
// .relative()
|
||||
// .size_full()
|
||||
// .flex()
|
||||
// .flex_col()
|
||||
// .font(ui_font)
|
||||
// .gap_0()
|
||||
// .justify_start()
|
||||
// .items_start()
|
||||
// .text_color(cx.theme().colors().text)
|
||||
// .bg(cx.theme().colors().background)
|
||||
// .child(self.title_bar.clone())
|
||||
// .child(
|
||||
// div()
|
||||
// .absolute()
|
||||
// .top_12()
|
||||
// .left_12()
|
||||
// .z_index(99)
|
||||
// .bg(cx.theme().colors().background)
|
||||
// .child(
|
||||
// Checkbox::new("test_checkbox", self.test_checkbox_selection).on_click(
|
||||
// |selection, workspace: &mut Workspace, cx| {
|
||||
// workspace.test_checkbox_selection = selection;
|
||||
|
||||
cx.notify();
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.overflow_hidden()
|
||||
.border_t()
|
||||
.border_b()
|
||||
.border_color(cx.theme().colors().border)
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("project-panel-outer", cx)
|
||||
.side(PanelSide::Left)
|
||||
.child(ProjectPanel::new("project-panel-inner")),
|
||||
)
|
||||
.filter(|_| self.is_project_panel_open()),
|
||||
)
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("collab-panel-outer", cx)
|
||||
.child(CollabPanel::new("collab-panel-inner"))
|
||||
.side(PanelSide::Left),
|
||||
)
|
||||
.filter(|_| self.is_collab_panel_open()),
|
||||
)
|
||||
// .child(NotificationToast::new(
|
||||
// "maxbrunsfeld has requested to add you as a contact.".into(),
|
||||
// ))
|
||||
.child(
|
||||
v_stack()
|
||||
.flex_1()
|
||||
.h_full()
|
||||
.child(div().flex().flex_1().child(root_group))
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("terminal-panel", cx)
|
||||
.child(Terminal::new())
|
||||
.allowed_sides(PanelAllowedSides::BottomOnly)
|
||||
.side(PanelSide::Bottom),
|
||||
)
|
||||
.filter(|_| self.is_terminal_open()),
|
||||
),
|
||||
)
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("chat-panel-outer", cx)
|
||||
.side(PanelSide::Right)
|
||||
.child(ChatPanel::new("chat-panel-inner").messages(vec![
|
||||
ChatMessage::new(
|
||||
"osiewicz".to_string(),
|
||||
"is this thing on?".to_string(),
|
||||
DateTime::parse_from_rfc3339("2023-09-27T15:40:52.707Z")
|
||||
.unwrap()
|
||||
.naive_local(),
|
||||
),
|
||||
ChatMessage::new(
|
||||
"maxdeviant".to_string(),
|
||||
"Reading you loud and clear!".to_string(),
|
||||
DateTime::parse_from_rfc3339("2023-09-28T15:40:52.707Z")
|
||||
.unwrap()
|
||||
.naive_local(),
|
||||
),
|
||||
])),
|
||||
)
|
||||
.filter(|_| self.is_chat_panel_open()),
|
||||
)
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("notifications-panel-outer", cx)
|
||||
.side(PanelSide::Right)
|
||||
.child(NotificationsPanel::new("notifications-panel-inner")),
|
||||
)
|
||||
.filter(|_| self.is_notifications_panel_open()),
|
||||
)
|
||||
.children(
|
||||
Some(
|
||||
Panel::new("assistant-panel-outer", cx)
|
||||
.child(AssistantPanel::new("assistant-panel-inner")),
|
||||
)
|
||||
.filter(|_| self.is_assistant_panel_open()),
|
||||
),
|
||||
)
|
||||
.child(StatusBar::new())
|
||||
.when(self.debug.show_toast, |this| {
|
||||
this.child(Toast::new(ToastOrigin::Bottom).child(Label::new("A toast")))
|
||||
})
|
||||
.children(
|
||||
Some(
|
||||
div()
|
||||
.absolute()
|
||||
.top(px(50.))
|
||||
.left(px(640.))
|
||||
.z_index(8)
|
||||
.child(LanguageSelector::new("language-selector")),
|
||||
)
|
||||
.filter(|_| self.is_language_selector_open()),
|
||||
)
|
||||
.z_index(8)
|
||||
// Debug
|
||||
.child(
|
||||
v_stack()
|
||||
.z_index(9)
|
||||
.absolute()
|
||||
.top_20()
|
||||
.left_1_4()
|
||||
.w_40()
|
||||
.gap_2()
|
||||
.when(self.show_debug, |this| {
|
||||
this.child(Button::<Workspace>::new("Toggle User Settings").on_click(
|
||||
Arc::new(|workspace, cx| workspace.debug_toggle_user_settings(cx)),
|
||||
))
|
||||
.child(
|
||||
Button::<Workspace>::new("Toggle Toasts").on_click(Arc::new(
|
||||
|workspace, cx| workspace.debug_toggle_toast(cx),
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
Button::<Workspace>::new("Toggle Livestream").on_click(Arc::new(
|
||||
|workspace, cx| workspace.debug_toggle_livestream(cx),
|
||||
)),
|
||||
)
|
||||
})
|
||||
.child(
|
||||
Button::<Workspace>::new("Toggle Debug")
|
||||
.on_click(Arc::new(|workspace, cx| workspace.toggle_debug(cx))),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
// cx.notify();
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// div()
|
||||
// .flex_1()
|
||||
// .w_full()
|
||||
// .flex()
|
||||
// .flex_row()
|
||||
// .overflow_hidden()
|
||||
// .border_t()
|
||||
// .border_b()
|
||||
// .border_color(cx.theme().colors().border)
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("project-panel-outer", cx)
|
||||
// .side(PanelSide::Left)
|
||||
// .child(ProjectPanel::new("project-panel-inner")),
|
||||
// )
|
||||
// .filter(|_| self.is_project_panel_open()),
|
||||
// )
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("collab-panel-outer", cx)
|
||||
// .child(CollabPanel::new("collab-panel-inner"))
|
||||
// .side(PanelSide::Left),
|
||||
// )
|
||||
// .filter(|_| self.is_collab_panel_open()),
|
||||
// )
|
||||
// // .child(NotificationToast::new(
|
||||
// // "maxbrunsfeld has requested to add you as a contact.".into(),
|
||||
// // ))
|
||||
// .child(
|
||||
// v_stack()
|
||||
// .flex_1()
|
||||
// .h_full()
|
||||
// .child(div().flex().flex_1().child(root_group))
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("terminal-panel", cx)
|
||||
// .child(Terminal::new())
|
||||
// .allowed_sides(PanelAllowedSides::BottomOnly)
|
||||
// .side(PanelSide::Bottom),
|
||||
// )
|
||||
// .filter(|_| self.is_terminal_open()),
|
||||
// ),
|
||||
// )
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("chat-panel-outer", cx)
|
||||
// .side(PanelSide::Right)
|
||||
// .child(ChatPanel::new("chat-panel-inner").messages(vec![
|
||||
// ChatMessage::new(
|
||||
// "osiewicz".to_string(),
|
||||
// "is this thing on?".to_string(),
|
||||
// DateTime::parse_from_rfc3339("2023-09-27T15:40:52.707Z")
|
||||
// .unwrap()
|
||||
// .naive_local(),
|
||||
// ),
|
||||
// ChatMessage::new(
|
||||
// "maxdeviant".to_string(),
|
||||
// "Reading you loud and clear!".to_string(),
|
||||
// DateTime::parse_from_rfc3339("2023-09-28T15:40:52.707Z")
|
||||
// .unwrap()
|
||||
// .naive_local(),
|
||||
// ),
|
||||
// ])),
|
||||
// )
|
||||
// .filter(|_| self.is_chat_panel_open()),
|
||||
// )
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("notifications-panel-outer", cx)
|
||||
// .side(PanelSide::Right)
|
||||
// .child(NotificationsPanel::new("notifications-panel-inner")),
|
||||
// )
|
||||
// .filter(|_| self.is_notifications_panel_open()),
|
||||
// )
|
||||
// .children(
|
||||
// Some(
|
||||
// Panel::new("assistant-panel-outer", cx)
|
||||
// .child(AssistantPanel::new("assistant-panel-inner")),
|
||||
// )
|
||||
// .filter(|_| self.is_assistant_panel_open()),
|
||||
// ),
|
||||
// )
|
||||
// .child(StatusBar::new())
|
||||
// .when(self.debug.show_toast, |this| {
|
||||
// this.child(Toast::new(ToastOrigin::Bottom).child(Label::new("A toast")))
|
||||
// })
|
||||
// .children(
|
||||
// Some(
|
||||
// div()
|
||||
// .absolute()
|
||||
// .top(px(50.))
|
||||
// .left(px(640.))
|
||||
// .z_index(8)
|
||||
// .child(LanguageSelector::new("language-selector")),
|
||||
// )
|
||||
// .filter(|_| self.is_language_selector_open()),
|
||||
// )
|
||||
// .z_index(8)
|
||||
// // Debug
|
||||
// .child(
|
||||
// v_stack()
|
||||
// .z_index(9)
|
||||
// .absolute()
|
||||
// .top_20()
|
||||
// .left_1_4()
|
||||
// .w_40()
|
||||
// .gap_2()
|
||||
// .when(self.show_debug, |this| {
|
||||
// this.child(Button::<Workspace>::new("Toggle User Settings").on_click(
|
||||
// Arc::new(|workspace, cx| workspace.debug_toggle_user_settings(cx)),
|
||||
// ))
|
||||
// .child(
|
||||
// Button::<Workspace>::new("Toggle Toasts").on_click(Arc::new(
|
||||
// |workspace, cx| workspace.debug_toggle_toast(cx),
|
||||
// )),
|
||||
// )
|
||||
// .child(
|
||||
// Button::<Workspace>::new("Toggle Livestream").on_click(Arc::new(
|
||||
// |workspace, cx| workspace.debug_toggle_livestream(cx),
|
||||
// )),
|
||||
// )
|
||||
// })
|
||||
// .child(
|
||||
// Button::<Workspace>::new("Toggle Debug")
|
||||
// .on_click(Arc::new(|workspace, cx| workspace.toggle_debug(cx))),
|
||||
// ),
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
pub use stories::*;
|
||||
// #[cfg(feature = "stories")]
|
||||
// pub use stories::*;
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
mod stories {
|
||||
use super::*;
|
||||
use gpui::VisualContext;
|
||||
// #[cfg(feature = "stories")]
|
||||
// mod stories {
|
||||
// use super::*;
|
||||
// use gpui::VisualContext;
|
||||
|
||||
pub struct WorkspaceStory {
|
||||
workspace: View<Workspace>,
|
||||
}
|
||||
// pub struct WorkspaceStory {
|
||||
// workspace: View<Workspace>,
|
||||
// }
|
||||
|
||||
impl WorkspaceStory {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.build_view(|cx| Self {
|
||||
workspace: Workspace::view(cx),
|
||||
})
|
||||
}
|
||||
}
|
||||
// impl WorkspaceStory {
|
||||
// pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
// cx.build_view(|cx| Self {
|
||||
// workspace: Workspace::view(cx),
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Render<Self> for WorkspaceStory {
|
||||
type Element = Div<Self>;
|
||||
// impl Render for WorkspaceStory {
|
||||
// type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
div().child(self.workspace.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
// div().child(self.workspace.clone())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user