1use std::marker::PhantomData;
2
3use crate::prelude::*;
4use crate::{v_stack, Buffer, Icon, IconButton, Label, LabelSize};
5
6#[derive(Element)]
7pub struct MultiBuffer<S: 'static + Send + Sync + Clone> {
8 state_type: PhantomData<S>,
9 buffers: Vec<Buffer<S>>,
10}
11
12impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
13 pub fn new(buffers: Vec<Buffer<S>>) -> Self {
14 Self {
15 state_type: PhantomData,
16 buffers,
17 }
18 }
19
20 fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
21 let theme = theme(cx);
22
23 v_stack()
24 .w_full()
25 .h_full()
26 .flex_1()
27 .children(self.buffers.clone().into_iter().map(|buffer| {
28 v_stack()
29 .child(
30 div()
31 .flex()
32 .items_center()
33 .justify_between()
34 .p_4()
35 .fill(theme.lowest.base.default.background)
36 .child(Label::new("main.rs").size(LabelSize::Small))
37 .child(IconButton::new(Icon::ArrowUpRight)),
38 )
39 .child(buffer)
40 }))
41 }
42}
43
44#[cfg(feature = "stories")]
45pub use stories::*;
46
47#[cfg(feature = "stories")]
48mod stories {
49 use crate::{hello_world_rust_buffer_example, Story};
50
51 use super::*;
52
53 #[derive(Element)]
54 pub struct MultiBufferStory<S: 'static + Send + Sync + Clone> {
55 state_type: PhantomData<S>,
56 }
57
58 impl<S: 'static + Send + Sync + Clone> MultiBufferStory<S> {
59 pub fn new() -> Self {
60 Self {
61 state_type: PhantomData,
62 }
63 }
64
65 fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
66 let theme = theme(cx);
67
68 Story::container(cx)
69 .child(Story::title_for::<_, MultiBuffer<S>>(cx))
70 .child(Story::label(cx, "Default"))
71 .child(MultiBuffer::new(vec![
72 hello_world_rust_buffer_example(&theme),
73 hello_world_rust_buffer_example(&theme),
74 hello_world_rust_buffer_example(&theme),
75 hello_world_rust_buffer_example(&theme),
76 hello_world_rust_buffer_example(&theme),
77 ]))
78 }
79 }
80}