Trait UiBuilder
pub trait UiBuilder {
Show 73 methods
// Required methods
fn heading(&mut self, text: &str);
fn label(&mut self, text: &str);
fn colored_label(&mut self, color: [f32; 4], text: &str);
fn small_label(&mut self, text: &str);
fn monospace(&mut self, text: &str);
fn button(&mut self, text: &str) -> bool;
fn small_button(&mut self, text: &str) -> bool;
fn selectable_label(&mut self, active: bool, text: &str) -> bool;
fn selectable_label_double_clicked(
&mut self,
active: bool,
text: &str,
) -> bool;
fn checkbox(&mut self, checked: &mut bool, text: &str) -> bool;
fn drag_value_f32(
&mut self,
label: &str,
value: &mut f32,
speed: f32,
) -> bool;
fn slider_f32(
&mut self,
label: &str,
value: &mut f32,
min: f32,
max: f32,
) -> bool;
fn text_edit_singleline(&mut self, text: &mut String) -> bool;
fn vec3_editor(
&mut self,
label: &str,
value: &mut [f32; 3],
speed: f32,
) -> bool;
fn color_edit(&mut self, label: &str, color: &mut [f32; 4]) -> bool;
fn combo_box(
&mut self,
id_salt: &str,
label: &str,
current: &mut usize,
options: &[&str],
) -> bool;
fn horizontal(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder));
fn vertical(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder));
fn collapsing(
&mut self,
header: &str,
default_open: bool,
f: &mut dyn FnMut(&mut dyn UiBuilder),
);
fn indent(&mut self, id: &str, f: &mut dyn FnMut(&mut dyn UiBuilder));
fn scroll_area(&mut self, id: &str, f: &mut dyn FnMut(&mut dyn UiBuilder));
fn separator(&mut self);
fn spacing(&mut self, points: f32);
fn is_last_item_double_clicked(&self) -> bool;
fn is_last_item_hovered(&self) -> bool;
fn is_last_item_enter_pressed(&self) -> bool;
fn is_last_item_escape_pressed(&self) -> bool;
fn context_menu_last(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder));
fn available_width(&self) -> f32;
fn available_height(&self) -> f32;
fn viewport_image(
&mut self,
handle: ViewportTextureHandle,
size: [f32; 2],
) -> Option<[f32; 2]>;
// Provided methods
fn top_inset_panel(
&mut self,
id: &str,
height: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn bottom_inset_panel(
&mut self,
id: &str,
height: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn left_inset_panel(
&mut self,
id: &str,
width: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn right_inset_panel(
&mut self,
id: &str,
width: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn central_inset(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder)) { ... }
fn frame_box(
&mut self,
margin: Margin,
fill: Option<LinearRgba>,
stroke: Stroke,
radius: CornerRadius,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn modal(
&mut self,
id: &str,
size: [f32; 2],
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn is_last_item_dragged(&self) -> bool { ... }
fn key_pressed(&self, key: KeyCode) -> bool { ... }
fn keyboard_captured(&self) -> bool { ... }
fn raw_key_pressed(&self, key: KeyCode) -> bool { ... }
fn focus_last_item(&mut self) { ... }
fn push_clip_rect(&mut self, rect: [f32; 4]) { ... }
fn pop_clip_rect(&mut self) { ... }
fn scroll_delta_in(&self, rect: [f32; 4]) -> f32 { ... }
fn context_menu_panel(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder)) { ... }
fn close_menu(&mut self) { ... }
fn menu_button(
&mut self,
label: &str,
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn paint_line(
&mut self,
from: [f32; 2],
to: [f32; 2],
color: [f32; 4],
thickness: f32,
) { ... }
fn paint_rect_filled(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
) { ... }
fn paint_text(&mut self, pos: [f32; 2], color: [f32; 4], text: &str) { ... }
fn paint_rect_stroke(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
thickness: f32,
) { ... }
fn paint_circle_filled(
&mut self,
center: [f32; 2],
radius: f32,
color: [f32; 4],
) { ... }
fn paint_circle_stroke(
&mut self,
center: [f32; 2],
radius: f32,
color: [f32; 4],
thickness: f32,
) { ... }
fn paint_text_styled(
&mut self,
pos: [f32; 2],
text: &str,
size: f32,
color: [f32; 4],
family: FontFamilyHint,
align: TextAlign,
) { ... }
fn paint_path_filled(&mut self, points: &[[f32; 2]], color: [f32; 4]) { ... }
fn interact_rect(&mut self, id_salt: &str, rect: [f32; 4]) -> Interaction { ... }
fn dnd_attach_drag_payload(&mut self, payload: u64) { ... }
fn dnd_take_drop_payload(&mut self) -> Option<u64> { ... }
fn pointer_position(&self) -> Option<[f32; 2]> { ... }
fn is_drag_active(&self) -> bool { ... }
fn inline_text_field(
&mut self,
rect: [f32; 4],
id_salt: &str,
text: &mut String,
request_focus: bool,
) -> InlineEditEvent { ... }
fn overlay_rect_filled(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
) { ... }
fn overlay_rect_stroke(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
thickness: f32,
) { ... }
fn overlay_text(
&mut self,
pos: [f32; 2],
text: &str,
size: f32,
color: [f32; 4],
family: FontFamilyHint,
) { ... }
fn tooltip_for_last(&mut self, text: &str) { ... }
fn region_at(
&mut self,
id_salt: &str,
rect: [f32; 4],
f: &mut dyn FnMut(&mut dyn UiBuilder),
) { ... }
fn cursor_pos(&self) -> [f32; 2] { ... }
fn allocate_size(&mut self, size: [f32; 2]) -> [f32; 4] { ... }
fn measure_text(
&self,
text: &str,
size: f32,
family: FontFamilyHint,
) -> [f32; 2] { ... }
fn panel_rect(&self) -> [f32; 4] { ... }
fn screen_rect(&self) -> [f32; 4] { ... }
}Expand description
A backend-agnostic, immediate-mode widget builder.
Panels receive a &mut dyn UiBuilder and use it to draw headings, labels,
buttons, separators, and nested layouts without knowing which UI library is
behind the trait.
Required Methods§
fn colored_label(&mut self, color: [f32; 4], text: &str)
fn colored_label(&mut self, color: [f32; 4], text: &str)
Colored label.
fn small_label(&mut self, text: &str)
fn small_label(&mut self, text: &str)
Small / secondary label.
Push-button. Returns true the frame it is clicked.
Small push-button (less padding).
fn selectable_label(&mut self, active: bool, text: &str) -> bool
fn selectable_label(&mut self, active: bool, text: &str) -> bool
Selectable label — highlights when active is true.
Returns true when clicked.
fn selectable_label_double_clicked(&mut self, active: bool, text: &str) -> bool
fn selectable_label_double_clicked(&mut self, active: bool, text: &str) -> bool
Selectable label that returns true when double-clicked.
fn checkbox(&mut self, checked: &mut bool, text: &str) -> bool
fn checkbox(&mut self, checked: &mut bool, text: &str) -> bool
Boolean checkbox. Returns true when toggled.
fn drag_value_f32(&mut self, label: &str, value: &mut f32, speed: f32) -> bool
fn drag_value_f32(&mut self, label: &str, value: &mut f32, speed: f32) -> bool
Draggable f32 value. Returns true when changed.
fn slider_f32(
&mut self,
label: &str,
value: &mut f32,
min: f32,
max: f32,
) -> bool
fn slider_f32( &mut self, label: &str, value: &mut f32, min: f32, max: f32, ) -> bool
Slider for f32. Returns true when changed.
fn text_edit_singleline(&mut self, text: &mut String) -> bool
fn text_edit_singleline(&mut self, text: &mut String) -> bool
Single-line text input. Returns true when changed.
fn vec3_editor(&mut self, label: &str, value: &mut [f32; 3], speed: f32) -> bool
fn vec3_editor(&mut self, label: &str, value: &mut [f32; 3], speed: f32) -> bool
Editable Vec3 as three drag-values (X / Y / Z). Returns true when any component changed.
fn color_edit(&mut self, label: &str, color: &mut [f32; 4]) -> bool
fn color_edit(&mut self, label: &str, color: &mut [f32; 4]) -> bool
RGBA color picker. Returns true when changed.
fn combo_box(
&mut self,
id_salt: &str,
label: &str,
current: &mut usize,
options: &[&str],
) -> bool
fn combo_box( &mut self, id_salt: &str, label: &str, current: &mut usize, options: &[&str], ) -> bool
Drop-down combo box picking among string options.
current is the index of the currently selected item.
Returns true when the selection changed.
Dropdown over options, writing the picked index into current.
id_salt must be stable across frames and unique among sibling combo
boxes: the backend keys the popup’s open state on it. Deriving it from
label is not enough — the inspector’s generic enum walker labels every
switchable enum the same way.
fn horizontal(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
fn horizontal(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
Horizontal layout — children placed left-to-right.
fn vertical(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
fn vertical(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
Vertical layout (default, but useful inside a horizontal).
fn collapsing(
&mut self,
header: &str,
default_open: bool,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn collapsing( &mut self, header: &str, default_open: bool, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Collapsible section with a header.
fn scroll_area(&mut self, id: &str, f: &mut dyn FnMut(&mut dyn UiBuilder))
fn scroll_area(&mut self, id: &str, f: &mut dyn FnMut(&mut dyn UiBuilder))
Scrollable area.
fn separator(&mut self)
fn separator(&mut self)
Horizontal separator line.
fn is_last_item_double_clicked(&self) -> bool
fn is_last_item_double_clicked(&self) -> bool
Returns true if the last widget was double-clicked.
fn is_last_item_hovered(&self) -> bool
fn is_last_item_hovered(&self) -> bool
Returns true if the last widget is currently hovered by the pointer.
fn is_last_item_enter_pressed(&self) -> bool
fn is_last_item_enter_pressed(&self) -> bool
Returns true if Enter was pressed while the last widget had focus.
fn is_last_item_escape_pressed(&self) -> bool
fn is_last_item_escape_pressed(&self) -> bool
Returns true if Escape was pressed while the last widget had focus.
Shows a right-click context menu on the last widget. The closure is called to build menu content when the menu is open.
fn available_width(&self) -> f32
fn available_width(&self) -> f32
Available width in the current layout region.
fn available_height(&self) -> f32
fn available_height(&self) -> f32
Available height in the current layout region.
fn viewport_image(
&mut self,
handle: ViewportTextureHandle,
size: [f32; 2],
) -> Option<[f32; 2]>
fn viewport_image( &mut self, handle: ViewportTextureHandle, size: [f32; 2], ) -> Option<[f32; 2]>
Display a viewport texture at the given size.
Returns the top-left position [x, y] of the rendered image in
window-space pixels (useful for hit-testing / picking).
Returns None if the backend cannot display this handle.
Provided Methods§
fn top_inset_panel(
&mut self,
id: &str,
height: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn top_inset_panel( &mut self, id: &str, height: f32, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Inset panel along the top edge of the current region.
Splits the layout vertically: the closure draws into the top
height pixels, then the rest of the region is left for
subsequent calls (typically a central_inset).
Used by tools that want a header bar nested inside a screen
(the hub does this for its title bar).
Default implementation is a no-op so the trait stays object-safe — the egui backend overrides it.
fn bottom_inset_panel(
&mut self,
id: &str,
height: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn bottom_inset_panel( &mut self, id: &str, height: f32, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Inset panel along the bottom edge — counterpart of
top_inset_panel.
fn left_inset_panel(
&mut self,
id: &str,
width: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn left_inset_panel( &mut self, id: &str, width: f32, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Inset sidebar on the left edge of the current region.
Splits the layout horizontally: the closure draws into the
left width pixels.
fn right_inset_panel(
&mut self,
id: &str,
width: f32,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn right_inset_panel( &mut self, id: &str, width: f32, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Inset sidebar on the right edge — counterpart of
left_inset_panel.
fn central_inset(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
fn central_inset(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))
Central region — fills whatever space remains after the inset panels above were placed.
fn frame_box(
&mut self,
margin: Margin,
fill: Option<LinearRgba>,
stroke: Stroke,
radius: CornerRadius,
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn frame_box( &mut self, margin: Margin, fill: Option<LinearRgba>, stroke: Stroke, radius: CornerRadius, f: &mut dyn FnMut(&mut dyn UiBuilder), )
Wraps f in a visual frame: paints the optional fill / stroke /
rounded background first, then runs f inside the inner
content rect (after applying margin).
Replaces the old egui::Frame::new().inner_margin(...).show(...)
idiom for tool apps that want decorative frames without
importing a backend type.
fn modal(
&mut self,
id: &str,
size: [f32; 2],
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn modal( &mut self, id: &str, size: [f32; 2], f: &mut dyn FnMut(&mut dyn UiBuilder), )
Open a modal dialog overlaid on top of the current screen.
The dialog is centered, has the requested logical size, and
dims the rest of the screen with a semi-transparent backdrop
to convey focus. The closure receives a UiBuilder scoped to
the dialog’s interior.
Default impl is a no-op so the trait stays object-safe — the egui backend overrides.
fn is_last_item_dragged(&self) -> bool
fn is_last_item_dragged(&self) -> bool
Returns true if the last interacted region is currently being dragged.
Used by drag sources to paint a cursor-following ghost so the user can
see a drag is in progress. Default: false.
fn key_pressed(&self, key: KeyCode) -> bool
fn key_pressed(&self, key: KeyCode) -> bool
Whether key was pressed this frame and no text field is consuming
keyboard input.
The focus condition is the whole point: a panel that drives selection with the arrow keys must go quiet while the user is typing in a search box, and every caller getting that right by hand is how a shortcut ends up eating keystrokes meant for a field.
Default: false, so a backend without keyboard support simply reports
no shortcuts rather than pretending.
fn keyboard_captured(&self) -> bool
fn keyboard_captured(&self) -> bool
Whether any widget currently holds keyboard focus — typically a text field being typed into.
Panels use it to suppress their own single-key shortcuts. Default:
false.
fn raw_key_pressed(&self, key: KeyCode) -> bool
fn raw_key_pressed(&self, key: KeyCode) -> bool
Whether key was pressed this frame, regardless of focus.
For the widget that owns the focused field: a command palette must
still move its selection with the arrows while the user types in its
own query box, which is exactly the case key_pressed refuses to
serve. Reach for that one by default; this is the deliberate exception.
fn focus_last_item(&mut self)
fn focus_last_item(&mut self)
Asks the backend to give the last widget keyboard focus.
Call it on the frame a field appears, not every frame: repeating the request traps focus so the user can never tab away.
fn push_clip_rect(&mut self, rect: [f32; 4])
fn push_clip_rect(&mut self, rect: [f32; 4])
Restricts painting to rect until the matching pop_clip_rect.
The editor’s panels paint in absolute window coordinates, so a scrolled list has to be clipped explicitly — otherwise its rows draw straight over the neighbouring panels.
fn pop_clip_rect(&mut self)
fn pop_clip_rect(&mut self)
Restores the clip region saved by push_clip_rect.
fn scroll_delta_in(&self, rect: [f32; 4]) -> f32
fn scroll_delta_in(&self, rect: [f32; 4]) -> f32
Accumulated scroll-wheel delta this frame while the pointer is inside
rect, in points. Positive means the content should move down
(the user scrolled towards the top of the list).
Scoped to a rect rather than reported globally so two scrollable panels
on screen can’t both consume the same gesture. Default: 0.0.
Shows a right-click context menu when the user right-clicks anywhere on the current panel background (not on a specific widget).
Allocates an invisible full-width/height region to detect right-clicks.
Close the currently open context menu (if any).
Call this after a menu action has been executed so the popup dismisses and the action takes effect on the same frame.
Shows a sub-menu button inside a context menu.
Unlike collapsing, this creates a proper egui sub-menu that doesn’t
steal focus from the parent context menu.
fn paint_line(
&mut self,
from: [f32; 2],
to: [f32; 2],
color: [f32; 4],
thickness: f32,
)
fn paint_line( &mut self, from: [f32; 2], to: [f32; 2], color: [f32; 4], thickness: f32, )
Paints a line in window-space coordinates.
fn paint_rect_filled(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
)
fn paint_rect_filled( &mut self, min: [f32; 2], size: [f32; 2], color: [f32; 4], rounding: f32, )
Paints a filled rectangle in window-space coordinates.
fn paint_text(&mut self, pos: [f32; 2], color: [f32; 4], text: &str)
fn paint_text(&mut self, pos: [f32; 2], color: [f32; 4], text: &str)
Paints text at a window-space position.
fn paint_rect_stroke(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
thickness: f32,
)
fn paint_rect_stroke( &mut self, min: [f32; 2], size: [f32; 2], color: [f32; 4], rounding: f32, thickness: f32, )
Paints a stroked (outlined) rectangle in window-space.
fn paint_circle_filled(
&mut self,
center: [f32; 2],
radius: f32,
color: [f32; 4],
)
fn paint_circle_filled( &mut self, center: [f32; 2], radius: f32, color: [f32; 4], )
Paints a filled circle.
fn paint_circle_stroke(
&mut self,
center: [f32; 2],
radius: f32,
color: [f32; 4],
thickness: f32,
)
fn paint_circle_stroke( &mut self, center: [f32; 2], radius: f32, color: [f32; 4], thickness: f32, )
Paints a circle outline.
fn paint_text_styled(
&mut self,
pos: [f32; 2],
text: &str,
size: f32,
color: [f32; 4],
family: FontFamilyHint,
align: TextAlign,
)
fn paint_text_styled( &mut self, pos: [f32; 2], text: &str, size: f32, color: [f32; 4], family: FontFamilyHint, align: TextAlign, )
Paints text with explicit size, font family and alignment.
fn paint_path_filled(&mut self, points: &[[f32; 2]], color: [f32; 4])
fn paint_path_filled(&mut self, points: &[[f32; 2]], color: [f32; 4])
Paints a closed polygon path (for diamonds, triangles, custom shapes).
points is a list of [x, y] window-space coordinates.
fn interact_rect(&mut self, id_salt: &str, rect: [f32; 4]) -> Interaction
fn interact_rect(&mut self, id_salt: &str, rect: [f32; 4]) -> Interaction
Allocates a clickable region at the given absolute window-space rect
and reports interaction this frame. The id_salt disambiguates
overlapping or repeatedly-painted hot regions.
fn dnd_attach_drag_payload(&mut self, payload: u64)
fn dnd_attach_drag_payload(&mut self, payload: u64)
Attaches a drag payload (typically an entity ID packed into a
u64) to the last interacted region (the most recent
interact_rect call). Should be called
immediately after interact_rect. Avoids creating a competing
hit-target on the same rect, which would steal pointer events.
Default: no-op.
fn dnd_take_drop_payload(&mut self) -> Option<u64>
fn dnd_take_drop_payload(&mut self) -> Option<u64>
If a drag-and-drop just released on the last interacted region,
returns its u64 payload. Should be called after
interact_rect. Default: no-op.
fn pointer_position(&self) -> Option<[f32; 2]>
fn pointer_position(&self) -> Option<[f32; 2]>
Current pointer (cursor) position in window-space [x, y], or None
when the pointer is outside the window or unknown. Drop targets use this
to place a dropped item where the cursor released (e.g. unproject the
drop point into the 3D scene). Default: None.
fn is_drag_active(&self) -> bool
fn is_drag_active(&self) -> bool
true while any u64 drag payload is in flight this frame (a drag
started and hasn’t been released). Drop targets use it to show a
“droppable here” highlight. Default: false.
fn inline_text_field(
&mut self,
rect: [f32; 4],
id_salt: &str,
text: &mut String,
request_focus: bool,
) -> InlineEditEvent
fn inline_text_field( &mut self, rect: [f32; 4], id_salt: &str, text: &mut String, request_focus: bool, ) -> InlineEditEvent
Draws a single-line text editor at an absolute window-space rect and
returns its outcome this frame (see InlineEditEvent). Unlike the
generic region_at + response-tracking helpers, this
is self-contained: it owns the widget’s Response, so Enter / Escape /
focus-loss are detected reliably. Pass request_focus = true on the
frame the field first appears so the user can type immediately.
Default: no-op returning InlineEditEvent::Idle.
fn overlay_rect_filled(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
)
fn overlay_rect_filled( &mut self, min: [f32; 2], size: [f32; 2], color: [f32; 4], rounding: f32, )
Paints a filled rounded rect in an unclipped top overlay layer (above all panels). For cursor-following affordances like drag ghosts that must remain visible outside the current panel’s clip rect. Default: no-op.
fn overlay_rect_stroke(
&mut self,
min: [f32; 2],
size: [f32; 2],
color: [f32; 4],
rounding: f32,
thickness: f32,
)
fn overlay_rect_stroke( &mut self, min: [f32; 2], size: [f32; 2], color: [f32; 4], rounding: f32, thickness: f32, )
Stroked rounded rect in the unclipped overlay layer. See
overlay_rect_filled. Default: no-op.
fn overlay_text(
&mut self,
pos: [f32; 2],
text: &str,
size: f32,
color: [f32; 4],
family: FontFamilyHint,
)
fn overlay_text( &mut self, pos: [f32; 2], text: &str, size: f32, color: [f32; 4], family: FontFamilyHint, )
Text in the unclipped overlay layer. See
overlay_rect_filled. Default: no-op.
fn tooltip_for_last(&mut self, text: &str)
fn tooltip_for_last(&mut self, text: &str)
Attaches a tooltip to the most recently created widget / interaction.
fn region_at(
&mut self,
id_salt: &str,
rect: [f32; 4],
f: &mut dyn FnMut(&mut dyn UiBuilder),
)
fn region_at( &mut self, id_salt: &str, rect: [f32; 4], f: &mut dyn FnMut(&mut dyn UiBuilder), )
Pushes a child layout region at the given absolute screen-space rect.
Inside the closure, &mut dyn UiBuilder reflects the constrained
region — egui-native widgets (button, text_edit_singleline,
vec3_editor, …) lay out within it instead of the parent panel.
Used by composite widgets (inspector cards) that paint their frame
absolutely but want native egui controls inside.
id_salt must be stable across frames and unique within the parent.
The backend derives the region’s widget ids from it, and those ids are
what carries keyboard focus and text-edit state: a salt that changes
between frames makes a field being typed into lose focus mid-word, and
two regions sharing a salt make their contents collide.
fn cursor_pos(&self) -> [f32; 2]
fn cursor_pos(&self) -> [f32; 2]
Returns the current layout cursor in screen-space (x, y). Useful for
composites that need to know where to place an absolutely-painted
frame before advancing egui’s natural layout.
fn allocate_size(&mut self, size: [f32; 2]) -> [f32; 4]
fn allocate_size(&mut self, size: [f32; 2]) -> [f32; 4]
Allocates [width, height] of space at the current cursor in
the active layout direction. Returns the resulting rect as
[x, y, w, h] — feed it to the paint primitives.
Unlike interact_rect, this reserves
space in the parent layout so subsequent widgets don’t paint
on top. Use this when a custom widget paints with
paint_rect_filled etc. so the layout flow stays correct (for
example inside a horizontal() row where the row’s height
must reflect the tallest custom-painted widget).
The returned rect’s position matches what the cursor would have
been just before the call. Default impl falls back to the
current cursor_pos() + the requested size — backends that
support real layout allocation must override.
fn measure_text(
&self,
text: &str,
size: f32,
family: FontFamilyHint,
) -> [f32; 2]
fn measure_text( &self, text: &str, size: f32, family: FontFamilyHint, ) -> [f32; 2]
Measures the rendered size of text at size points using family.
Returns [width, height] in logical points.
Backends without a real text shaper fall back to a heuristic (~0.55 × size per character, height = size). The egui backend uses the actual font metrics — call this rather than guessing widths.
fn panel_rect(&self) -> [f32; 4]
fn panel_rect(&self) -> [f32; 4]
Returns the current paint region in screen-space coordinates as
[min_x, min_y, width, height].
Useful for panels that need to draw custom chrome (rounded backgrounds, gradients, branded pills) on top of their content. The returned rectangle matches the area covered by the current layout, including space already consumed by widgets.
Default implementation falls back to a (0, 0) origin and the
available size — backends should override it to return their real
region.
fn screen_rect(&self) -> [f32; 4]
fn screen_rect(&self) -> [f32; 4]
Returns the full screen size (top-left = (0, 0)) as
[min_x, min_y, width, height].
Used by floating overlays / modals that need to cover or center
themselves on the entire viewport. Default implementation falls back
to panel_rect.