Rename S type to V

This commit is contained in:
Marshall Bowers 2023-10-26 15:54:43 +02:00
parent 8a70ef3e8f
commit 1887f3b594
34 changed files with 140 additions and 152 deletions

View file

@ -154,7 +154,7 @@ impl Buffer {
self
}
fn render_row<S: 'static>(row: BufferRow, cx: &WindowContext) -> impl Component<S> {
fn render_row<V: 'static>(row: BufferRow, cx: &WindowContext) -> impl Component<V> {
let theme = theme(cx);
let line_background = if row.current {
@ -204,7 +204,7 @@ impl Buffer {
}))
}
fn render_rows<S: 'static>(&self, cx: &WindowContext) -> Vec<impl Component<S>> {
fn render_rows<V: 'static>(&self, cx: &WindowContext) -> Vec<impl Component<V>> {
match &self.rows {
Some(rows) => rows
.rows
@ -215,7 +215,7 @@ impl Buffer {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let rows = self.render_rows(cx);
@ -250,7 +250,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
Story::container(cx)

View file

@ -22,7 +22,7 @@ impl ChatPanel {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div()
.id(self.element_id.clone())
.flex()
@ -84,7 +84,7 @@ impl ChatMessage {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div()
.flex()
.flex_col()
@ -121,7 +121,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, ChatPanel>(cx))
.child(Story::label(cx, "Default"))

View file

@ -14,7 +14,7 @@ impl CollabPanel {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
v_stack()
@ -101,7 +101,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, CollabPanel>(cx))
.child(Story::label(cx, "Default"))

View file

@ -11,7 +11,7 @@ impl CommandPalette {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().id(self.id.clone()).child(
Palette::new("palette")
.items(example_editor_actions())
@ -39,7 +39,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, CommandPalette>(cx))
.child(Story::label(cx, "Default"))

View file

@ -43,7 +43,7 @@ impl ContextMenu {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
v_stack()
@ -80,7 +80,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, ContextMenu>(cx))
.child(Story::label(cx, "Default"))

View file

@ -10,7 +10,7 @@ impl CopilotModal {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().id(self.id.clone()).child(
Modal::new("some-id")
.title("Connect Copilot to Zed")
@ -37,7 +37,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, CopilotModal>(cx))
.child(Story::label(cx, "Default"))

View file

@ -13,7 +13,7 @@ impl Facepile {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(ix, player)| {
let isnt_last = ix < player_count - 1;
@ -43,7 +43,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let players = static_players();
Story::container(cx)

View file

@ -5,27 +5,27 @@ use gpui2::MouseButton;
use crate::{h_stack, prelude::*};
use crate::{ClickHandler, Icon, IconColor, IconElement};
struct IconButtonHandlers<S: 'static> {
click: Option<ClickHandler<S>>,
struct IconButtonHandlers<V: 'static> {
click: Option<ClickHandler<V>>,
}
impl<S: 'static> Default for IconButtonHandlers<S> {
impl<V: 'static> Default for IconButtonHandlers<V> {
fn default() -> Self {
Self { click: None }
}
}
#[derive(Component)]
pub struct IconButton<S: 'static> {
pub struct IconButton<V: 'static> {
id: ElementId,
icon: Icon,
color: IconColor,
variant: ButtonVariant,
state: InteractionState,
handlers: IconButtonHandlers<S>,
handlers: IconButtonHandlers<V>,
}
impl<S: 'static> IconButton<S> {
impl<V: 'static> IconButton<V> {
pub fn new(id: impl Into<ElementId>, icon: Icon) -> Self {
Self {
id: id.into(),
@ -57,12 +57,12 @@ impl<S: 'static> IconButton<S> {
self
}
pub fn on_click(mut self, handler: impl 'static + Fn(&mut S, &mut ViewContext<S>) + Send + Sync) -> Self {
pub fn on_click(mut self, handler: impl 'static + Fn(&mut V, &mut ViewContext<V>) + Send + Sync) -> Self {
self.handlers.click = Some(Arc::new(handler));
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let icon_color = match (self.state, self.color) {

View file

@ -29,7 +29,7 @@ impl Keybinding {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div()
.flex()
.gap_2()
@ -59,7 +59,7 @@ impl Key {
Self { key: key.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
div()

View file

@ -11,7 +11,7 @@ impl LanguageSelector {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().id(self.id.clone()).child(
Palette::new("palette")
.items(vec![
@ -50,7 +50,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, LanguageSelector>(cx))
.child(Story::label(cx, "Default"))

View file

@ -55,7 +55,7 @@ impl ListHeader {
self
}
fn disclosure_control<S: 'static>(&self) -> Div<S> {
fn disclosure_control<V: 'static>(&self) -> Div<V> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable);
@ -88,7 +88,7 @@ impl ListHeader {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let is_toggleable = self.toggleable != Toggleable::NotToggleable;
@ -151,7 +151,7 @@ impl ListSubHeader {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
h_stack().flex_1().w_full().relative().py_1().child(
div()
.h_6()
@ -192,39 +192,39 @@ pub enum ListEntrySize {
}
#[derive(Component)]
pub enum ListItem<S: 'static> {
pub enum ListItem<V: 'static> {
Entry(ListEntry),
Details(ListDetailsEntry<S>),
Details(ListDetailsEntry<V>),
Separator(ListSeparator),
Header(ListSubHeader),
}
impl<S: 'static> From<ListEntry> for ListItem<S> {
impl<V: 'static> From<ListEntry> for ListItem<V> {
fn from(entry: ListEntry) -> Self {
Self::Entry(entry)
}
}
impl<S: 'static> From<ListDetailsEntry<S>> for ListItem<S> {
fn from(entry: ListDetailsEntry<S>) -> Self {
impl<V: 'static> From<ListDetailsEntry<V>> for ListItem<V> {
fn from(entry: ListDetailsEntry<V>) -> Self {
Self::Details(entry)
}
}
impl<S: 'static> From<ListSeparator> for ListItem<S> {
impl<V: 'static> From<ListSeparator> for ListItem<V> {
fn from(entry: ListSeparator) -> Self {
Self::Separator(entry)
}
}
impl<S: 'static> From<ListSubHeader> for ListItem<S> {
impl<V: 'static> From<ListSubHeader> for ListItem<V> {
fn from(entry: ListSubHeader) -> Self {
Self::Header(entry)
}
}
impl<S: 'static> ListItem<S> {
fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
impl<V: 'static> ListItem<V> {
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
match self {
ListItem::Entry(entry) => div().child(entry.render(view, cx)),
ListItem::Separator(separator) => div().child(separator.render(view, cx)),
@ -361,7 +361,7 @@ impl ListEntry {
}
}
fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(mut self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let settings = user_settings(cx);
let theme = theme(cx);
@ -417,29 +417,29 @@ impl ListEntry {
}
}
struct ListDetailsEntryHandlers<S: 'static> {
click: Option<ClickHandler<S>>,
struct ListDetailsEntryHandlers<V: 'static> {
click: Option<ClickHandler<V>>,
}
impl<S: 'static> Default for ListDetailsEntryHandlers<S> {
impl<V: 'static> Default for ListDetailsEntryHandlers<V> {
fn default() -> Self {
Self { click: None }
}
}
#[derive(Component)]
pub struct ListDetailsEntry<S: 'static> {
pub struct ListDetailsEntry<V: 'static> {
label: SharedString,
meta: Option<SharedString>,
left_content: Option<LeftContent>,
handlers: ListDetailsEntryHandlers<S>,
actions: Option<Vec<Button<S>>>,
handlers: ListDetailsEntryHandlers<V>,
actions: Option<Vec<Button<V>>>,
// TODO: make this more generic instead of
// specifically for notifications
seen: bool,
}
impl<S: 'static> ListDetailsEntry<S> {
impl<V: 'static> ListDetailsEntry<V> {
pub fn new(label: impl Into<SharedString>) -> Self {
Self {
label: label.into(),
@ -461,17 +461,17 @@ impl<S: 'static> ListDetailsEntry<S> {
self
}
pub fn on_click(mut self, handler: ClickHandler<S>) -> Self {
pub fn on_click(mut self, handler: ClickHandler<V>) -> Self {
self.handlers.click = Some(handler);
self
}
pub fn actions(mut self, actions: Vec<Button<S>>) -> Self {
pub fn actions(mut self, actions: Vec<Button<V>>) -> Self {
self.actions = Some(actions);
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let settings = user_settings(cx);
@ -531,15 +531,15 @@ impl ListSeparator {
}
#[derive(Component)]
pub struct List<S: 'static> {
items: Vec<ListItem<S>>,
pub struct List<V: 'static> {
items: Vec<ListItem<V>>,
empty_message: SharedString,
header: Option<ListHeader>,
toggleable: Toggleable,
}
impl<S: 'static> List<S> {
pub fn new(items: Vec<ListItem<S>>) -> Self {
impl<V: 'static> List<V> {
pub fn new(items: Vec<ListItem<V>>) -> Self {
Self {
items,
empty_message: "No items".into(),
@ -563,7 +563,7 @@ impl<S: 'static> List<S> {
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable);

View file

@ -4,15 +4,15 @@ use smallvec::SmallVec;
use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label};
#[derive(Component)]
pub struct Modal<S: 'static> {
pub struct Modal<V: 'static> {
id: ElementId,
title: Option<SharedString>,
primary_action: Option<Button<S>>,
secondary_action: Option<Button<S>>,
children: SmallVec<[AnyElement<S>; 2]>,
primary_action: Option<Button<V>>,
secondary_action: Option<Button<V>>,
children: SmallVec<[AnyElement<V>; 2]>,
}
impl<S: 'static> Modal<S> {
impl<V: 'static> Modal<V> {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
@ -28,17 +28,17 @@ impl<S: 'static> Modal<S> {
self
}
pub fn primary_action(mut self, action: Button<S>) -> Self {
pub fn primary_action(mut self, action: Button<V>) -> Self {
self.primary_action = Some(action);
self
}
pub fn secondary_action(mut self, action: Button<S>) -> Self {
pub fn secondary_action(mut self, action: Button<V>) -> Self {
self.secondary_action = Some(action);
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
v_stack()
@ -76,8 +76,8 @@ impl<S: 'static> Modal<S> {
}
}
impl<S: 'static> ParentElement<S> for Modal<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
impl<V: 'static> ParentElement<V> for Modal<V> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
&mut self.children
}
}

View file

@ -10,10 +10,7 @@ pub struct NotificationToast {
impl NotificationToast {
pub fn new(label: SharedString) -> Self {
Self {
label,
icon: None,
}
Self { label, icon: None }
}
pub fn icon<I>(mut self, icon: I) -> Self
@ -24,7 +21,7 @@ impl NotificationToast {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
h_stack()

View file

@ -1,4 +1,3 @@
use crate::{prelude::*, static_new_notification_items, static_read_notification_items};
use crate::{List, ListHeader};
@ -9,12 +8,10 @@ pub struct NotificationsPanel {
impl NotificationsPanel {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
}
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
div()

View file

@ -42,7 +42,7 @@ impl Palette {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
v_stack()
@ -131,7 +131,7 @@ impl PaletteItem {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div()
.flex()
.flex_row()

View file

@ -39,17 +39,17 @@ pub enum PanelSide {
use std::collections::HashSet;
#[derive(Component)]
pub struct Panel<S: 'static> {
pub struct Panel<V: 'static> {
id: ElementId,
current_side: PanelSide,
/// Defaults to PanelAllowedSides::LeftAndRight
allowed_sides: PanelAllowedSides,
initial_width: AbsoluteLength,
width: Option<AbsoluteLength>,
children: SmallVec<[AnyElement<S>; 2]>,
children: SmallVec<[AnyElement<V>; 2]>,
}
impl<S: 'static> Panel<S> {
impl<V: 'static> Panel<V> {
pub fn new(id: impl Into<ElementId>, cx: &mut WindowContext) -> Self {
let settings = user_settings(cx);
@ -92,7 +92,7 @@ impl<S: 'static> Panel<S> {
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let current_size = self.width.unwrap_or(self.initial_width);
@ -117,8 +117,8 @@ impl<S: 'static> Panel<S> {
}
}
impl<S: 'static> ParentElement<S> for Panel<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
impl<V: 'static> ParentElement<V> for Panel<V> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
&mut self.children
}
}
@ -140,9 +140,9 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, Panel<S>>(cx))
.child(Story::title_for::<_, Panel<V>>(cx))
.child(Story::label(cx, "Default"))
.child(
Panel::new("panel", cx).child(

View file

@ -13,7 +13,7 @@ impl PlayerStack {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let player = self.player_with_call_status.get_player();
self.player_with_call_status.get_call_status();

View file

@ -13,7 +13,7 @@ impl ProjectPanel {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
div()
@ -69,7 +69,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, ProjectPanel>(cx))
.child(Story::label(cx, "Default"))

View file

@ -11,7 +11,7 @@ impl RecentProjects {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().id(self.id.clone()).child(
Palette::new("palette")
.items(vec![
@ -46,7 +46,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, RecentProjects>(cx))
.child(Story::label(cx, "Default"))

View file

@ -23,7 +23,7 @@ impl TabBar {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let (can_navigate_back, can_navigate_forward) = self.can_navigate;
@ -104,7 +104,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, TabBar>(cx))
.child(Story::label(cx, "Default"))

View file

@ -11,7 +11,7 @@ impl Terminal {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let can_navigate_back = true;
@ -95,7 +95,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, Terminal>(cx))
.child(Story::label(cx, "Default"))

View file

@ -11,7 +11,7 @@ impl ThemeSelector {
Self { id: id.into() }
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().child(
Palette::new(self.id.clone())
.items(vec![
@ -51,7 +51,7 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, ThemeSelector>(cx))
.child(Story::label(cx, "Default"))

View file

@ -23,12 +23,12 @@ pub enum ToastOrigin {
///
/// Only one toast may be visible at a time.
#[derive(Component)]
pub struct Toast<S: 'static> {
pub struct Toast<V: 'static> {
origin: ToastOrigin,
children: SmallVec<[AnyElement<S>; 2]>,
children: SmallVec<[AnyElement<V>; 2]>,
}
impl<S: 'static> Toast<S> {
impl<V: 'static> Toast<V> {
pub fn new(origin: ToastOrigin) -> Self {
Self {
origin,
@ -36,7 +36,7 @@ impl<S: 'static> Toast<S> {
}
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let mut div = div();
@ -61,8 +61,8 @@ impl<S: 'static> Toast<S> {
}
}
impl<S: 'static> ParentElement<S> for Toast<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
impl<V: 'static> ParentElement<V> for Toast<V> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
&mut self.children
}
}
@ -84,9 +84,9 @@ mod stories {
Self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
Story::container(cx)
.child(Story::title_for::<_, Toast<S>>(cx))
.child(Story::title_for::<_, Toast<V>>(cx))
.child(Story::label(cx, "Default"))
.child(Toast::new(ToastOrigin::Bottom).child(Label::new("label")))
}

View file

@ -7,12 +7,12 @@ use crate::prelude::*;
pub struct ToolbarItem {}
#[derive(Component)]
pub struct Toolbar<S: 'static> {
left_items: SmallVec<[AnyElement<S>; 2]>,
right_items: SmallVec<[AnyElement<S>; 2]>,
pub struct Toolbar<V: 'static> {
left_items: SmallVec<[AnyElement<V>; 2]>,
right_items: SmallVec<[AnyElement<V>; 2]>,
}
impl<S: 'static> Toolbar<S> {
impl<V: 'static> Toolbar<V> {
pub fn new() -> Self {
Self {
left_items: SmallVec::new(),
@ -20,7 +20,7 @@ impl<S: 'static> Toolbar<S> {
}
}
pub fn left_item(mut self, child: impl Component<S>) -> Self
pub fn left_item(mut self, child: impl Component<V>) -> Self
where
Self: Sized,
{
@ -28,7 +28,7 @@ impl<S: 'static> Toolbar<S> {
self
}
pub fn left_items(mut self, iter: impl IntoIterator<Item = impl Component<S>>) -> Self
pub fn left_items(mut self, iter: impl IntoIterator<Item = impl Component<V>>) -> Self
where
Self: Sized,
{
@ -37,7 +37,7 @@ impl<S: 'static> Toolbar<S> {
self
}
pub fn right_item(mut self, child: impl Component<S>) -> Self
pub fn right_item(mut self, child: impl Component<V>) -> Self
where
Self: Sized,
{
@ -45,7 +45,7 @@ impl<S: 'static> Toolbar<S> {
self
}
pub fn right_items(mut self, iter: impl IntoIterator<Item = impl Component<S>>) -> Self
pub fn right_items(mut self, iter: impl IntoIterator<Item = impl Component<V>>) -> Self
where
Self: Sized,
{
@ -54,7 +54,7 @@ impl<S: 'static> Toolbar<S> {
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
div()

View file

@ -21,7 +21,7 @@ impl TrafficLight {
}
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let fill = match (self.window_has_focus, self.color) {
@ -52,7 +52,7 @@ impl TrafficLights {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div()
.flex()
.items_center()

View file

@ -1,6 +1,6 @@
use gpui2::Element;
pub trait ElementExt<S: 'static>: Element<S> {
pub trait ElementExt<V: 'static>: Element<V> {
// fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
// where
// Self: Sized,

View file

@ -50,23 +50,23 @@ impl ButtonVariant {
pub type ClickHandler<S> = Arc<dyn Fn(&mut S, &mut ViewContext<S>) + Send + Sync>;
struct ButtonHandlers<S: 'static> {
click: Option<ClickHandler<S>>,
struct ButtonHandlers<V: 'static> {
click: Option<ClickHandler<V>>,
}
unsafe impl<S> Send for ButtonHandlers<S> {}
unsafe impl<S> Sync for ButtonHandlers<S> {}
impl<S: 'static> Default for ButtonHandlers<S> {
impl<V: 'static> Default for ButtonHandlers<V> {
fn default() -> Self {
Self { click: None }
}
}
#[derive(Component)]
pub struct Button<S: 'static> {
pub struct Button<V: 'static> {
disabled: bool,
handlers: ButtonHandlers<S>,
handlers: ButtonHandlers<V>,
icon: Option<Icon>,
icon_position: Option<IconPosition>,
label: SharedString,
@ -74,7 +74,7 @@ pub struct Button<S: 'static> {
width: Option<DefiniteLength>,
}
impl<S: 'static> Button<S> {
impl<V: 'static> Button<V> {
pub fn new(label: impl Into<SharedString>) -> Self {
Self {
disabled: false,
@ -114,7 +114,7 @@ impl<S: 'static> Button<S> {
self
}
pub fn on_click(mut self, handler: ClickHandler<S>) -> Self {
pub fn on_click(mut self, handler: ClickHandler<V>) -> Self {
self.handlers.click = Some(handler);
self
}
@ -150,7 +150,7 @@ impl<S: 'static> Button<S> {
self.icon.map(|i| IconElement::new(i).color(icon_color))
}
pub fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
pub fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let icon_color = self.icon_color();
let mut button = h_stack()

View file

@ -7,7 +7,7 @@ pub struct Details<V: 'static> {
actions: Option<ButtonGroup<V>>,
}
impl<S: 'static> Details<S> {
impl<V: 'static> Details<V> {
pub fn new(text: &'static str) -> Self {
Self {
text,
@ -21,12 +21,12 @@ impl<S: 'static> Details<S> {
self
}
pub fn actions(mut self, actions: ButtonGroup<S>) -> Self {
pub fn actions(mut self, actions: ButtonGroup<V>) -> Self {
self.actions = Some(actions);
self
}
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
v_stack()

View file

@ -56,7 +56,7 @@ impl Input {
self
}
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let theme = theme(cx);
let (input_bg, input_hover_bg, input_active_bg) = match self.variant {

View file

@ -138,12 +138,12 @@ impl Player {
self
}
pub fn cursor_color<S: 'static>(&self, cx: &mut ViewContext<S>) -> Hsla {
pub fn cursor_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
let theme = theme(cx);
theme.players[self.index].cursor
}
pub fn selection_color<S: 'static>(&self, cx: &mut ViewContext<S>) -> Hsla {
pub fn selection_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
let theme = theme(cx);
theme.players[self.index].selection
}

View file

@ -14,18 +14,18 @@ pub trait Stack: Styled + Sized {
}
}
impl<S: 'static> Stack for Div<S> {}
impl<V: 'static> Stack for Div<V> {}
/// Horizontally stacks elements.
///
/// Sets `flex()`, `flex_row()`, `items_center()`
pub fn h_stack<S: 'static>() -> Div<S> {
pub fn h_stack<V: 'static>() -> Div<V> {
div().h_stack()
}
/// Vertically stacks elements.
///
/// Sets `flex()`, `flex_col()`
pub fn v_stack<S: 'static>() -> Div<S> {
pub fn v_stack<V: 'static>() -> Div<V> {
div().v_stack()
}

View file

@ -325,7 +325,7 @@ pub fn static_players_with_call_status() -> Vec<PlayerWithCallStatus> {
]
}
pub fn static_new_notification_items<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_new_notification_items<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListDetailsEntry::new("maxdeviant invited you to join a stream in #design.")
.meta("4 people in stream."),
@ -336,7 +336,7 @@ pub fn static_new_notification_items<S: 'static>() -> Vec<ListItem<S>> {
.collect()
}
pub fn static_read_notification_items<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_read_notification_items<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListDetailsEntry::new("mikaylamaki added you as a contact.").actions(vec![
Button::new("Decline"),
@ -352,7 +352,7 @@ pub fn static_read_notification_items<S: 'static>() -> Vec<ListItem<S>> {
.collect()
}
pub fn static_project_panel_project_items<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_project_panel_project_items<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListEntry::new(Label::new("zed"))
.left_icon(Icon::FolderOpen.into())
@ -479,7 +479,7 @@ pub fn static_project_panel_project_items<S: 'static>() -> Vec<ListItem<S>> {
.collect()
}
pub fn static_project_panel_single_items<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_project_panel_single_items<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListEntry::new(Label::new("todo.md"))
.left_icon(Icon::FileDoc.into())
@ -496,7 +496,7 @@ pub fn static_project_panel_single_items<S: 'static>() -> Vec<ListItem<S>> {
.collect()
}
pub fn static_collab_panel_current_call<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_collab_panel_current_call<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListEntry::new(Label::new("as-cii")).left_avatar("http://github.com/as-cii.png?s=50"),
ListEntry::new(Label::new("nathansobo"))
@ -509,7 +509,7 @@ pub fn static_collab_panel_current_call<S: 'static>() -> Vec<ListItem<S>> {
.collect()
}
pub fn static_collab_panel_channels<S: 'static>() -> Vec<ListItem<S>> {
pub fn static_collab_panel_channels<V: 'static>() -> Vec<ListItem<V>> {
vec![
ListEntry::new(Label::new("zed"))
.left_icon(Icon::Hash.into())

View file

@ -5,7 +5,7 @@ use crate::prelude::*;
pub struct Story {}
impl Story {
pub fn container<S: 'static>(cx: &mut ViewContext<S>) -> Div<S> {
pub fn container<V: 'static>(cx: &mut ViewContext<V>) -> Div<V> {
let theme = theme(cx);
div()
@ -18,10 +18,7 @@ impl Story {
.bg(theme.background)
}
pub fn title<S: 'static>(
cx: &mut ViewContext<S>,
title: &str,
) -> impl Component<S> {
pub fn title<V: 'static>(cx: &mut ViewContext<V>, title: &str) -> impl Component<V> {
let theme = theme(cx);
div()
@ -30,14 +27,11 @@ impl Story {
.child(title.to_owned())
}
pub fn title_for<S: 'static, T>(cx: &mut ViewContext<S>) -> impl Component<S> {
pub fn title_for<V: 'static, T>(cx: &mut ViewContext<V>) -> impl Component<V> {
Self::title(cx, std::any::type_name::<T>())
}
pub fn label<S: 'static>(
cx: &mut ViewContext<S>,
label: &str,
) -> impl Component<S> {
pub fn label<V: 'static>(cx: &mut ViewContext<V>, label: &str) -> impl Component<V> {
let theme = theme(cx);
div()