Pane grid with different panes holding different data

the video explains it pretty well
Peek 2023-08-31 21-28 MConverter.eu

Each pane should have its own data which they seem to. However how I create the pane grid seems to be the problem, I create the same widget for all exists of a pane grid.

pub fn pane_grid<'a>(
    panes: &'a Panes,
    tabs: &'a [DefaultKey],
    map: &SlotMap<DefaultKey, Tab>,
) -> PaneGrid<'a, Message, Renderer> {
    PaneGrid::new(&panes.data, |pane, state, _is_maximized| {
        let is_focused = panes.active == pane;
        Content::new(match state.tab {
            Tab::File(_) => tab_bar(state.active_tab, &tabs, map),
        })
        .style(Container::PaneGridContent(is_focused))
        .title_bar(
            TitleBar::new(title_bar(pane, state)).style(Container::PaneGridTitleBar(is_focused)),
        )
    })
    .on_click(Message::PaneClicked)
    .on_drag(Message::PaneDragged)
    .on_resize(10, Message::PaneResized)
}

It seems like I would need a for loop for creating the widgets for each panel, but I’m not sure where that would go. Because how the code is structured it looks like i can only edit/create widgets on one pane at a time?

Your tabs and map are being reused for all the panes.

This is a problem with your code. You need to have some way to query the state of a Pane, instead of sharing the same data structure with all of them.

iced won’t magically change your data structures.

so this code is run three times if I have three panes?

|pane, state, _is_maximized| {
        let is_focused = panes.active == pane;
        Content::new(match state.tab {
            Tab::File(_) => tab_bar(state.active_tab, &tabs, map),
        }

just trying to figure out how Iced calls this code so i can pass in the right data.

That closure is run for each pane that exists in the pane grid and passed the state for the pane that you’re returning a Content for.

When you create a new pane with split it takes a state. This is the state that is returned for that pane in the closure.

1 Like