Skip to main content

Module cursor

Module cursor 

Source
Expand description

Cursors over the viewport: what the active tool shows under the pointer, resolved each time the situation changes (the tool, the keys held, a drag, a handle under the pointer) and drawn crisp at the window’s scale.

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

A Cursor is one of:

  • a system cursor ([egui::CursorIcon]);
  • one of egui-pop’s tool cursors (ToolCursor: a crosshair, an eyedropper, a hand, zoom in and out…), drawn as a bitmap at the cursor size and the window’s scale, in the theme’s colours, and handed to the system as a real cursor;
  • a bitmap the application registered by name (register_image), at several sizes, with a dark variant and frames if it wants;
  • a brush outline (BrushOutline) painted over the image, sized in image pixels so it follows the zoom, the system cursor hidden.

The viewport asks default_cursor for a CursorQuery (Alt turns zoom in into zoom out, a hand closes while dragging), then its on_cursor hook, which may give another cursor (egui-pop-imaging runs it as the cursor.resolve step). shown then decides what reaches the screen, under the CursorSettings: painted cursors may be turned off (system cursors only), and the cursor size follows the system’s.

Bitmap cursors go through egui::Context::set_cursor_image, which eframe’s native integration hands to winit as a custom cursor; where it cannot (the web, immediate viewports), the system cursor given as the fallback shows instead.

Structs§

Bitmap
A bitmap of a cursor: straight (not premultiplied) RGBA.
Brush
A brush tool’s size and hardness.
BrushOutline
A brush outline: a ring of the brush’s radius, in image pixels, so it follows the zoom, and an inner ring where its hardness ends (the feather between them).
CursorImage
A cursor of the application’s: bitmaps at several sizes (give one per scale used: 1x, 1.5x, 2x…), a dark theme’s variant, more frames for an animation, and the system cursor shown where bitmaps cannot be.
CursorQuery
What a viewport knows when it asks which cursor to show. It asks again only when this changes.
CursorSettings
How cursors are shown in a context (set_settings).

Enums§

BrushMark
What a brush outline carries beside the pointer.
Cursor
A cursor.
Shown
What reaches the screen for a cursor.
Tool
The tool active over a viewport, which decides its cursor.
ToolCursor
egui-pop’s tool cursors, drawn in the icon set’s line style.

Constants§

DEFAULT_SIZE
The cursor size when the system says nothing, in points.
MIN_OUTLINE_RADIUS
Below this radius on screen (points), a brush outline gives way to a crosshair: too small to read, it would hide the point painted.

Functions§

apply
Shows a cursor for this frame at pos: sets the system cursor, hands a bitmap to the integration, or paints an outline with painter. Returns whether a bitmap was set: the caller clears it (clear_image) once the pointer leaves, as egui keeps it from frame to frame.
clear_image
Clears a bitmap cursor set by apply.
default_cursor
The cursor egui-pop shows for a query, before the application’s hook:
image
The cursor image registered under a name.
paint_outline
Paints a brush outline: a ring of radius points, a lighter one at inner (none at 0), a point at the centre and the mark beside it, each a line over a wider one in the outline colour so it reads on any image.
paint_sample
Paints a tool cursor with painter in a square (the gallery’s samples, a legend): the bitmap the system would show, as a texture.
parse_size
A cursor size from the text of XCURSOR_SIZE: 8 to 256, else the default.
rasterize
Draws a tool cursor at side physical pixels: its strokes in fill, ringed by outline (about a pixel at 24, more when larger), with anti-aliased edges. Straight RGBA, row by row.
register_image
Registers a cursor image under a name, for Cursor::Image.
set_settings
Sets the cursor settings of a context (an application maps its own settings here).
settings
The cursor settings of a context.
shown
What a cursor shows in a context at a zoom (physical pixels per image pixel) and scale: with painted cursors off, the system cursor standing for it; a brush outline under MIN_OUTLINE_RADIUS, a crosshair; an image nobody registered, its name’s system arrow.
size
The cursor size in use in a context, in points.
system_size
The system’s cursor size, in points: XCURSOR_SIZE where it is set (X11 and Wayland desktops), else DEFAULT_SIZE.
tool_image
A tool cursor’s bitmap at the context’s cursor size and scale, in the theme’s colours; drawn once, then kept.