You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When retaining tabs in a dock state the program will panic if all tabs are removed from a node.
To Reproduce
Run this program and click the "filter tabs" button in the menu bar.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]// hide console window on Windows in releaseuse eframe::{egui,NativeOptions};use egui_dock::{DockArea,DockState,NodeIndex,Style};fnmain() -> eframe::Result<()>{let options = NativeOptions::default();
eframe::run_native("My egui App",
options,Box::new(|_cc| Box::<MyApp>::default()),)}#[derive(Clone)]enumTab{Stay,GoAway,}structTabViewer{}impl egui_dock::TabViewerforTabViewer{typeTab = Tab;fntitle(&mutself,tab:&mutSelf::Tab) -> egui::WidgetText{match tab {Tab::Stay => "Stay".into(),Tab::GoAway => "GoAway".into(),}}fnui(&mutself,ui:&mut egui::Ui,tab:&mutSelf::Tab){match tab {Tab::Stay => ui.label("This tab will stay"),Tab::GoAway => ui.label("This hab will go away"),};}}structMyApp{tree:DockState<Tab>,}implDefaultforMyApp{fndefault() -> Self{letmut tree = DockState::new(vec![Tab::Stay]);let[_left, _right] =
tree.main_surface_mut().split_left(NodeIndex::root(),0.5,vec![Tab::GoAway]);Self{ tree }}}impl eframe::AppforMyApp{fnupdate(&mutself,ctx:&egui::Context,_frame:&mut eframe::Frame){
egui::TopBottomPanel::top("Top panel").show(ctx, |ui| {if ui.button("Filter tabs").clicked(){//self.tree = self.tree.filter_tabs(|tab| matches!(tab, Tab::Stay));self.tree.retain_tabs(|tab| matches!(tab,Tab::Stay));}});DockArea::new(&mutself.tree).style(Style::from_egui(ctx.style().as_ref())).show(ctx,&mutTabViewer{});}}
This bug happens because in the retain method of a tree, all Node::Empty are removed from the tree. This breaks the binary tree.
A similar thing happens when filtering instead. There the binary tree is not destroyed but the Node remains in the empty state and is displayed as a black hole in the tree. See image:
Expected behavior
For starters, retaining tabs shouldnt break the binary tree. However, that still leaves empty nodes visible in the layout. It should be easy enought to properly remove empty nodes from the binary tree, but this only really works if you have access to the tree in the first place.
The retain_tabs method on Node does not have access to the tree and cannot properly remove itself once empty.
I see two ways to solve this:
Dont allow retain_tabs and filter_tabs on Nodes because it is not possible to properly restore the tree to a valid state.
Allow Node::Leaf to have no tabs. In this case we should display a dummy empty tab that is always closeable. Closing this tab will then correclty remove it from the tree. I think this is a really good solution actually because filtering would then no longer impact the layout of the tree. This allows you to first filter any unwanted tabs and then add new ones without changing the layout and invalidating any node indicies you might have.
The text was updated successfully, but these errors were encountered:
Not related to this bug but probably a good time to think about it.
With #212Node::Empty and possibly Surface::Empty will be removed. Depending on what solution we go with this would impact the api of filter_tabs, filter_map_tabs and retain_tabs for Node and Surface.
Describe the bug
When retaining tabs in a dock state the program will panic if all tabs are removed from a node.
To Reproduce
Run this program and click the "filter tabs" button in the menu bar.
This bug happens because in the retain method of a tree, all
Node::Empty
are removed from the tree. This breaks the binary tree.A similar thing happens when filtering instead. There the binary tree is not destroyed but the Node remains in the empty state and is displayed as a black hole in the tree. See image:
Expected behavior
For starters, retaining tabs shouldnt break the binary tree. However, that still leaves empty nodes visible in the layout. It should be easy enought to properly remove empty nodes from the binary tree, but this only really works if you have access to the tree in the first place.
The
retain_tabs
method onNode
does not have access to the tree and cannot properly remove itself once empty.I see two ways to solve this:
retain_tabs
andfilter_tabs
onNode
s because it is not possible to properly restore the tree to a valid state.Node::Leaf
to have no tabs. In this case we should display a dummy empty tab that is always closeable. Closing this tab will then correclty remove it from the tree. I think this is a really good solution actually because filtering would then no longer impact the layout of the tree. This allows you to first filter any unwanted tabs and then add new ones without changing the layout and invalidating any node indicies you might have.The text was updated successfully, but these errors were encountered: