Expand description
Drag cursors: the cursor a draggable shows, hovered and while it is
dragged, keyed by what the drag means (DragKind) rather than by
widget.
egui resets the cursor every pass, and the pointer leaves a widget
while it drags it: a cursor set only when the widget is hovered, or
only where the pointer is over it, comes back to the arrow mid-drag.
drag_cursor asks the drag’s cursor every pass the response is
dragged, wherever the pointer is, and the hover cursor only while
nothing else is dragged.
The hover rule. By default a draggable shows its hover cursor
only when dragging is its only action (HoverPolicy::OnlyAction):
a splitter, a resize grip, an item’s handle. Where a click or a
double click does something (select, set a value, move the playhead),
the arrow stays until the drag starts. Whether a response clicks is
read from its sense, unless the widget says (DragCursorFor::clicks).
Three levels, the most specific winning: the widget
(DragCursorFor::hover, DragCursorFor::dragging,
DragCursorFor::hover_policy), the pointer profile
(PointerMap::drag_cursor_over),
the kit (drag-cursor.<kind>.hover, .drag, .policy:
DragCursorKit), over the kind’s own
(DragKind::cursors).
use egui_pop_core::pointer::{self, DragKind, HoverPolicy};
let ctx = egui::Context::default();
let mut out = ctx.run_ui(Default::default(), |ui| {
let (_, splitter) = ui.allocate_exact_size(egui::vec2(4.0, 100.0), egui::Sense::drag());
pointer::drag_cursor(&splitter, DragKind::SplitColumns);
// A click selects it: the arrow until it is dragged, unless asked.
let (_, clip) = ui.allocate_exact_size(egui::vec2(100.0, 20.0), egui::Sense::click_and_drag());
pointer::drag_cursor(&clip, DragKind::Move).hover_policy(HoverPolicy::Always);
});
out.textures_delta.clear();
assert_eq!(
pointer::drag_cursor_icons(&ctx, DragKind::Pan),
(egui::CursorIcon::Grab, egui::CursorIcon::Grabbing)
);Structs§
- Drag
Cursor - The cursors of a drag kind: hovered, and while dragging (kept until
the drag ends, wherever the pointer goes), and when the hover one
shows. Names from
CURSOR_NAMES; in a kit or a profile, an empty or unknown name and no policy keep the level below’s (DragCursor::over). - Drag
Cursor For - The cursor a draggable asks for (
drag_cursor), shown when it is dropped. Its settings are the most specific level: they win over the pointer profile’s and the kit’s.
Enums§
- Drag
Kind - What a drag does to what it holds: the meaning a drag’s cursor is
keyed by, whatever the widget. A widget names the kind of each of its
drags; the profile in force says which cursor each kind shows,
hovered and dragged, and when the hover cursor shows
(
DragKind::cursors,Profile::drag_cursors,HoverPolicy). - Hover
Policy - When a draggable shows its hover cursor, before any drag. While it is dragged it always shows its drag cursor.
Constants§
- CURSOR_
NAMES - The cursor names a profile may give: CSS’s (
grab,ew-resize), which egui shows on every platform.
Functions§
- cursor_
icon - egui’s cursor of a CSS cursor name (
CURSOR_NAMES). - drag_
cursor - Shows the cursor of a drag of
kindfor a response: its drag cursor every pass it is dragged, wherever the pointer is; its hover cursor while it is hovered and nothing is dragged, as the hover policy says (HoverPolicy). Called each pass the widget is drawn, after anything else that sets the cursor for it. - drag_
cursor_ icons - A drag kind’s cursors in a context, hovered and dragged: the kit’s
under the pointer map’s (
resolve_drag_cursor). - ghost_
shown - Whether a drag’s ghost goes under the pointer: the application API’s drag session says so when its source gave it one, and a view that would show how many items it carries beside the pointer leaves that to the ghost.
- hold_
drag_ cursor - Shows the drag cursor of
kindthis pass: for a drag a widget follows itself (a state of its own rather than one response). - hover_
drag_ cursor - Shows the hover cursor of
kindthis pass over what a widget hovers itself, if the hover policy in force shows it for an element that does something on a click (clicks) or not, and unless it is the arrow (which leaves the cursor to whatever asked for one). - resolve_
drag_ cursor - A drag kind’s cursors in a context, with its hover policy: the
kit’s (
DragCursorKit), under the pointer map’s (super::map). - set_
ghost_ shown - Says whether a drag’s ghost goes under the pointer (
ghost_shown).