Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-core/src/graph_split.rs

//! **A graph under its header, with a drag bar between** — once, for every tab that
//! shows content above a graph (the Coderoom's connections, the Explorer's live unit
//! graph, …).
//!
//! The owner (loki): "the graph works but is only visible in the lower part of the
//! window, and no drag bar exists". A pane that lays out its lists / layer lines / pane
//! headers first and hands the graph whatever height is left gives the graph the LEAST
//! of the window exactly when there is the most to read above it.
//!
//! [`header_above`]: the header goes in a top region that scrolls when it is
//! longer than its share — by default a quarter of the height, never more than
//! [`HEADER_MAX`] — and the graph takes ALL the rest. Between them is a draggable bar;
//! where the viewer leaves it is remembered in the UI's memory under the region's id
//! (egui's own panel state), so it survives a rebuild of the pane.

/// The header's default share of the height.
pub const HEADER_DEFAULT: f32 = 0.25;
/// The most of the height the header may be dragged to.
pub const HEADER_MAX: f32 = 0.8;

/// Draw `header` (scrolling when long) in a top region with a draggable divider
/// remembered under `id`; everything drawn into `ui` AFTER this call — the graph — gets
/// all the remaining height.
pub fn header_above(ui: &mut egui::Ui, id: impl std::hash::Hash, header: impl FnOnce(&mut egui::Ui)) {
    let h = ui.available_height().max(1.0);
    let id = {
        use std::hash::Hasher;
        let mut h = std::collections::hash_map::DefaultHasher::new();
        id.hash(&mut h);
        ui.id().with(("facett-graph-split", h.finish()))
    };
    egui::Panel::top(id)
        .resizable(true)
        .default_size(h * HEADER_DEFAULT)
        .size_range(24.0..=(h * HEADER_MAX).max(48.0))
        .show(ui, |ui| {
            egui::ScrollArea::vertical().id_salt(id.with("scroll")).auto_shrink([false, false]).show(ui, header);
        });
}