Checkpoint

This commit is contained in:
Marshall Bowers 2023-10-12 12:18:35 -04:00
parent 207d843aee
commit 262f5886a4
44 changed files with 237 additions and 148 deletions

View file

@ -196,7 +196,7 @@ impl<V: 'static + Send + Sync, Marker: 'static + Send + Sync> Styled for Div<V,
impl<V: Send + Sync + 'static> IdentifiedElement for Div<V, HasId> {} impl<V: Send + Sync + 'static> IdentifiedElement for Div<V, HasId> {}
impl<V: Send + Sync + 'static> Interactive<V> for Div<V, HasId> { impl<V: Send + Sync + 'static, Marker: 'static + Send + Sync> Interactive<V> for Div<V, Marker> {
fn listeners(&mut self) -> &mut MouseEventListeners<V> { fn listeners(&mut self) -> &mut MouseEventListeners<V> {
&mut self.listeners &mut self.listeners
} }

View file

@ -6,12 +6,35 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput); let ast = parse_macro_input!(input as DeriveInput);
let type_name = ast.ident; let type_name = ast.ident;
let mut logme = false;
let mut state_type = quote! { () }; let mut state_type = quote! { () };
for param in &ast.generics.params { for param in &ast.generics.params {
if let GenericParam::Type(type_param) = param { if let GenericParam::Type(type_param) = param {
let type_ident = &type_param.ident; let type_ident = &type_param.ident;
state_type = quote! {#type_ident}; state_type = quote! {#type_ident};
break;
}
}
let attrs = &ast.attrs;
for attr in attrs {
if attr.path.is_ident("element") {
match attr.parse_meta() {
Ok(syn::Meta::List(i)) => {
for nested_meta in i.nested {
if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested_meta {
if nv.path.is_ident("view_state") {
if let syn::Lit::Str(lit_str) = nv.lit {
state_type = lit_str.value().parse().unwrap();
logme = true;
}
}
}
}
}
_ => (),
}
} }
} }
@ -30,29 +53,32 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
fn layout( fn layout(
&mut self, &mut self,
state: &mut #state_type, view_state: &mut Self::ViewState,
element_state: Option<Self::ElementState>, element_state: Option<Self::ElementState>,
cx: &mut gpui3::ViewContext<Self::ViewState>, cx: &mut gpui3::ViewContext<Self::ViewState>,
) -> (gpui3::LayoutId, Self::ElementState) { ) -> (gpui3::LayoutId, Self::ElementState) {
use gpui3::IntoAnyElement; use gpui3::IntoAnyElement;
let mut rendered_element = self.render(cx).into_any(); let mut rendered_element = self.render(view_state, cx).into_any();
let layout_id = rendered_element.layout(state, cx); let layout_id = rendered_element.layout(view_state, cx);
(layout_id, rendered_element) (layout_id, rendered_element)
} }
fn paint( fn paint(
&mut self, &mut self,
bounds: gpui3::Bounds<gpui3::Pixels>, bounds: gpui3::Bounds<gpui3::Pixels>,
state: &mut Self::ViewState, view_state: &mut Self::ViewState,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut gpui3::ViewContext<Self::ViewState>, cx: &mut gpui3::ViewContext<Self::ViewState>,
) { ) {
// TODO: Where do we get the `offset` from? element_state.paint(view_state, None, cx)
element_state.paint(state, None, cx)
} }
} }
}; };
if logme {
println!(">>>>>>>>>>>>>>>>>>>>>>\n{}", gen);
}
gen.into() gen.into()
} }

View file

@ -8,7 +8,7 @@ pub fn style_helpers(args: TokenStream) -> TokenStream {
style_helpers::style_helpers(args) style_helpers::style_helpers(args)
} }
#[proc_macro_derive(Element, attributes(element_crate))] #[proc_macro_derive(Element, attributes(element))]
pub fn derive_element(input: TokenStream) -> TokenStream { pub fn derive_element(input: TokenStream) -> TokenStream {
derive_element::derive_element(input) derive_element::derive_element(input)
} }

View file

@ -18,9 +18,9 @@ impl<S: 'static + Send + Sync + Clone> KitchenSinkStory<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let element_stories = ElementStory::iter().map(|selector| selector.story()); let element_stories = ElementStory::iter().map(|selector| selector.story());
let component_stories = ComponentStory::iter().map(|selector| selector.story()); let component_stories = ComponentStory::iter().map(|selector| selector.story(cx));
Story::container(cx) Story::container(cx)
.overflow_y_scroll(ScrollState::default()) .overflow_y_scroll(ScrollState::default())

View file

@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ZIndexStory<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title(cx, "z-index")) .child(Story::title(cx, "z-index"))
.child( .child(
@ -103,7 +103,7 @@ impl<S: 'static + Send + Sync> ZIndexExample<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div() div()
.relative() .relative()
.size_full() .size_full()

View file

@ -65,7 +65,7 @@ pub enum ComponentStory {
} }
impl ComponentStory { impl ComponentStory {
pub fn story<S: 'static + Send + Sync + Clone>(&self) -> AnyElement<S> { pub fn story<S: 'static + Send + Sync + Clone>(&self, cx: &mut WindowContext) -> AnyElement<S> {
match self { match self {
Self::AssistantPanel => ui::AssistantPanelStory::new().into_any(), Self::AssistantPanel => ui::AssistantPanelStory::new().into_any(),
Self::Buffer => ui::BufferStory::new().into_any(), Self::Buffer => ui::BufferStory::new().into_any(),
@ -90,7 +90,7 @@ impl ComponentStory {
Self::Toast => ui::ToastStory::new().into_any(), Self::Toast => ui::ToastStory::new().into_any(),
Self::Toolbar => ui::ToolbarStory::new().into_any(), Self::Toolbar => ui::ToolbarStory::new().into_any(),
Self::TrafficLights => ui::TrafficLightsStory::new().into_any(), Self::TrafficLights => ui::TrafficLightsStory::new().into_any(),
Self::Workspace => ui::WorkspaceStory::new().into_any(), Self::Workspace => ui::workspace_story(cx).into_any().into_any(),
} }
} }
} }
@ -131,10 +131,10 @@ impl FromStr for StorySelector {
} }
impl StorySelector { impl StorySelector {
pub fn story<S: 'static + Send + Sync + Clone>(&self) -> AnyElement<S> { pub fn story<S: 'static + Send + Sync + Clone>(&self, cx: &mut WindowContext) -> AnyElement<S> {
match self { match self {
Self::Element(element_story) => element_story.story(), Self::Element(element_story) => element_story.story(),
Self::Component(component_story) => component_story.story(), Self::Component(component_story) => component_story.story(cx),
Self::KitchenSink => crate::stories::kitchen_sink::KitchenSinkStory::new().into_any(), Self::KitchenSink => crate::stories::kitchen_sink::KitchenSinkStory::new().into_any(),
} }
} }

View file

@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync + Clone> AssistantPanel<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
struct PanelPayload { struct PanelPayload {
@ -110,7 +110,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, AssistantPanel<S>>(cx)) .child(Story::title_for::<_, AssistantPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -31,7 +31,7 @@ impl<S: 'static + Send + Sync + Clone> Breadcrumb<S> {
.text_color(HighlightColor::Default.hsla(theme)) .text_color(HighlightColor::Default.hsla(theme))
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view_state: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let symbols_len = self.symbols.len(); let symbols_len = self.symbols.len();
@ -99,7 +99,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view_state: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -224,7 +224,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let rows = self.render_rows(cx); let rows = self.render_rows(cx);
@ -263,7 +263,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync + Clone> ChatPanel<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -89,7 +89,7 @@ impl<S: 'static + Send + Sync + Clone> ChatMessage<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div() div()
.flex() .flex()
.flex_col() .flex_col()
@ -130,7 +130,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ChatPanel<S>>(cx)) .child(Story::title_for::<_, ChatPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -23,7 +23,7 @@ impl<S: 'static + Send + Sync + Clone> CollabPanel<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let color = ThemeColor::new(cx); let color = ThemeColor::new(cx);
@ -180,7 +180,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CollabPanel<S>>(cx)) .child(Story::title_for::<_, CollabPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> CommandPalette<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div().child( div().child(
Palette::new(self.scroll_state.clone()) Palette::new(self.scroll_state.clone())
.items(example_editor_actions()) .items(example_editor_actions())
@ -49,7 +49,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CommandPalette<S>>(cx)) .child(Story::title_for::<_, CommandPalette<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -43,7 +43,7 @@ impl<S: 'static + Send + Sync + Clone> ContextMenu<S> {
items: items.into_iter().collect(), items: items.into_iter().collect(),
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -87,7 +87,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ContextMenu<S>>(cx)) .child(Story::title_for::<_, ContextMenu<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -20,7 +20,7 @@ impl<S: 'static + Send + Sync + Clone> EditorPane<S> {
Self { editor } Self { editor }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
struct LeftItemsPayload { struct LeftItemsPayload {
path: PathBuf, path: PathBuf,
symbols: Vec<Symbol>, symbols: Vec<Symbol>,

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> Facepile<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let player_count = self.players.len(); let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(ix, player)| { let player_list = self.players.iter().enumerate().map(|(ix, player)| {
@ -52,7 +52,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let players = static_players(); let players = static_players();
Story::container(cx) Story::container(cx)

View file

@ -66,7 +66,7 @@ impl<S: 'static + Send + Sync> IconButton<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let icon_color = match (self.state, self.color) { let icon_color = match (self.state, self.color) {
@ -80,9 +80,9 @@ impl<S: 'static + Send + Sync> IconButton<S> {
} }
if let Some(click_handler) = self.handlers.click.clone() { if let Some(click_handler) = self.handlers.click.clone() {
// div = div.on_click(MouseButton::Left, move |state, event, cx| { div = div.on_mouse_down(MouseButton::Left, move |state, event, cx| {
// click_handler(state, cx); click_handler(state, cx);
// }); });
} }
div.w_7() div.w_7()

View file

@ -35,7 +35,7 @@ impl<S: 'static + Send + Sync + Clone> Keybinding<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div() div()
.flex() .flex()
.gap_2() .gap_2()
@ -72,7 +72,7 @@ impl<S: 'static + Send + Sync> Key<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -189,7 +189,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let all_modifier_permutations = ModifierKey::iter().permutations(2); let all_modifier_permutations = ModifierKey::iter().permutations(2);
Story::container(cx) Story::container(cx)

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> LanguageSelector<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div().child( div().child(
Palette::new(self.scroll_state.clone()) Palette::new(self.scroll_state.clone())
.items(vec![ .items(vec![
@ -60,7 +60,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, LanguageSelector<S>>(cx)) .child(Story::title_for::<_, LanguageSelector<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -92,7 +92,7 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
let system_color = SystemColor::new(); let system_color = SystemColor::new();
@ -164,7 +164,7 @@ impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
@ -237,11 +237,11 @@ impl<S: 'static + Send + Sync + Clone> From<ListSubHeader<S>> for ListItem<S> {
} }
impl<S: 'static + Send + Sync + Clone> ListItem<S> { impl<S: 'static + Send + Sync + Clone> ListItem<S> {
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
match self { match self {
ListItem::Entry(entry) => div().child(entry.render(cx)), ListItem::Entry(entry) => div().child(entry.render(view, cx)),
ListItem::Separator(separator) => div().child(separator.render(cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)),
ListItem::Header(header) => div().child(header.render(cx)), ListItem::Header(header) => div().child(header.render(view, cx)),
} }
} }
@ -346,7 +346,10 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
} }
} }
fn disclosure_control(&mut self, cx: &mut ViewContext<S>) -> Option<impl Element<ViewState = S>> { fn disclosure_control(
&mut self,
cx: &mut ViewContext<S>,
) -> Option<impl Element<ViewState = S>> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
@ -369,7 +372,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
let system_color = SystemColor::new(); let system_color = SystemColor::new();
@ -437,7 +440,7 @@ impl<S: 'static + Send + Sync> ListSeparator<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx); let color = ThemeColor::new(cx);
div().h_px().w_full().fill(color.border) div().h_px().w_full().fill(color.border)
@ -477,7 +480,7 @@ impl<S: 'static + Send + Sync + Clone> List<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -62,7 +62,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -47,7 +47,7 @@ impl<S: 'static + Send + Sync + Clone> Palette<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -134,7 +134,7 @@ impl<S: 'static + Send + Sync + Clone> PaletteItem<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -172,7 +172,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Palette<S>>(cx)) .child(Story::title_for::<_, Palette<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -100,7 +100,7 @@ impl<S: 'static + Send + Sync> Panel<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let token = token(); let token = token();
let theme = theme(cx); let theme = theme(cx);
@ -165,7 +165,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Panel<S>>(cx)) .child(Story::title_for::<_, Panel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -48,7 +48,7 @@ impl<S: 'static + Send + Sync> Pane<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -89,7 +89,7 @@ impl<S: 'static + Send + Sync> PaneGroup<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
if !self.panes.is_empty() { if !self.panes.is_empty() {
@ -100,7 +100,7 @@ impl<S: 'static + Send + Sync> PaneGroup<S> {
.w_full() .w_full()
.h_full() .h_full()
.fill(theme.lowest.base.default.background) .fill(theme.lowest.base.default.background)
.children(self.panes.iter_mut().map(|pane| pane.render(cx))); .children(self.panes.iter_mut().map(|pane| pane.render(view, cx)));
if self.split_direction == SplitDirection::Horizontal { if self.split_direction == SplitDirection::Horizontal {
return el; return el;
@ -117,7 +117,7 @@ impl<S: 'static + Send + Sync> PaneGroup<S> {
.w_full() .w_full()
.h_full() .h_full()
.fill(theme.lowest.base.default.background) .fill(theme.lowest.base.default.background)
.children(self.groups.iter_mut().map(|group| group.render(cx))); .children(self.groups.iter_mut().map(|group| group.render(view, cx)));
if self.split_direction == SplitDirection::Horizontal { if self.split_direction == SplitDirection::Horizontal {
return el; return el;

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> PlayerStack<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let system_color = SystemColor::new(); let system_color = SystemColor::new();
let player = self.player_with_call_status.get_player(); let player = self.player_with_call_status.get_player();
self.player_with_call_status.get_call_status(); self.player_with_call_status.get_call_status();

View file

@ -20,7 +20,7 @@ impl<S: 'static + Send + Sync + Clone> ProjectPanel<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let color = ThemeColor::new(cx); let color = ThemeColor::new(cx);
@ -78,7 +78,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ProjectPanel<S>>(cx)) .child(Story::title_for::<_, ProjectPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> RecentProjects<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div().child( div().child(
Palette::new(self.scroll_state.clone()) Palette::new(self.scroll_state.clone())
.items(vec![ .items(vec![
@ -56,7 +56,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, RecentProjects<S>>(cx)) .child(Story::title_for::<_, RecentProjects<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -1,8 +1,7 @@
use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use crate::prelude::*;
use crate::{get_workspace_state, Button, Icon, IconButton, IconColor, ToolDivider}; use crate::{get_workspace_state, Button, Icon, IconButton, IconColor, ToolDivider};
use crate::{prelude::*, Workspace};
#[derive(Default, PartialEq)] #[derive(Default, PartialEq)]
pub enum Tool { pub enum Tool {
@ -30,17 +29,17 @@ impl Default for ToolGroup {
} }
#[derive(Element)] #[derive(Element)]
pub struct StatusBar<S: 'static + Send + Sync + Clone> { #[element(view_state = "Workspace")]
state_type: PhantomData<S>, pub struct StatusBar {
left_tools: Option<ToolGroup>, left_tools: Option<ToolGroup>,
right_tools: Option<ToolGroup>, right_tools: Option<ToolGroup>,
bottom_tools: Option<ToolGroup>, bottom_tools: Option<ToolGroup>,
} }
impl<S: 'static + Send + Sync + Clone> StatusBar<S> { impl StatusBar {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
state_type: PhantomData, // state_type: PhantomData,
left_tools: None, left_tools: None,
right_tools: None, right_tools: None,
bottom_tools: None, bottom_tools: None,
@ -83,7 +82,11 @@ impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(
&mut self,
view: &mut Workspace,
cx: &mut ViewContext<Workspace>,
) -> impl Element<ViewState = Workspace> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -94,34 +97,35 @@ impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
.justify_between() .justify_between()
.w_full() .w_full()
.fill(theme.lowest.base.default.background) .fill(theme.lowest.base.default.background)
.child(self.left_tools(&theme)) .child(self.left_tools(view, &theme))
.child(self.right_tools(&theme)) .child(self.right_tools(&theme))
} }
fn left_tools(&self, theme: &Theme) -> impl Element<ViewState = S> { fn left_tools(
let workspace_state = get_workspace_state(); &self,
workspace: &mut Workspace,
div() theme: &Theme,
) -> impl Element<ViewState = Workspace> {
div::<Workspace>()
.flex() .flex()
.items_center() .items_center()
.gap_1() .gap_1()
.child( .child(
IconButton::new(Icon::FileTree) IconButton::<Workspace>::new(Icon::FileTree)
.when(workspace_state.is_project_panel_open(), |this| { .when(workspace.is_project_panel_open(), |this| {
this.color(IconColor::Accent) this.color(IconColor::Accent)
}) })
.on_click(|_, cx| { .on_click(|workspace, cx| {
workspace_state.toggle_project_panel(); workspace.toggle_project_panel(cx);
cx.notify();
}), }),
) )
.child( .child(
IconButton::new(Icon::Hash) IconButton::<Workspace>::new(Icon::Hash)
.when(workspace_state.is_collab_panel_open(), |this| { .when(workspace.is_collab_panel_open(), |this| {
this.color(IconColor::Accent) this.color(IconColor::Accent)
}) })
.on_click(|_, cx| { .on_click(|workspace, cx| {
workspace_state.toggle_collab_panel(); workspace.toggle_collab_panel();
cx.notify(); cx.notify();
}), }),
) )
@ -129,7 +133,7 @@ impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
.child(IconButton::new(Icon::XCircle)) .child(IconButton::new(Icon::XCircle))
} }
fn right_tools(&self, theme: &Theme) -> impl Element<ViewState = S> { fn right_tools(&self, theme: &Theme) -> impl Element<ViewState = Workspace> {
let workspace_state = get_workspace_state(); let workspace_state = get_workspace_state();
div() div()

View file

@ -74,7 +74,7 @@ impl<S: 'static + Send + Sync + Clone> Tab<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict;
let is_deleted = self.fs_status == FileSystemStatus::Deleted; let is_deleted = self.fs_status == FileSystemStatus::Deleted;
@ -157,7 +157,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let git_statuses = GitStatus::iter(); let git_statuses = GitStatus::iter();
let fs_statuses = FileSystemStatus::iter(); let fs_statuses = FileSystemStatus::iter();

View file

@ -23,7 +23,7 @@ impl<S: 'static + Send + Sync + Clone> TabBar<S> {
self.scroll_state = scroll_state; self.scroll_state = scroll_state;
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let can_navigate_back = true; let can_navigate_back = true;
let can_navigate_forward = false; let can_navigate_forward = false;
@ -105,7 +105,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TabBar<S>>(cx)) .child(Story::title_for::<_, TabBar<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -18,7 +18,7 @@ impl<S: 'static + Send + Sync + Clone> Terminal<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let can_navigate_back = true; let can_navigate_back = true;
@ -109,7 +109,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Terminal<S>>(cx)) .child(Story::title_for::<_, Terminal<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> ThemeSelector<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
div().child( div().child(
Palette::new(self.scroll_state.clone()) Palette::new(self.scroll_state.clone())
.items(vec![ .items(vec![
@ -61,7 +61,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ThemeSelector<S>>(cx)) .child(Story::title_for::<_, ThemeSelector<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -46,7 +46,7 @@ impl<S: 'static + Send + Sync + Clone> TitleBar<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
// let has_focus = cx.window_is_active(); // let has_focus = cx.window_is_active();
let has_focus = true; let has_focus = true;
@ -139,7 +139,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TitleBar<S>>(cx)) .child(Story::title_for::<_, TitleBar<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -41,7 +41,7 @@ impl<S: 'static + Send + Sync> Toast<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx); let color = ThemeColor::new(cx);
let mut div = div(); let mut div = div();
@ -89,7 +89,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Toast<S>>(cx)) .child(Story::title_for::<_, Toast<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -27,7 +27,7 @@ impl<S: 'static + Send + Sync> Toolbar<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -74,7 +74,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
struct LeftItemsPayload { struct LeftItemsPayload {

View file

@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> TrafficLight<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let system_color = SystemColor::new(); let system_color = SystemColor::new();
@ -60,7 +60,7 @@ impl<S: 'static + Send + Sync> TrafficLights<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let token = token(); let token = token();
@ -104,7 +104,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TrafficLights<S>>(cx)) .child(Story::title_for::<_, TrafficLights<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock}; use std::sync::{Arc, OnceLock};
use chrono::DateTime; use chrono::DateTime;
use gpui3::{px, relative, rems, Size}; use gpui3::{px, relative, rems, view, Context, Size, View};
use crate::prelude::*; use crate::prelude::*;
use crate::{ use crate::{
@ -105,19 +105,26 @@ pub fn get_workspace_state() -> &'static WorkspaceState {
state state
} }
#[derive(Element)] // #[derive(Element)]
pub struct WorkspaceElement<S: 'static + Send + Sync + Clone> { #[derive(Clone)]
state_type: PhantomData<S>, pub struct Workspace {
show_project_panel: bool,
show_collab_panel: bool,
left_panel_scroll_state: ScrollState, left_panel_scroll_state: ScrollState,
right_panel_scroll_state: ScrollState, right_panel_scroll_state: ScrollState,
tab_bar_scroll_state: ScrollState, tab_bar_scroll_state: ScrollState,
bottom_panel_scroll_state: ScrollState, bottom_panel_scroll_state: ScrollState,
} }
impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> { fn workspace<P: 'static>(cx: &mut WindowContext) -> View<Workspace, P> {
view(cx.entity(|cx| Workspace::new()), Workspace::render)
}
impl Workspace {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
state_type: PhantomData, show_project_panel: true,
show_collab_panel: false,
left_panel_scroll_state: ScrollState::default(), left_panel_scroll_state: ScrollState::default(),
right_panel_scroll_state: ScrollState::default(), right_panel_scroll_state: ScrollState::default(),
tab_bar_scroll_state: ScrollState::default(), tab_bar_scroll_state: ScrollState::default(),
@ -125,7 +132,31 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
} }
} }
pub fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { pub fn is_project_panel_open(&self) -> bool {
dbg!(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;
dbg!(self.show_project_panel);
cx.notify();
}
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;
self.show_project_panel = false;
}
pub fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
let theme = theme(cx).clone(); let theme = theme(cx).clone();
let workspace_state = get_workspace_state(); let workspace_state = get_workspace_state();
@ -341,21 +372,23 @@ pub use stories::*;
mod stories { mod stories {
use super::*; use super::*;
#[derive(Element)] // #[derive(Element)]
pub struct WorkspaceStory<S: 'static + Send + Sync + Clone> { // pub struct WorkspaceStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, // state_type: PhantomData<S>,
// }
pub struct WorkspaceStory<P> {
workspace: View<Workspace, P>,
} }
impl<S: 'static + Send + Sync + Clone> WorkspaceStory<S> { pub fn workspace_story<P: 'static + Send + Sync>(cx: &mut WindowContext) -> View<WorkspaceStory<P>, P> {
pub fn new() -> Self { todo!()
Self { // let workspace = workspace::<P>(cx);
state_type: PhantomData, // view(
} // cx.entity(|cx| WorkspaceStory {
} // workspace,
// }),
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { // |view, cx| view.workspace.clone(),
// Just render the workspace without any story boilerplate. // )
WorkspaceElement::new()
}
} }
} }

View file

@ -13,6 +13,16 @@ pub trait ElementExt<S: 'static + Send + Sync>: Element<ViewState = S> {
} }
self self
} }
// fn when_some<T, U>(mut self, option: Option<T>, then: impl FnOnce(Self, T) -> U) -> U
// where
// Self: Sized,
// {
// if let Some(value) = option {
// self = then(self, value);
// }
// self
// }
} }
impl<S: 'static + Send + Sync, E: Element<ViewState = S>> ElementExt<S> for E {} impl<S: 'static + Send + Sync, E: Element<ViewState = S>> ElementExt<S> for E {}

View file

@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let mut img = img(); let mut img = img();
@ -64,7 +64,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Avatar<S>>(cx)) .child(Story::title_for::<_, Avatar<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -1,7 +1,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use gpui3::{DefiniteLength, Hsla, Interactive, MouseButton, WindowContext}; use gpui3::{DefiniteLength, Hsla, WindowContext};
use crate::prelude::*; use crate::prelude::*;
use crate::{h_stack, theme, Icon, IconColor, IconElement, Label, LabelColor, LabelSize}; use crate::{h_stack, theme, Icon, IconColor, IconElement, Label, LabelColor, LabelSize};
@ -160,7 +160,7 @@ impl<S: 'static + Send + Sync + Clone> Button<S> {
self.icon.map(|i| IconElement::new(i).color(icon_color)) self.icon.map(|i| IconElement::new(i).color(icon_color))
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let icon_color = self.icon_color(); let icon_color = self.icon_color();
let system_color = SystemColor::new(); let system_color = SystemColor::new();
@ -195,11 +195,20 @@ impl<S: 'static + Send + Sync + Clone> Button<S> {
el = el.w(width).justify_center(); el = el.w(width).justify_center();
} }
if let Some(click_handler) = self.handlers.click.clone() { // el.when_some(self.handlers.click.clone(), |el, click_handler| {
// el = el.on_click(MouseButton::Left, move |state, event, cx| { // el.id(0)
// click_handler(state, cx); // .on_click(MouseButton::Left, move |state, event, cx| {
// }); // click_handler(state, cx);
} // })
// });
// if let Some(click_handler) = self.handlers.click.clone() {
// el = el
// .id(0)
// .on_click(MouseButton::Left, move |state, event, cx| {
// click_handler(state, cx);
// });
// }
el el
} }
@ -229,7 +238,11 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(
&mut self,
_view: &mut S,
cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> {
let states = InteractionState::iter(); let states = InteractionState::iter();
Story::container(cx) Story::container(cx)

View file

@ -24,7 +24,7 @@ impl<S: 'static + Send + Sync + Clone> Details<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -60,7 +60,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Details<S>>(cx)) .child(Story::title_for::<_, Details<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -170,7 +170,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let fill = self.color.color(theme); let fill = self.color.color(theme);
@ -206,7 +206,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let icons = Icon::iter(); let icons = Icon::iter();
Story::container(cx) Story::container(cx)

View file

@ -45,7 +45,7 @@ impl<S: 'static + Send + Sync> Input<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let text_el; let text_el;
@ -128,7 +128,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx)) .child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -90,7 +90,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
self self
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
let highlight_color = theme.lowest.accent.default.foreground; let highlight_color = theme.lowest.accent.default.foreground;
@ -185,7 +185,7 @@ mod stories {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Label<S>>(cx)) .child(Story::title_for::<_, Label<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -15,7 +15,7 @@ impl<S: 'static + Send + Sync> ToolDivider<S> {
} }
} }
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx); let theme = theme(cx);
div().w_px().h_3().fill(theme.lowest.base.default.border) div().w_px().h_3().fill(theme.lowest.base.default.border)