class

Egui::Svg

Inherits Egui::Widget < Reference < Object

Constants

BLACK = Color32.rgb(0, 0, 0)

Default currentColor resolution (the parse argument below).

MAX_RASTER_SIZES = 8

Fit the intrinsic size into rect (aspect preserved, centered) and replay the art as one textured quad.

The raster texture is software-baked ONCE per (source, tint, pixel size) with anti-aliasing (MAX_RASTER_SIZES bounds the bakes per icon so a size slider evicts the oldest instead of accumulating). Raster and quad are DERIVED from each other: bake at whole physical pixels, then draw the quad at exactly that many pixels, snapped to the pixel grid — a 1:1 texel-to-pixel mapping samples without resampling blur. This is why fonts are crisp: they rasterize at their exact ppem and land 1:1. (A quad of 44.2 px sampling a 45-texel raster smears every texel into its neighbor — the "soapy icon" look.)

MAX_RASTER_TEXTURES = 2000

Global budget across ALL Svgs (GPU memory + the sokol image pool): past it the oldest bake is destroyed FIFO — scrolled-away icons re-bake on return (~a millisecond each), memory stays bounded whatever the app does. Sized to hold the full lucide set (~1850) plus headroom: sokol frees destroyed image slots a few frames LATE, so a budget below the working set makes rapid eviction churn exhaust the pool even with the cap respected (the LUCIDE_NO_CULL stress lesson).

Constructors

load(path : String, size : Vec2 = Vec2.new(128.0, 128.0)) : self

From a file on disk (e.g. assets/icon.svg).

Source
new(source : String, size : Vec2 = Vec2.new(128.0, 128.0), current_color : Color32 = BLACK)

current_color resolves currentColor in the source (icon sets are monochrome; pass the theme fg here).

Source

Class methods

external_rasterizer

Optional primary rasterizer: (source, tint, w, h) → straight-alpha RGBA8 bytes, or nil to use NanoSvgCr. backend/ sokol.cr installs the C NanoSVG shim here in DEV builds only (no --release): the C code is cc -O2 regardless of Crystal's flags, while the port's hot loops are 10-100x slower unoptimized — the release build stays pure Crystal.

Source
external_rasterizer=(external_rasterizer : Proc(String, Color32, Int32, Int32, Bytes | Nil) | Nil)

Optional primary rasterizer: (source, tint, w, h) → straight-alpha RGBA8 bytes, or nil to use NanoSvgCr. backend/ sokol.cr installs the C NanoSVG shim here in DEV builds only (no --release): the C code is cc -O2 regardless of Crystal's flags, while the port's hot loops are 10-100x slower unoptimized — the release build stays pure Crystal.

Source

Instance methods

paint(ui : Ui, rect : Rect) : Nil
Source
size

Square widget by default — the common logo shape.

Source
size=(size : Vec2)

Square widget by default — the common logo shape.

Source
ui(ui : Ui) : Response
Source