Egui::Backend::Sokol
The sokol_gfx rendering backend (eframe/glow_integration role).
Constants
sapp_event_type values (sokol_app.h)
Cap on simultaneously live materialized stacks (the shared atlas removes the GPU-side pressure; this caps the CPU side — .ttf data + glyph/kern/measure caches per family, a few MiB each). Above it, the least-recently-drawn stacks are dropped.
Class methods
sg_apply_scissor_rectf truncates x/y/w/h to ints independently (sokol_gfx.h), so trunc(y) + trunc(h) can land a full pixel above trunc(y + h) for a fractional clip — e.g. a modal centered at screen.center - size/2 — clipping away a stroke sitting on the rect edge (the invisible bottom border). Round outward instead: floor the min corner, ceil the size, so every partially-covered pixel row/column stays inside the scissor. Scissor rects are in FRAMEBUFFER pixels — scale the point-space clip by ppp first.
Live-switch the client-side frame style (Windows/Ubuntu/Macos).
Full-circle tessellation segment count, using the same radius
cutoffs as upstream epaint (Tessellator::add_circle: 8/16/
32/64/128). Small circles stay cheap, big ones stay round; the
4x MSAA framebuffer (backend/sokol_shim.c) smooths the edges.
Default font-backend chain, shared by on_init, examples and
benches: the freetype-cr port (pure Crystal, what release
ships). Dev builds with C_EXTENSIONS enabled accelerate through
the C-FFI FreeType first — same glyphs, faster bake under debug
codegen. atlas = the registry's shared glyph atlas (nil —
default — bakes into a private atlas: specs, standalone tools).
Vertical-gradient color at y within r (Gouraud per-vertex).
8-bit alpha mask of an image file (255 = opaque pixel), the input for SystemPorts::Window.set_shape (e.g. the splash PNG). Nil when the file cannot be decoded. The C-side buffer is copied into a Crystal Bytes and freed.
Queue a synthetic input event for the next frame's RawInput (ports that take over the event stream — native window drags — use it to close interactions the platform no longer reports).
Last pointer position reported to egui (window-local points); zero before any pointer event. Ports use it when they need to synthesize input (see WindowPort#hand_off_release).
eframe::run_native — blocks until the window closes.
- icon — window icon as straight RGBA8 pixels (
width×height), applied right after the window exists. Win32 only today (WM_SETICON); a no-op elsewhere. - decorations —
falsecreates a borderless window (no system title bar / frame) so the app can draw its own chrome; it can still be toggled at runtime via SystemPorts::Window. - transparent — per-pixel window transparency: pixels left at alpha 0 show the desktop through (splash screens, custom chrome). The backdrop is cleared to fully transparent and UI quads blend into a premultiplied swapchain; on Linux this also drops MSAA (the ARGB visuals are single-sample).
- chrome — the client-side frame for a borderless window:
Egui::WindowFramedrawn by the backend before every app frame, including edge resize grips.nil(default) = on for borderless opaque windows, off for transparent ones (splash-style apps draw their own shape);falseopts out for fully custom chrome. A runtimeWindow.set_decorationstoggle shows/hides it in step. - chrome_style — which chrome look to draw: Windows 11 dark
(default), Windows XP Luna (blue gradient titlebar + thick
blue frame), Windows XP Silver (same chrome silver-grey,
rose #DFA1A6→#913448 close button), classic Ubuntu Ambiance (gradient +
round orange close) or macOS (traffic lights left, close
first). Switchable live via
Sokol.chrome_style=. - inspector —
:onenables the runtime widget inspector (right-click any widget → «Inspect»; F12 toggles the bottom panel — seeegui/inspector.cr) with the panel visible from the start;:hiddenenables it the same way but starts with the panel closed (invoked via F12 or «Inspect»). Off by default. Decode an image file (PNG/…) into a CPU-side straight-alpha RGBA buffer — the source forCustomCursorImage(a GPU texture can't be read back). Returns nil when the file can't be decoded.
Rounded-corner stroke: four shortened bars + four quarter-arc rings (the epaint tessellator produces the same shape as a stroked rounded path).
The shared geometry of stroked circles and arcs: a strip of quads between radius - width/2 and radius + width/2.
Inset: the band lives INSIDE the rect, per-side depth = half the
blur plus the offset's push towards that side (CSS inset 0 1px
— y+1 is down — deepens the TOP band, thins the bottom one to
nothing), plus spread everywhere. Corner depths are the mean
of their two sides, clamped so the inner corner radius stays
non-negative; every depth also clamps to half the rect's small
side so opposing bands never cross the center.
Outset: the caster is the rect translated by offset and
expanded by spread (corner radius grows with both, like
upstream Shadow::as_shape); blur fades outward from there.
A ~zero blur leaves the plain offset/spread silhouette.
A quad from four arbitrary points (what the egui tessellator produces for thick lines, rings and arcs — stroke geometry is just quads in epaint too).
Triangle fan slice (center, p, q) with per-vertex gradient colors.
Register a system-scan family: the NAME lands in the catalogs now (Context#deferred_font_paths / #font_family_catalog and the backend's own registry); the stack parses on first use. The reserved names are not deferrable.
Register a NAMED font stack (Context#font_families): a widget
group whose style sets font_family: name measures and draws
through it. Callable before #run (the name lands in the class
registry here and in the Context once the app exists). The
names "monospace" and "system" are reserved — they install the
mono/primary slots instead of an extra stack.
Walk the rounded perimeter clockwise: top edge → TR arc → right edge → BR arc → bottom edge → BL arc → left edge → TL arc. Straight edges carry only their endpoints — alpha never varies along an edge, so one quad per band spans it.
Filled rounded rect: perimeter fan (degenerate quads from the
center), like a disc but with a rounded-rect rim. When fill2
is set the fill is a vertical gradient: each vertex color is
lerp(fill, fill2, y / height), interpolated across triangles.
Swap the active font backend at runtime (e.g. a preview app
toggling between the C FreeType and the Crystal port). The new
backend's atlas is uploaded and bound on the next frame.
mono: optionally installs a SECOND stack (Context#mono_fonts)
for TextCmd family "monospace" — terminal grids, code. Nil
(default) keeps mono text on the primary stack.
bold:/italic:/bold_italic: install the primary stack's REAL
variant faces (Context#bold_fonts & co) — what TextCmd bold /
italic flags draw and measure through. A nil variant is no
emulation: the base stack's real glyphs serve the text.
Emit the band quads between perimeter offset t0 * depth and
t1 * depth (depth is per-point — sides can differ for inset
shadows); outward when sign is -1, inward when +1.
Gaussian-ish falloff for one band stop: full alpha at the caster
edge (t=0), ~0.14 at the band rim (t=1) — a CSS blur of b
reads as a gaussian with σ ≈ b/2, i.e. exp(-2t²) over the band.