1use crate::prelude::*;
2use crate::{v_stack, Buffer, Icon, IconButton, Label};
3
4#[derive(RenderOnce)]
5pub struct MultiBuffer {
6 buffers: Vec<Buffer>,
7}
8
9impl<V: 'static> Component<V> for MultiBuffer {
10 type Rendered = Div<V>;
11
12 fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
13 v_stack()
14 .w_full()
15 .h_full()
16 .flex_1()
17 .children(self.buffers.clone().into_iter().map(|buffer| {
18 v_stack()
19 .child(
20 div()
21 .flex()
22 .items_center()
23 .justify_between()
24 .p_4()
25 .bg(cx.theme().colors().editor_subheader_background)
26 .child(Label::new("main.rs"))
27 .child(IconButton::new("arrow_up_right", Icon::ArrowUpRight)),
28 )
29 .child(buffer)
30 }))
31 }
32}
33
34impl MultiBuffer {
35 pub fn new(buffers: Vec<Buffer>) -> Self {
36 Self { buffers }
37 }
38}
39
40use gpui::{Div, RenderOnce};
41#[cfg(feature = "stories")]
42pub use stories::*;
43
44#[cfg(feature = "stories")]
45mod stories {
46 use super::*;
47 use crate::{hello_world_rust_buffer_example, Story};
48 use gpui::{Div, Render};
49
50 pub struct MultiBufferStory;
51
52 impl Render<Self> for MultiBufferStory {
53 type Element = Div<Self>;
54
55 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
56 Story::container(cx)
57 .child(Story::title_for::<_, MultiBuffer>(cx))
58 .child(Story::label(cx, "Default"))
59 .child(MultiBuffer::new(vec![
60 hello_world_rust_buffer_example(cx),
61 hello_world_rust_buffer_example(cx),
62 hello_world_rust_buffer_example(cx),
63 hello_world_rust_buffer_example(cx),
64 hello_world_rust_buffer_example(cx),
65 ]))
66 }
67 }
68}