Skip to main content

facett_core/
graph_split.rs

1//! **A graph under its header, with a drag bar between** — once, for every tab that
2//! shows content above a graph (the Coderoom's connections, the Explorer's live unit
3//! graph, …).
4//!
5//! The owner (loki): "the graph works but is only visible in the lower part of the
6//! window, and no drag bar exists". A pane that lays out its lists / layer lines / pane
7//! headers first and hands the graph whatever height is left gives the graph the LEAST
8//! of the window exactly when there is the most to read above it.
9//!
10//! [`header_above`]: the header goes in a top region that scrolls when it is
11//! longer than its share — by default a quarter of the height, never more than
12//! [`HEADER_MAX`] — and the graph takes ALL the rest. Between them is a draggable bar;
13//! where the viewer leaves it is remembered in the UI's memory under the region's id
14//! (egui's own panel state), so it survives a rebuild of the pane.
15
16/// The header's default share of the height.
17pub const HEADER_DEFAULT: f32 = 0.25;
18/// The most of the height the header may be dragged to.
19pub const HEADER_MAX: f32 = 0.8;
20
21/// Draw `header` (scrolling when long) in a top region with a draggable divider
22/// remembered under `id`; everything drawn into `ui` AFTER this call — the graph — gets
23/// all the remaining height.
24pub fn header_above(ui: &mut egui::Ui, id: impl std::hash::Hash, header: impl FnOnce(&mut egui::Ui)) {
25    let h = ui.available_height().max(1.0);
26    let id = {
27        use std::hash::Hasher;
28        let mut h = std::collections::hash_map::DefaultHasher::new();
29        id.hash(&mut h);
30        ui.id().with(("facett-graph-split", h.finish()))
31    };
32    egui::Panel::top(id)
33        .resizable(true)
34        .default_size(h * HEADER_DEFAULT)
35        .size_range(24.0..=(h * HEADER_MAX).max(48.0))
36        .show(ui, |ui| {
37            egui::ScrollArea::vertical().id_salt(id.with("scroll")).auto_shrink([false, false]).show(ui, header);
38        });
39}