Checkpoint: Compiling after view type removal
This commit is contained in:
parent
c9c9db903d
commit
88ef74ec8f
44 changed files with 392 additions and 695 deletions
|
@ -1,20 +1,16 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use gpui2::img;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Avatar<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct Avatar {
|
||||
src: SharedString,
|
||||
shape: Shape,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Avatar<S> {
|
||||
impl Avatar {
|
||||
pub fn new(src: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
src: src.into(),
|
||||
shape: Shape::Circle,
|
||||
}
|
||||
|
@ -25,7 +21,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
|
|||
self
|
||||
}
|
||||
|
||||
fn render(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 mut img = img();
|
||||
|
@ -52,20 +48,16 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct AvatarStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct AvatarStory;
|
||||
|
||||
impl<S: 'static + Send + Sync> AvatarStory<S> {
|
||||
impl AvatarStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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::<_, Avatar<S>>(cx))
|
||||
.child(Story::title_for::<_, Avatar>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Avatar::new(
|
||||
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui2::{div, DefiniteLength, Hsla, MouseButton, WindowContext};
|
||||
|
@ -49,21 +48,23 @@ impl ButtonVariant {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ClickHandler<S> = Arc<dyn Fn(&mut S, &mut ViewContext<S>) + 'static + Send + Sync>;
|
||||
pub type ClickHandler<S> = Arc<dyn Fn(&mut S, &mut ViewContext<S>) + Send + Sync>;
|
||||
|
||||
struct ButtonHandlers<S: 'static + Send + Sync> {
|
||||
struct ButtonHandlers<S: 'static> {
|
||||
click: Option<ClickHandler<S>>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Default for ButtonHandlers<S> {
|
||||
unsafe impl<S> Send for ButtonHandlers<S> {}
|
||||
unsafe impl<S> Sync for ButtonHandlers<S> {}
|
||||
|
||||
impl<S: 'static> Default for ButtonHandlers<S> {
|
||||
fn default() -> Self {
|
||||
Self { click: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Button<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct Button<S: 'static> {
|
||||
disabled: bool,
|
||||
handlers: ButtonHandlers<S>,
|
||||
icon: Option<Icon>,
|
||||
|
@ -73,10 +74,9 @@ pub struct Button<S: 'static + Send + Sync> {
|
|||
width: Option<DefiniteLength>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Button<S> {
|
||||
impl<S: 'static> Button<S> {
|
||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
disabled: false,
|
||||
handlers: ButtonHandlers::default(),
|
||||
icon: None,
|
||||
|
@ -140,13 +140,13 @@ impl<S: 'static + Send + Sync> Button<S> {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_label(&self) -> Label<S> {
|
||||
fn render_label(&self) -> Label {
|
||||
Label::new(self.label.clone())
|
||||
.color(self.label_color())
|
||||
.line_height_style(LineHeightStyle::UILabel)
|
||||
}
|
||||
|
||||
fn render_icon(&self, icon_color: IconColor) -> Option<IconElement<S>> {
|
||||
fn render_icon(&self, icon_color: IconColor) -> Option<IconElement> {
|
||||
self.icon.map(|i| IconElement::new(i).color(icon_color))
|
||||
}
|
||||
|
||||
|
@ -194,20 +194,16 @@ impl<S: 'static + Send + Sync> Button<S> {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct ButtonGroup<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
buttons: Vec<Button<S>>,
|
||||
pub struct ButtonGroup<V: 'static> {
|
||||
buttons: Vec<Button<V>>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> ButtonGroup<S> {
|
||||
pub fn new(buttons: Vec<Button<S>>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
buttons,
|
||||
}
|
||||
impl<V: 'static> ButtonGroup<V> {
|
||||
pub fn new(buttons: Vec<Button<V>>) -> Self {
|
||||
Self { buttons }
|
||||
}
|
||||
|
||||
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 mut el = h_stack().text_size(ui_size(cx, 1.));
|
||||
|
||||
for button in self.buttons {
|
||||
|
@ -231,22 +227,18 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct ButtonStory<S: 'static + Send + Sync + Clone> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct ButtonStory;
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> ButtonStory<S> {
|
||||
impl ButtonStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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 states = InteractionState::iter();
|
||||
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Button<S>>(cx))
|
||||
.child(Story::title_for::<_, Button<V>>(cx))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::{prelude::*, v_stack, ButtonGroup};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Details<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct Details<V: 'static> {
|
||||
text: &'static str,
|
||||
meta: Option<&'static str>,
|
||||
actions: Option<ButtonGroup<S>>,
|
||||
actions: Option<ButtonGroup<V>>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Details<S> {
|
||||
impl<S: 'static> Details<S> {
|
||||
pub fn new(text: &'static str) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
text,
|
||||
meta: None,
|
||||
actions: None,
|
||||
|
@ -55,20 +51,16 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DetailsStory<S: 'static + Send + Sync + Clone> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct DetailsStory;
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> DetailsStory<S> {
|
||||
impl DetailsStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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::<_, Details<S>>(cx))
|
||||
.child(Story::title_for::<_, Details<V>>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Details::new("The quick brown fox jumps over the lazy dog"))
|
||||
.child(Story::label(cx, "With meta"))
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use gpui2::{svg, Hsla};
|
||||
use strum::EnumIter;
|
||||
|
||||
|
@ -149,17 +147,15 @@ impl Icon {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct IconElement<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct IconElement {
|
||||
icon: Icon,
|
||||
color: IconColor,
|
||||
size: IconSize,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> IconElement<S> {
|
||||
impl IconElement {
|
||||
pub fn new(icon: Icon) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
icon,
|
||||
color: IconColor::default(),
|
||||
size: IconSize::default(),
|
||||
|
@ -176,7 +172,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
|
|||
self
|
||||
}
|
||||
|
||||
fn render(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 fill = self.color.color(cx);
|
||||
let svg_size = match self.size {
|
||||
IconSize::Small => ui_size(cx, 12. / 14.),
|
||||
|
@ -203,22 +199,18 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct IconStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct IconStory;
|
||||
|
||||
impl<S: 'static + Send + Sync> IconStory<S> {
|
||||
impl IconStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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 icons = Icon::iter();
|
||||
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, IconElement<S>>(cx))
|
||||
.child(Story::title_for::<_, IconElement>(cx))
|
||||
.child(Story::label(cx, "All Icons"))
|
||||
.child(div().flex().gap_3().children(icons.map(IconElement::new)))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::Label;
|
||||
use crate::LabelColor;
|
||||
|
@ -12,8 +10,7 @@ pub enum InputVariant {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Input<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct Input {
|
||||
placeholder: SharedString,
|
||||
value: String,
|
||||
state: InteractionState,
|
||||
|
@ -22,10 +19,9 @@ pub struct Input<S: 'static + Send + Sync> {
|
|||
is_active: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Input<S> {
|
||||
impl Input {
|
||||
pub fn new(placeholder: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
placeholder: placeholder.into(),
|
||||
value: "".to_string(),
|
||||
state: InteractionState::default(),
|
||||
|
@ -60,7 +56,7 @@ impl<S: 'static + Send + Sync> Input<S> {
|
|||
self
|
||||
}
|
||||
|
||||
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
|
||||
fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
|
||||
let theme = theme(cx);
|
||||
|
||||
let (input_bg, input_hover_bg, input_active_bg) = match self.variant {
|
||||
|
@ -121,20 +117,16 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct InputStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct InputStory;
|
||||
|
||||
impl<S: 'static + Send + Sync> InputStory<S> {
|
||||
impl InputStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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::<_, Input<S>>(cx))
|
||||
.child(Story::title_for::<_, Input>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(div().flex().child(Input::new("Search")))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use gpui2::{relative, Hsla, WindowContext};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
|
@ -49,18 +47,16 @@ pub enum LineHeightStyle {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Label<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct Label {
|
||||
label: SharedString,
|
||||
line_height_style: LineHeightStyle,
|
||||
color: LabelColor,
|
||||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Label<S> {
|
||||
impl Label {
|
||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
label: label.into(),
|
||||
line_height_style: LineHeightStyle::default(),
|
||||
color: LabelColor::Default,
|
||||
|
@ -83,7 +79,7 @@ impl<S: 'static + Send + Sync> Label<S> {
|
|||
self
|
||||
}
|
||||
|
||||
fn render(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()
|
||||
.when(self.strikethrough, |this| {
|
||||
this.relative().child(
|
||||
|
@ -106,18 +102,16 @@ impl<S: 'static + Send + Sync> Label<S> {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct HighlightedLabel<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
pub struct HighlightedLabel {
|
||||
label: SharedString,
|
||||
color: LabelColor,
|
||||
highlight_indices: Vec<usize>,
|
||||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> HighlightedLabel<S> {
|
||||
impl HighlightedLabel {
|
||||
pub fn new(label: impl Into<SharedString>, highlight_indices: Vec<usize>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
label: label.into(),
|
||||
color: LabelColor::Default,
|
||||
highlight_indices,
|
||||
|
@ -135,7 +129,7 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
|
|||
self
|
||||
}
|
||||
|
||||
fn render(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 highlight_color = theme.text_accent;
|
||||
|
@ -212,20 +206,16 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct LabelStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct LabelStory;
|
||||
|
||||
impl<S: 'static + Send + Sync> LabelStory<S> {
|
||||
impl LabelStory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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::<_, Label<S>>(cx))
|
||||
.child(Story::title_for::<_, Label>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
.child(Label::new("Hello, world!"))
|
||||
.child(Story::label(cx, "Highlighted"))
|
||||
|
|
|
@ -14,18 +14,18 @@ pub trait Stack: Styled + Sized {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Stack for Div<S> {}
|
||||
impl<S: 'static> Stack for Div<S> {}
|
||||
|
||||
/// Horizontally stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_row()`, `items_center()`
|
||||
pub fn h_stack<S: 'static + Send + Sync>() -> Div<S> {
|
||||
pub fn h_stack<S: 'static>() -> Div<S> {
|
||||
div().h_stack()
|
||||
}
|
||||
|
||||
/// Vertically stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_col()`
|
||||
pub fn v_stack<S: 'static + Send + Sync>() -> Div<S> {
|
||||
pub fn v_stack<S: 'static>() -> Div<S> {
|
||||
div().v_stack()
|
||||
}
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct ToolDivider<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
pub struct ToolDivider;
|
||||
|
||||
impl<S: 'static + Send + Sync> ToolDivider<S> {
|
||||
impl ToolDivider {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
}
|
||||
Self
|
||||
}
|
||||
|
||||
fn render(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().w_px().h_3().bg(theme.border)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue