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