Last active
August 24, 2025 20:24
-
-
Save Omustardo/c613f21633fdbf382a6795e05ed55379 to your computer and use it in GitHub Desktop.
Demo of a fraction of 1.0 causing tabs to stack weirdly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use eframe::egui; | |
| use egui_dock::{DockState, NodeIndex, TabViewer}; | |
| fn main() -> Result<(), eframe::Error> { | |
| let options = eframe::NativeOptions { | |
| viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]), | |
| ..Default::default() | |
| }; | |
| eframe::run_native( | |
| "Dock Tab Overlap Demo", | |
| options, | |
| Box::new(|_cc| Ok(Box::new(DockApp::default()))), | |
| ) | |
| } | |
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
| enum Tab { | |
| TopLeft, | |
| BottomLeft, | |
| RightMain, | |
| Bottom, | |
| } | |
| impl Tab { | |
| fn name(&self) -> &'static str { | |
| match self { | |
| Tab::TopLeft => "TopLeft", | |
| Tab::BottomLeft => "LastLeft", | |
| Tab::RightMain => "RightMain", | |
| Tab::Bottom => "Bottom", | |
| } | |
| } | |
| } | |
| struct Context; | |
| struct DockApp { | |
| dock_state: DockState<Tab>, | |
| context: Context, | |
| } | |
| impl Default for DockApp { | |
| fn default() -> Self { | |
| let mut state = DockState::new(vec![Tab::RightMain]); | |
| let [_right_area, current_left] = | |
| state | |
| .main_surface_mut() | |
| .split_left(NodeIndex::root(), 0.2, vec![Tab::TopLeft]); | |
| let [_prev_area, _new_area] = state | |
| .main_surface_mut() | |
| // The fraction of 1.0 here is a problem. | |
| .split_below(current_left, 1.0, vec![Tab::BottomLeft]); | |
| let [_main_area, _bottom_area] = | |
| state | |
| .main_surface_mut() | |
| .split_below(NodeIndex::root(), 0.7, vec![Tab::Bottom]); | |
| Self { | |
| dock_state: state, | |
| context: Context, | |
| } | |
| } | |
| } | |
| impl TabViewer for Context { | |
| type Tab = Tab; | |
| fn title(&mut self, tab: &mut Tab) -> egui::WidgetText { | |
| tab.name().into() | |
| } | |
| fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Tab) { | |
| ui.style_mut().text_styles.insert( | |
| egui::TextStyle::Body, | |
| egui::FontId::new(18.0, egui::FontFamily::Proportional), | |
| ); | |
| match tab { | |
| Tab::BottomLeft => { | |
| ui.label( | |
| egui::RichText::new("LASTLEFT CONTENT") | |
| .size(24.0) | |
| .color(egui::Color32::from_rgb(255, 100, 100)), | |
| ); | |
| ui.label( | |
| egui::RichText::new("If you see 'BOTTOM CONTENT' here, that's the bug!") | |
| .size(16.0), | |
| ); | |
| } | |
| Tab::Bottom => { | |
| ui.label( | |
| egui::RichText::new("BOTTOM CONTENT") | |
| .size(24.0) | |
| .color(egui::Color32::from_rgb(100, 100, 255)), | |
| ); | |
| ui.label( | |
| egui::RichText::new( | |
| "If you see this when LastLeft is selected, that's the bug!", | |
| ) | |
| .size(16.0), | |
| ); | |
| } | |
| _ => { | |
| ui.label( | |
| egui::RichText::new(format!("{} CONTENT", tab.name().to_uppercase())) | |
| .size(20.0), | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| impl eframe::App for DockApp { | |
| fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | |
| egui::CentralPanel::default().show(ctx, |ui| { | |
| egui_dock::DockArea::new(&mut self.dock_state).show_inside(ui, &mut self.context); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment