Adanos020 / egui_dock

Docking support for egui – an immediate-mode GUI library for Rust
MIT License
458 stars 75 forks source link

`iter_all_tabs` and `iter_all_nodes` should return indexes #249

Open enomado opened 1 month ago

enomado commented 1 month ago

Current api is like

Iterator<Item = (SurfaceIndex, &Node<Tab>)>

whith is not very practical. better to return

Iterator<Item = (SurfaceIndex, NodeIndex)>

and

Iterator<Item = (SurfaceIndex, NodeIndex, TabIndex)>

Because all operations(focusing) is performed with indexes.

BTW

My case is search to find node by part of it(since Node must have id, find_tab is almost useless), so I was forced to re-create that iterators in my code.

We could actually merge find_tab and iter_all_nodes with "index api"

enomado commented 1 month ago

Currently i use something like

        .iter_all_tabs()
        .find_map(|(loc, itab)| (itab.variant == tab).then_some(loc));
        .iter_all_nodes()
        .enumerate()
        .find_map(|(node_idx, (surface_index, node))| {
            node.iter_tabs().enumerate().find_map(|(tab_index, itab)| {
                (itab.variant == tab).then_some((surface_index, NodeIndex(node_idx), TabIndex(tab_index)))
            })
        });