1
2#[derive(Clone)]
3struct DockingTab {
4 text: &'static str,
5 n: i32
6}
7
8impl pierro::DockingTab for DockingTab {
9
10 type Context = ();
11
12 fn title(&self) -> String {
13 self.text.to_owned()
14 }
15
16 fn render(&mut self, ui: &mut pierro::UI, _context: &mut ()) {
17 pierro::label(ui, format!("{}: {}", self.text, self.n));
18 if pierro::button(ui, "Add 100!").mouse_clicked() {
19 self.n += 100;
20 }
21 }
22
23 fn add_tab_dropdown<F: FnMut(Self)>(ui: &mut pierro::UI, mut add_tab: F, _context: &mut ()) {
24 if pierro::menu_button(ui, "Hey").mouse_clicked() {
25 add_tab(Self {
26 text: "Hey",
27 n: 0,
28 });
29 }
30 if pierro::menu_button(ui, "Goodbye").mouse_clicked() {
31 add_tab(Self {
32 text: "Goodbye",
33 n: 123,
34 });
35 }
36 }
37
38}
39
40struct DockingApp {
41 docking_state: pierro::DockingState<DockingTab>,
42}
43
44impl pierro::App for DockingApp {
45
46 fn window_config() -> pierro::WindowConfig {
47 pierro::WindowConfig::default()
48 .with_title("Pierro Docking")
49 }
50
51 fn tick(&mut self, ui: &mut pierro::UI) {
52 pierro::menu_bar(ui, |ui| {
53 pierro::menu_bar_item(ui, "Menu", |ui| {
54 pierro::menu_button(ui, "Some");
55 pierro::menu_button(ui, "Stuff");
56 pierro::menu_button(ui, "Here");
57 });
58 });
59 self.docking_state.render(ui, &mut ());
60 }
61
62}
63
64fn main() {
65 pierro::run(DockingApp {
66 docking_state: pierro::DockingState::new(vec![
67 DockingTab { text: "Hello", n: 0 },
68 DockingTab { text: "World", n: 0 },
69 ]),
70 });
71}