Skip to main content

Module sections

Module sections 

Source
Expand description

Collapsible sections stacked in a panel: each a title band (a disclosure mark, a title, a count) over its own scrolling body, as a code editor’s side bar stacks its views.

Experimental: may change in any release (docs/stability.md).

The stack is egui_stack’s ([egui_stack::sections]), which holds the layout arithmetic (plan), the drag, the fold, the keyboard, the accessibility, the windowed rows and the wheel. egui-pop gives it its look, its words and its gestures:

  • A click on a band, or Space or Enter while it has the keyboard, folds or opens its section; Left folds it and Right opens it. A folded section keeps its band in place; open sections fill the panel’s height, so the bands of folded sections below the last open one sit at the panel’s bottom, unless the stack is sized by its content (Sections::fill).
  • A section’s height is set by hand, in points, or sized by the list: those never set by hand share what the others leave, and the last open section always takes what is left. Each keeps a least height (two rows by default, Section::min_height) and scrolls its own body.
  • The line above a band, between two open sections, is a boundary (the first open section above is the one it resizes, past any folded ones). It follows the pointer when dragged, or moves by a row with Up and Down while it has the keyboard. Sections give way in turn, the nearest first, never in proportion, and it stops once they are all at their least (plan). A double click, or Enter, drops the heights set by hand and any empty room.
  • In a panel too short, sections sized by the list give way first, then those set by hand, from the bottom up; their stored heights come back with the room, until the next drag aligns them on what is shown. When even the least heights do not fit, the whole stack scrolls, with a scrollbar then only (the kit’s, seen at rest). Every bar of the stack is drawn as UiPop::scroll_area draws one: the theme’s thumb and track, and scroll-bar.margin-track.
  • Sections::grab_titles (off by default) makes the titles drag too: a press that moves resizes as the line above does, one that does not folds, and a double click drops the heights set by hand.
  • The keys of gesture.sections.pull (Ctrl with a drag by default, Cmd on macOS, read from the pointer map) move the sections below as a block, heights kept: only the section above changes, and empty room opens under the last. The empty room is kept, with the layout, until a drag takes it back or a double click drops it.
  • Sections::keep_titles (off by default) leaves a title where it is when its section folds or opens (plan::keep_title).
  • A body is scrolled by the stack (Stack::section), windowed over rows of one height, so that only those in view are drawn (Stack::rows), or left to an application’s own view (Stack::bare). A wheel pushing past the end of a body’s scroll stops there: neither the stack nor a parent moves.
  • What is folded, the heights set by hand and the empty room are remembered with the window’s layout (egui’s persisted memory, under the stack’s name, egui_stack’s key), and readable as a Layout an application keeps with its own. A layout stored by egui-pop 0.4 and earlier, under egui-pop’s own key, moves to egui_stack’s the first time the stack is shown or its layout loaded.

The kit draws the band (section-band, handler section), its mark (section-disclosure, the disclosure-open and disclosure-closed glyph roles) and its count (section-count, based on indicator-badge), as the kit’s [egui_stack::DockPainter].

Named and observable. A band is a button named by its title and count (“Live, 3”), expanded or not for assistive technology; a boundary is a splitter named after the section above it (“Resize Live”, the strings provider’s egui-pop-section-resize), its value the height of that section’s body. laid_out gives each section as drawn on the last pass, with its height and whether that was set by hand (the debug bridge’s state collector lists it too), so an agent reads the stack rather than pixels.

use egui_pop_core::sections::{Section, Sections};

let ctx = egui::Context::default();
let mut out = ctx.run_ui(Default::default(), |ui| {
    Sections::new("sessions").show(ui, |stack| {
        stack.section(Section::new("live", "Live").count(2), |ui| {
            ui.label("build");
            ui.label("tests");
        });
        stack.section(Section::new("idle", "Idle").count(0).open(false), |ui| {
            ui.weak("No idle session");
        });
    });
});
out.textures_delta.clear();
let live = &egui_pop_core::sections::laid_out(&ctx, "sessions")[0];
assert!(live.open && live.body.is_some());

Modules§

plan
The arithmetic of a stack of collapsible sections: how heights share a panel, and what a drag on a boundary between two sections does. Heights are in points, a section’s body alone (its title band is the caller’s); folded sections take no height and are skipped.

Structs§

Laid
A section as laid out on the last pass (laid_out).
Layout
What a stack remembers, by section key: kept in egui’s persisted memory under the stack’s name, and readable and writable whole (Layout::load, Layout::store) for an application that keeps it with its own layout. egui_stack’s own ([egui_stack::sections::Layout]) converts to and from it.
Remembered
What a stack remembers of one section.
Section
One section: a key (stable, what the layout remembers it by), a title, an optional count, its least height, its rows’ height and whether it starts open.
Sections
A stack of collapsible sections filling the room it is given (a panel’s height), named for its memory and for agents.
SectionsResponse
What the user did to a stack this pass.
Stack
The sections a stack is given, in order ([Sections::show]).

Enums§

DragMode
How a drag moves the sections around a boundary.

Functions§

band
One band standing alone, in the look of a section’s: the disclosure mark, the title, the count, for a fold that is not a stack of sections (a card’s “More (n)” row, a group in a form). A click, or Space or Enter while it has the keyboard, toggles it: the caller flips open when the response is clicked(). It is a button named by its title and count (“More, 3”), expanded or not for assistive technology. It takes the width available and a band’s height.
laid_out
The sections of the stack named name as drawn on the last pass, in order (empty when it was not drawn).
row_height
The height of a row when the application names none (Section::row_height): the style’s interactive height, or the body text’s when that is taller.