Clean up Element API and start on docs
This commit is contained in:
@@ -16,9 +16,9 @@ pub struct Avatar {
|
||||
}
|
||||
|
||||
impl RenderOnce for Avatar {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(mut self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(mut self, cx: &mut WindowContext) -> Self::Output {
|
||||
if self.image.style().corner_radii.top_left.is_none() {
|
||||
self = self.shape(Shape::Circle);
|
||||
}
|
||||
|
||||
@@ -136,9 +136,9 @@ impl ButtonCommon for Button {
|
||||
}
|
||||
|
||||
impl RenderOnce for Button {
|
||||
type Rendered = ButtonLike;
|
||||
type Output = ButtonLike;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
let is_disabled = self.base.disabled;
|
||||
let is_selected = self.base.selected;
|
||||
|
||||
|
||||
@@ -63,9 +63,9 @@ impl Selectable for ButtonIcon {
|
||||
}
|
||||
|
||||
impl RenderOnce for ButtonIcon {
|
||||
type Rendered = IconElement;
|
||||
type Output = IconElement;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
let icon = self
|
||||
.selected_icon
|
||||
.filter(|_| self.selected)
|
||||
|
||||
@@ -363,9 +363,9 @@ impl ParentElement for ButtonLike {
|
||||
}
|
||||
|
||||
impl RenderOnce for ButtonLike {
|
||||
type Rendered = Stateful<Div>;
|
||||
type Output = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
self.base
|
||||
.h_flex()
|
||||
.id(self.id.clone())
|
||||
|
||||
@@ -106,9 +106,9 @@ impl VisibleOnHover for IconButton {
|
||||
}
|
||||
|
||||
impl RenderOnce for IconButton {
|
||||
type Rendered = ButtonLike;
|
||||
type Output = ButtonLike;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
let is_disabled = self.base.disabled;
|
||||
let is_selected = self.base.selected;
|
||||
|
||||
|
||||
@@ -99,9 +99,9 @@ impl ButtonCommon for ToggleButton {
|
||||
}
|
||||
|
||||
impl RenderOnce for ToggleButton {
|
||||
type Rendered = ButtonLike;
|
||||
type Output = ButtonLike;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
let is_disabled = self.base.disabled;
|
||||
let is_selected = self.base.selected;
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ pub struct Checkbox {
|
||||
}
|
||||
|
||||
impl RenderOnce for Checkbox {
|
||||
type Rendered = gpui::Stateful<Div>;
|
||||
type Output = gpui::Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
let group_id = format!("checkbox_group_{:?}", self.id);
|
||||
|
||||
let icon = match self.checked {
|
||||
|
||||
@@ -232,9 +232,9 @@ impl ContextMenuItem {
|
||||
}
|
||||
|
||||
impl Render for ContextMenu {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
div().elevation_2(cx).flex().flex_row().child(
|
||||
v_stack()
|
||||
.min_w(px(200.))
|
||||
|
||||
@@ -28,9 +28,9 @@ impl Disclosure {
|
||||
}
|
||||
|
||||
impl RenderOnce for Disclosure {
|
||||
type Rendered = IconButton;
|
||||
type Output = IconButton;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
IconButton::new(
|
||||
self.id,
|
||||
match self.is_open {
|
||||
|
||||
@@ -31,9 +31,9 @@ pub struct Divider {
|
||||
}
|
||||
|
||||
impl RenderOnce for Divider {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.map(|this| match self.direction {
|
||||
DividerDirection::Horizontal => {
|
||||
|
||||
@@ -196,9 +196,9 @@ pub struct IconElement {
|
||||
}
|
||||
|
||||
impl RenderOnce for IconElement {
|
||||
type Rendered = Svg;
|
||||
type Output = Svg;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
svg()
|
||||
.size(self.size.rems())
|
||||
.flex_none()
|
||||
|
||||
@@ -45,9 +45,9 @@ impl Indicator {
|
||||
}
|
||||
|
||||
impl RenderOnce for Indicator {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.flex_none()
|
||||
.map(|this| match self.style {
|
||||
|
||||
@@ -11,9 +11,9 @@ pub struct KeyBinding {
|
||||
}
|
||||
|
||||
impl RenderOnce for KeyBinding {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
h_stack()
|
||||
.flex_none()
|
||||
.gap_2()
|
||||
@@ -91,9 +91,9 @@ pub struct Key {
|
||||
}
|
||||
|
||||
impl RenderOnce for Key {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
let single_char = self.key.len() == 1;
|
||||
|
||||
div()
|
||||
@@ -125,9 +125,9 @@ pub struct KeyIcon {
|
||||
}
|
||||
|
||||
impl RenderOnce for KeyIcon {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.w(rems(14. / 16.))
|
||||
.child(IconElement::new(self.icon).size(IconSize::Small))
|
||||
|
||||
@@ -46,9 +46,9 @@ impl LabelCommon for HighlightedLabel {
|
||||
}
|
||||
|
||||
impl RenderOnce for HighlightedLabel {
|
||||
type Rendered = LabelLike;
|
||||
type Output = LabelLike;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
let highlight_color = cx.theme().colors().text_accent;
|
||||
|
||||
let mut highlight_indices = self.highlight_indices.iter().copied().peekable();
|
||||
|
||||
@@ -40,9 +40,9 @@ impl LabelCommon for Label {
|
||||
}
|
||||
|
||||
impl RenderOnce for Label {
|
||||
type Rendered = LabelLike;
|
||||
type Output = LabelLike;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
self.base.child(self.label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ impl ParentElement for LabelLike {
|
||||
}
|
||||
|
||||
impl RenderOnce for LabelLike {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.when(self.strikethrough, |this| {
|
||||
this.relative().child(
|
||||
|
||||
@@ -46,9 +46,9 @@ impl ParentElement for List {
|
||||
}
|
||||
|
||||
impl RenderOnce for List {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
v_stack().w_full().py_1().children(self.header).map(|this| {
|
||||
match (self.children.is_empty(), self.toggle) {
|
||||
(false, _) => this.children(self.children),
|
||||
|
||||
@@ -76,9 +76,9 @@ impl Selectable for ListHeader {
|
||||
}
|
||||
|
||||
impl RenderOnce for ListHeader {
|
||||
type Rendered = Stateful<Div>;
|
||||
type Output = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
h_stack()
|
||||
.id(self.label.clone())
|
||||
.w_full()
|
||||
|
||||
@@ -147,9 +147,9 @@ impl ParentElement for ListItem {
|
||||
}
|
||||
|
||||
impl RenderOnce for ListItem {
|
||||
type Rendered = Stateful<Div>;
|
||||
type Output = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
h_stack()
|
||||
.id(self.id)
|
||||
.w_full()
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::prelude::*;
|
||||
pub struct ListSeparator;
|
||||
|
||||
impl RenderOnce for ListSeparator {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.h_px()
|
||||
.w_full()
|
||||
|
||||
@@ -26,9 +26,9 @@ impl ListSubHeader {
|
||||
}
|
||||
|
||||
impl RenderOnce for ListSubHeader {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, _cx: &mut WindowContext) -> Self::Output {
|
||||
h_stack().flex_1().w_full().relative().py_1().child(
|
||||
div()
|
||||
.h_6()
|
||||
|
||||
@@ -41,9 +41,9 @@ pub struct Popover {
|
||||
}
|
||||
|
||||
impl RenderOnce for Popover {
|
||||
type Rendered = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
div()
|
||||
.flex()
|
||||
.gap_1()
|
||||
|
||||
@@ -130,7 +130,7 @@ pub struct PopoverMenuState<M> {
|
||||
impl<M: ManagedView> Element for PopoverMenu<M> {
|
||||
type State = PopoverMenuState<M>;
|
||||
|
||||
fn layout(
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
element_state: Option<Self::State>,
|
||||
cx: &mut WindowContext,
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct MenuHandleState<M> {
|
||||
impl<M: ManagedView> Element for RightClickMenu<M> {
|
||||
type State = MenuHandleState<M>;
|
||||
|
||||
fn layout(
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
element_state: Option<Self::State>,
|
||||
cx: &mut WindowContext,
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::Avatar;
|
||||
pub struct AvatarStory;
|
||||
|
||||
impl Render for AvatarStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Avatar>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{Button, ButtonStyle};
|
||||
pub struct ButtonStory;
|
||||
|
||||
impl Render for ButtonStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Button>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{h_stack, Checkbox};
|
||||
pub struct CheckboxStory;
|
||||
|
||||
impl Render for CheckboxStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Checkbox>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -20,9 +20,9 @@ fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<C
|
||||
pub struct ContextMenuStory;
|
||||
|
||||
impl Render for ContextMenuStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.on_action(|_: &PrintCurrentDate, _| {
|
||||
println!("printing unix time!");
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::Disclosure;
|
||||
pub struct DisclosureStory;
|
||||
|
||||
impl Render for DisclosureStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Disclosure>())
|
||||
.child(Story::label("Toggled"))
|
||||
|
||||
@@ -8,9 +8,9 @@ use crate::{Icon, IconElement};
|
||||
pub struct IconStory;
|
||||
|
||||
impl Render for IconStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
let icons = Icon::iter();
|
||||
|
||||
Story::container()
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{Icon, IconButton};
|
||||
pub struct IconButtonStory;
|
||||
|
||||
impl Render for IconButtonStory {
|
||||
type Element = Component<StoryContainer>;
|
||||
type Output = Component<StoryContainer>;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
let default_button = StoryItem::new(
|
||||
"Default",
|
||||
IconButton::new("default_icon_button", Icon::Hash),
|
||||
|
||||
@@ -13,9 +13,9 @@ pub fn binding(key: &str) -> gpui::KeyBinding {
|
||||
}
|
||||
|
||||
impl Render for KeybindingStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
let all_modifier_permutations = ["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
|
||||
|
||||
Story::container()
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{HighlightedLabel, Label};
|
||||
pub struct LabelStory;
|
||||
|
||||
impl Render for LabelStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Label>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{List, ListItem};
|
||||
pub struct ListStory;
|
||||
|
||||
impl Render for ListStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<List>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{Icon, ListHeader};
|
||||
pub struct ListHeaderStory;
|
||||
|
||||
impl Render for ListHeaderStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<ListHeader>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{Icon, ListItem};
|
||||
pub struct ListItemStory;
|
||||
|
||||
impl Render for ListItemStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.bg(cx.theme().colors().background)
|
||||
.child(Story::title_for::<ListItem>())
|
||||
|
||||
@@ -9,9 +9,9 @@ use crate::{Indicator, Tab};
|
||||
pub struct TabStory;
|
||||
|
||||
impl Render for TabStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
Story::container()
|
||||
.child(Story::title_for::<Tab>())
|
||||
.child(Story::label("Default"))
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::{prelude::*, Tab, TabBar, TabPosition};
|
||||
pub struct TabBarStory;
|
||||
|
||||
impl Render for TabBarStory {
|
||||
type Element = Div;
|
||||
type Output = Div;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
let tab_count = 20;
|
||||
let selected_tab_index = 3;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::{prelude::*, ToggleButton};
|
||||
pub struct ToggleButtonStory;
|
||||
|
||||
impl Render for ToggleButtonStory {
|
||||
type Element = Component<StoryContainer>;
|
||||
type Output = Component<StoryContainer>;
|
||||
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
StoryContainer::new(
|
||||
"Toggle Button",
|
||||
"crates/ui2/src/components/stories/toggle_button.rs",
|
||||
|
||||
@@ -93,9 +93,9 @@ impl ParentElement for Tab {
|
||||
}
|
||||
|
||||
impl RenderOnce for Tab {
|
||||
type Rendered = Stateful<Div>;
|
||||
type Output = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
let (text_color, tab_bg, _tab_hover_bg, _tab_active_bg) = match self.selected {
|
||||
false => (
|
||||
cx.theme().colors().text_muted,
|
||||
|
||||
@@ -89,9 +89,9 @@ impl ParentElement for TabBar {
|
||||
}
|
||||
|
||||
impl RenderOnce for TabBar {
|
||||
type Rendered = Stateful<Div>;
|
||||
type Output = Stateful<Div>;
|
||||
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||
fn render(self, cx: &mut WindowContext) -> Self::Output {
|
||||
const HEIGHT_IN_REMS: f32 = 30. / 16.;
|
||||
|
||||
div()
|
||||
|
||||
@@ -68,9 +68,9 @@ impl Tooltip {
|
||||
}
|
||||
|
||||
impl Render for Tooltip {
|
||||
type Element = Overlay;
|
||||
type Output = Overlay;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Output {
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
overlay().child(
|
||||
// padding to avoid mouse cursor
|
||||
|
||||
Reference in New Issue
Block a user