Skip to main content

Module layers

Module layers 

Source
Expand description

Layer ranks: what lies over what in a window’s foreground (from egui-pop-core, ADR 0026).

Experimental: may change in any release (docs/stability.md).
Layer ranks: a fixed order between the foreground layers of a window (ADR 0026).
Experimental: may change in any release (docs/stability.md).

egui has no z-index: inside an [Order], the layer shown or clicked last goes on top. A panel lying over the centre and an application’s card both live in [Order::Foreground], so a click on the panel would put it over the card. Ranks fix the order between kinds of layers, bottom to top, in each window:

  1. the docked panels and the central panel (egui’s background);
  2. Rank::Over: the zones lying over their neighbour and flyouts;
  3. Rank::Overlay: egui-pop’s and the application’s overlays (cards, popovers, toasts, the zen way out);
  4. every foreground layer nobody ranked: menus, combo lists, context menus, dialogs;
  5. tooltips ([Order::Tooltip]).

Inside a rank, egui’s rule still holds: the layer clicked last is on top.

Each pinned rank has a base: an empty foreground layer egui-pop puts at the bottom of the foreground on a window’s first pass and never raises. A ranked layer is made a sublayer of its rank’s base each pass ([egui::Context::set_sublayer]), so egui moves it right above that base at the end of the pass, whatever was clicked.

An application overlay calls area where it would show an [egui::Area] (instead of calling ctx.move_to_top on it):

use egui_pop_core::layers::{self, Rank};

layers::area(
    ctx,
    egui::Area::new(egui::Id::unique("my_app.card")).anchor(egui::Align2::LEFT_BOTTOM, [8.0, -8.0]),
    Rank::Overlay,
    |ui| ui.label("Did you know?"),
);

A layer drawn some other way (a [egui::Context::layer_painter]) calls rank each pass it is shown. A layer left unranked stays above every ranked one; a layer to keep under the lying-over zones is made a sublayer of base(ctx, Rank::Over) by its owner.

begin_pass and end_pass run at the start and the end of every pass of every window once install was called (the application does).

Enums§

Rank
Where a foreground layer sits among the others of its window, bottom to top (see the module). The ranks not listed here are egui’s: the background below, the unranked foreground layers and tooltips above.

Functions§

area
Shows area in the foreground at rank: what an application calls for its own overlay instead of ctx.move_to_top.
base
The base layer of rank: an empty foreground layer kept at the bottom of the foreground, the ranked layers right above it. A host drawing its own lying-over surface makes it a sublayer of base(ctx, Rank::Over) (egui_stack’s LayoutArea::sublayer_of).
begin_pass
Starts a pass of the window being drawn: puts the bases into egui’s order, Over under Overlay. On a window’s first pass, before any other foreground layer is shown, this puts them at the bottom of the foreground, where they stay since nothing raises them. Calling it again in a pass does nothing more.
end_pass
Ends a pass of the window being drawn: a ranked layer’s own sublayers (a scene, a canvas overlay inside a lying-over panel) are made sublayers of its base too, since egui nests one level only; and the layers someone else made sublayers of a base (egui_stack’s lying-over zones) are noted at its rank.
install
Installs the ranks on a context (once; later calls do nothing), and starts the current pass: call it before the pass shows any foreground layer.
rank
Puts layer at rank for this pass: call it each pass the layer is shown. Only a foreground layer can be ranked; another is left where it is.
rank_from
Puts layer at rank when the layer it was opened from, opener, lies at that rank or below it (a panel, a window, a lying-over zone, another overlay); leaves it unranked, above its opener, when the opener is above that rank (a dialog, a menu). Returns whether it was ranked.
rank_of
The rank layer was given in this pass or the previous one, in the window being drawn; None for a layer nobody ranked.