story: Move DescriptionList into main story. (#1037)
This commit is contained in:
parent
4075447c63
commit
d70d649a67
3 changed files with 43 additions and 22 deletions
|
|
@ -1,29 +1,33 @@
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
|
use gpui::{
|
||||||
|
Action, App, AppContext, Axis, Context, Entity, FocusHandle, Focusable, IntoElement,
|
||||||
|
ParentElement, Render, Styled, Window,
|
||||||
|
};
|
||||||
use gpui_component::{
|
use gpui_component::{
|
||||||
button::Button,
|
button::Button,
|
||||||
checkbox::Checkbox,
|
checkbox::Checkbox,
|
||||||
description_list::{DescriptionItem, DescriptionList},
|
description_list::{DescriptionItem, DescriptionList},
|
||||||
h_flex,
|
dock::PanelControl,
|
||||||
popup_menu::PopupMenuExt as _,
|
|
||||||
text::TextView,
|
text::TextView,
|
||||||
v_flex, AxisExt, Sizable as _, Size,
|
v_flex, Sizable as _, Size,
|
||||||
};
|
};
|
||||||
|
use gpui_component::{h_flex, popup_menu::PopupMenuExt as _, AxisExt};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use story::Assets;
|
|
||||||
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[action(namespace = example, no_json)]
|
#[action(namespace = description_list_story, no_json)]
|
||||||
struct ChangeSize(Size);
|
struct ChangeSize(Size);
|
||||||
|
|
||||||
pub struct Example {
|
pub struct DescriptionListStory {
|
||||||
|
focus_handle: gpui::FocusHandle,
|
||||||
layout: Axis,
|
layout: Axis,
|
||||||
bordered: bool,
|
bordered: bool,
|
||||||
size: Size,
|
size: Size,
|
||||||
items: Vec<(&'static str, &'static str, usize)>,
|
items: Vec<(&'static str, &'static str, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Example {
|
impl DescriptionListStory {
|
||||||
pub fn new(_: &mut Window, _: &mut Context<Self>) -> Self {
|
fn new(_: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let items = vec![
|
let items = vec![
|
||||||
("Name", "GPUI Component", 1),
|
("Name", "GPUI Component", 1),
|
||||||
(
|
(
|
||||||
|
|
@ -62,10 +66,11 @@ impl Example {
|
||||||
bordered: true,
|
bordered: true,
|
||||||
size: Size::default(),
|
size: Size::default(),
|
||||||
layout: Axis::Horizontal,
|
layout: Axis::Horizontal,
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
pub fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
||||||
cx.new(|cx| Self::new(window, cx))
|
cx.new(|cx| Self::new(window, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,8 +90,32 @@ impl Example {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Example {
|
impl super::Story for DescriptionListStory {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn title() -> &'static str {
|
||||||
|
"DescriptionList"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn description() -> &'static str {
|
||||||
|
"Use to display details with a tidy layout."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_view(window: &mut Window, cx: &mut App) -> Entity<impl Render + Focusable> {
|
||||||
|
Self::view(window, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn zoomable() -> Option<PanelControl> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Focusable for DescriptionListStory {
|
||||||
|
fn focus_handle(&self, _: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for DescriptionListStory {
|
||||||
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
v_flex()
|
v_flex()
|
||||||
.id("example")
|
.id("example")
|
||||||
.on_action(cx.listener(Self::on_change_size))
|
.on_action(cx.listener(Self::on_change_size))
|
||||||
|
|
@ -163,14 +192,3 @@ impl Render for Example {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let app = Application::new().with_assets(Assets);
|
|
||||||
|
|
||||||
app.run(move |cx| {
|
|
||||||
story::init(cx);
|
|
||||||
cx.activate(true);
|
|
||||||
|
|
||||||
story::create_new_window("Description List Example", Example::view, cx);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -10,6 +10,7 @@ mod checkbox_story;
|
||||||
mod clipboard_story;
|
mod clipboard_story;
|
||||||
mod color_picker_story;
|
mod color_picker_story;
|
||||||
mod date_picker_story;
|
mod date_picker_story;
|
||||||
|
mod description_list_story;
|
||||||
mod drawer_story;
|
mod drawer_story;
|
||||||
mod dropdown_story;
|
mod dropdown_story;
|
||||||
mod form_story;
|
mod form_story;
|
||||||
|
|
@ -62,6 +63,7 @@ pub use checkbox_story::CheckboxStory;
|
||||||
pub use clipboard_story::ClipboardStory;
|
pub use clipboard_story::ClipboardStory;
|
||||||
pub use color_picker_story::ColorPickerStory;
|
pub use color_picker_story::ColorPickerStory;
|
||||||
pub use date_picker_story::DatePickerStory;
|
pub use date_picker_story::DatePickerStory;
|
||||||
|
pub use description_list_story::DescriptionListStory;
|
||||||
pub use drawer_story::DrawerStory;
|
pub use drawer_story::DrawerStory;
|
||||||
pub use dropdown_story::DropdownStory;
|
pub use dropdown_story::DropdownStory;
|
||||||
pub use form_story::FormStory;
|
pub use form_story::FormStory;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ impl Gallery {
|
||||||
StoryContainer::panel::<ClipboardStory>(window, cx),
|
StoryContainer::panel::<ClipboardStory>(window, cx),
|
||||||
StoryContainer::panel::<ColorPickerStory>(window, cx),
|
StoryContainer::panel::<ColorPickerStory>(window, cx),
|
||||||
StoryContainer::panel::<DatePickerStory>(window, cx),
|
StoryContainer::panel::<DatePickerStory>(window, cx),
|
||||||
|
StoryContainer::panel::<DescriptionListStory>(window, cx),
|
||||||
StoryContainer::panel::<DrawerStory>(window, cx),
|
StoryContainer::panel::<DrawerStory>(window, cx),
|
||||||
StoryContainer::panel::<DropdownStory>(window, cx),
|
StoryContainer::panel::<DropdownStory>(window, cx),
|
||||||
StoryContainer::panel::<FormStory>(window, cx),
|
StoryContainer::panel::<FormStory>(window, cx),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue