Add MultiBuffer
component
This commit is contained in:
parent
ac93449788
commit
06b0707aa9
5 changed files with 81 additions and 0 deletions
|
@ -7,6 +7,7 @@ pub mod command_palette;
|
||||||
pub mod context_menu;
|
pub mod context_menu;
|
||||||
pub mod facepile;
|
pub mod facepile;
|
||||||
pub mod keybinding;
|
pub mod keybinding;
|
||||||
|
pub mod multi_buffer;
|
||||||
pub mod palette;
|
pub mod palette;
|
||||||
pub mod panel;
|
pub mod panel;
|
||||||
pub mod project_panel;
|
pub mod project_panel;
|
||||||
|
|
34
crates/storybook2/src/stories/components/multi_buffer.rs
Normal file
34
crates/storybook2/src/stories/components/multi_buffer.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use ui::prelude::*;
|
||||||
|
use ui::{hello_world_rust_buffer_example, MultiBuffer};
|
||||||
|
|
||||||
|
use crate::story::Story;
|
||||||
|
|
||||||
|
#[derive(Element)]
|
||||||
|
pub struct MultiBufferStory<S: 'static + Send + Sync + Clone> {
|
||||||
|
state_type: PhantomData<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync + Clone> MultiBufferStory<S> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state_type: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||||
|
let theme = theme(cx);
|
||||||
|
|
||||||
|
Story::container(cx)
|
||||||
|
.child(Story::title_for::<_, MultiBuffer<S>>(cx))
|
||||||
|
.child(Story::label(cx, "Default"))
|
||||||
|
.child(MultiBuffer::new(vec![
|
||||||
|
hello_world_rust_buffer_example(&theme),
|
||||||
|
hello_world_rust_buffer_example(&theme),
|
||||||
|
hello_world_rust_buffer_example(&theme),
|
||||||
|
hello_world_rust_buffer_example(&theme),
|
||||||
|
hello_world_rust_buffer_example(&theme),
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,7 @@ pub enum ComponentStory {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
Facepile,
|
Facepile,
|
||||||
Keybinding,
|
Keybinding,
|
||||||
|
MultiBuffer,
|
||||||
Palette,
|
Palette,
|
||||||
Panel,
|
Panel,
|
||||||
ProjectPanel,
|
ProjectPanel,
|
||||||
|
@ -76,6 +77,7 @@ impl ComponentStory {
|
||||||
Self::ContextMenu => components::context_menu::ContextMenuStory::new().into_any(),
|
Self::ContextMenu => components::context_menu::ContextMenuStory::new().into_any(),
|
||||||
Self::Facepile => components::facepile::FacepileStory::new().into_any(),
|
Self::Facepile => components::facepile::FacepileStory::new().into_any(),
|
||||||
Self::Keybinding => components::keybinding::KeybindingStory::new().into_any(),
|
Self::Keybinding => components::keybinding::KeybindingStory::new().into_any(),
|
||||||
|
Self::MultiBuffer => components::multi_buffer::MultiBufferStory::new().into_any(),
|
||||||
Self::Palette => components::palette::PaletteStory::new().into_any(),
|
Self::Palette => components::palette::PaletteStory::new().into_any(),
|
||||||
Self::Panel => components::panel::PanelStory::new().into_any(),
|
Self::Panel => components::panel::PanelStory::new().into_any(),
|
||||||
Self::ProjectPanel => components::project_panel::ProjectPanelStory::new().into_any(),
|
Self::ProjectPanel => components::project_panel::ProjectPanelStory::new().into_any(),
|
||||||
|
|
|
@ -10,6 +10,7 @@ mod facepile;
|
||||||
mod icon_button;
|
mod icon_button;
|
||||||
mod keybinding;
|
mod keybinding;
|
||||||
mod list;
|
mod list;
|
||||||
|
mod multi_buffer;
|
||||||
mod palette;
|
mod palette;
|
||||||
mod panel;
|
mod panel;
|
||||||
mod panes;
|
mod panes;
|
||||||
|
@ -37,6 +38,7 @@ pub use facepile::*;
|
||||||
pub use icon_button::*;
|
pub use icon_button::*;
|
||||||
pub use keybinding::*;
|
pub use keybinding::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
|
pub use multi_buffer::*;
|
||||||
pub use palette::*;
|
pub use palette::*;
|
||||||
pub use panel::*;
|
pub use panel::*;
|
||||||
pub use panes::*;
|
pub use panes::*;
|
||||||
|
|
42
crates/ui2/src/components/multi_buffer.rs
Normal file
42
crates/ui2/src/components/multi_buffer.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::{v_stack, Buffer, Icon, IconButton, Label, LabelSize};
|
||||||
|
|
||||||
|
#[derive(Element)]
|
||||||
|
pub struct MultiBuffer<S: 'static + Send + Sync + Clone> {
|
||||||
|
state_type: PhantomData<S>,
|
||||||
|
buffers: Vec<Buffer<S>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
|
||||||
|
pub fn new(buffers: Vec<Buffer<S>>) -> Self {
|
||||||
|
Self {
|
||||||
|
state_type: PhantomData,
|
||||||
|
buffers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||||
|
let theme = theme(cx);
|
||||||
|
|
||||||
|
v_stack()
|
||||||
|
.w_full()
|
||||||
|
.h_full()
|
||||||
|
.flex_1()
|
||||||
|
.children(self.buffers.clone().into_iter().map(|buffer| {
|
||||||
|
v_stack()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_between()
|
||||||
|
.p_4()
|
||||||
|
.fill(theme.lowest.base.default.background)
|
||||||
|
.child(Label::new("main.rs").size(LabelSize::Small))
|
||||||
|
.child(IconButton::new(Icon::ArrowUpRight)),
|
||||||
|
)
|
||||||
|
.child(buffer)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue