Expand description
Layer ranks: a fixed order between the foreground layers of a window (ADR 0026).
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:
- the docked panels and the central panel (egui’s background);
Rank::Over: the zones lying over their neighbour and flyouts;Rank::Overlay: egui-pop’s and the application’s overlays (cards, popovers, toasts, the zen way out);- every foreground layer nobody ranked: menus, combo lists, context menus, dialogs;
- 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
areain the foreground atrank: what an application calls for its own overlay instead ofctx.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 ofbase(ctx, Rank::Over)(egui_stack’sLayoutArea::sublayer_of). - begin_
pass - Starts a pass of the window being drawn: puts the bases into egui’s
order,
OverunderOverlay. 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
layeratrankfor 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
layeratrankwhen 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
layerwas given in this pass or the previous one, in the window being drawn;Nonefor a layer nobody ranked.