rerun-io / egui_tiles

A tiling layout engine for egui with drag-and-drop and resizing
Apache License 2.0
305 stars 25 forks source link

Dynamically adding tiles/panes if only one pane exists #83

Open canselcik opened 2 months ago

canselcik commented 2 months ago

I am probably doing it wrong but there seems to be some sort of idiosyncrasy to it that I am having a hard time figuring out.

If I created the tree as such:

    let mut tiles = egui_tiles::Tiles::default();
    let children = vec![
        tiles.insert_pane(Pane {
            nr: PaneType::Chart("SOMETHING", "SOMETHING".to_string()),
            retained: true,
        }),
        tiles.insert_pane(Pane {
            nr: PaneType::EmptyDemo(Color32::DARK_BLUE),
            retained: true,
        }),
    ];
    let h2 = tiles.insert_tab_tile(children);
    egui_tiles::Tree::new("tree_root", h2, tiles)

And then try to add a new tile like:

        if ui.button("UI Panels Test").clicked() {
            if let Some(r) = self.tree.root() {
                self.log("Found root");
                let content = Pane {
                    nr: PaneType::EmptyDemo(Color32::DARK_BLUE),
                    retained: true,
                };
                let t = vec![self.tree.tiles.insert_pane(content)];
                let pid = self.tree.tiles.insert_horizontal_tile(t);
                self.tree.move_tile_to_container(pid, r.clone(), 0, true);
            }
        }

It works fine. But if I closed the PaneType::EmptyDemo(Color32::DARK_BLUE) pane before creating another, it never shows up.

Is it about the size of the new panel?

canselcik commented 2 months ago

As a workaround I added an empty pane and marked it invisible. Everything works as expected.