module

Egui::Backend::Sokol

The sokol_gfx rendering backend (eframe/glow_integration role).

Constants

CHAR = 3
FILES_DROPPED = 23
KEY_DOWN = 1

sapp_event_type values (sokol_app.h)

KEY_UP = 2
MAX_LIVE_STACKS = 64

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.

MOUSE_DOWN = 4
MOUSE_MOVE = 7
MOUSE_SCROLL = 6
MOUSE_UP = 5
RESIZED = 14
TAU = (2.0 * Math::PI)

Class methods

apply_scissor(clip : Egui::Rect) : Nil

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.

Source
bar(r : Egui::Rect, c : Egui::Color32) : Nil
Source
chrome_active=(flag : Bool) : Bool
Source
chrome_active?
Source
chrome_enabled?
Source
chrome_style
Source
chrome_style=(style : WindowFrame::Style) : WindowFrame::Style

Live-switch the client-side frame style (Windows/Ubuntu/Macos).

Source
circle_segments(radius : Float64) : Int32

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.

Source
fonts_from_system(paths : Array(String), atlas : GlyphAtlas | Nil = nil) : AtlasFonts | Nil

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).

Source
grad_color(c1 : Egui::Color32, c2 : Egui::Color32, y : Float64, r : Egui::Rect) : Egui::Color32

Vertical-gradient color at y within r (Gouraud per-vertex).

Source
image_alpha_mask(path : String) : NamedTuple(mask: Bytes, width: Int32, height: Int32) | Nil

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.

Source
inject_event(event : Egui::Event) : Nil

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).

Source
last_pointer_pos

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).

Source
load_rgba(path : String)

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 — false creates 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::WindowFrame drawn 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); false opts out for fully custom chrome. A runtime Window.set_decorations toggle 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 — :on enables the runtime widget inspector (right-click any widget → «Inspect»; F12 toggles the bottom panel — see egui/inspector.cr) with the panel visible from the start; :hidden enables 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 for CustomCursorImage (a GPU texture can't be read back). Returns nil when the file can't be decoded.
Source
paint(cmd : Egui::PaintCmd) : Nil
Source
paint_arc(cmd : Egui::ArcCmd) : Nil
Source
paint_circle(cmd : Egui::CircleCmd) : Nil
Source
paint_image(cmd : Egui::ImageCmd) : Nil
Source
paint_line(cmd : Egui::LineCmd) : Nil
Source
paint_rect(cmd : Egui::RectCmd) : Nil
Source
paint_rect_body(cmd : Egui::RectCmd) : Nil
Source
paint_rect_stroke_rounded(r : Egui::Rect, round : Float64, w : Float64, stroke : Egui::Color32, clip : Egui::Rect) : Nil

Rounded-corner stroke: four shortened bars + four quarter-arc rings (the epaint tessellator produces the same shape as a stroked rounded path).

Source
paint_ring(center : Egui::Pos2, radius : Float64, start_angle : Float64, end_angle : Float64, width : Float64, color : Egui::Color32, clip : Egui::Rect) : Nil

The shared geometry of stroked circles and arcs: a strip of quads between radius - width/2 and radius + width/2.

Source
paint_shadow(cmd : Egui::ShadowCmd) : Nil
Source
paint_shadow_inset(cmd : Egui::ShadowCmd) : Nil

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.

Source
paint_shadow_outset(cmd : Egui::ShadowCmd) : Nil

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.

Source
paint_text(cmd : Egui::TextCmd) : Nil
Source
quad(r : Egui::Rect, c : Egui::Color32) : Nil
Source
quad_pts(p1 : Egui::Pos2, p2 : Egui::Pos2, p3 : Egui::Pos2, p4 : Egui::Pos2, c : Egui::Color32) : Nil

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).

Source
quad_pts_grad(center : Egui::Pos2, p : Egui::Pos2, q : Egui::Pos2, c1 : Egui::Color32, c2 : Egui::Color32, r : Egui::Rect) : Nil

Triangle fan slice (center, p, q) with per-vertex gradient colors.

Source
register_deferred_font(name : String, paths : Array(String)) : Nil

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.

Source
register_font(name : String, fonts : AtlasFonts) : Nil

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.

Source
rounded_perimeter(r : Egui::Rect, radius : Float64) : Array(PerimPt)

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.

Source
rounded_rect_fill(r : Egui::Rect, round : Float64, fill : Egui::Color32, fill2 : Egui::Color32 | Nil = nil) : Nil

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.

Source
run(app : Egui::App, title : String = "egui-cr", width : Int32 = 800, height : Int32 = 600, icon : NamedTuple(rgba: Bytes, width: Int32, height: Int32) | Nil = nil, decorations : Bool = true, transparent : Bool = false, chrome : Bool | Nil = nil, chrome_style : WindowFrame::Style = WindowFrame::Style::Windows, inspector : Symbol = :off, vsync : Bool = true) : Nil
Source
select_fonts(font : AtlasFonts, mono : AtlasFonts | Nil = nil, bold : AtlasFonts | Nil = nil, italic : AtlasFonts | Nil = nil, bold_italic : AtlasFonts | Nil = nil) : Nil

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.

Source
sgl_quad_colors(p0 : Egui::Pos2, p1 : Egui::Pos2, p2 : Egui::Pos2, p3 : Egui::Pos2, c_edge : Egui::Color32, c_inner : Egui::Color32) : Nil
Source
shadow_band(pts : Array(PerimPt), depths : Array(Float64), t0 : Float64, t1 : Float64, color : Egui::Color32, sign : Float64) : Nil

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.

Source
shadow_stop(color : Egui::Color32, t : Float64) : Egui::Color32

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.

Source
side_depth(side : Symbol, d_top : Float64, d_bottom : Float64, d_left : Float64, d_right : Float64) : Float64
Source
title
Source
title=(title : String) : String
Source

Nested types