ui/widgets
lib/ui/widgets.vklib/ui/widgets.vk
Pure-Veko immediate-mode UI widget, layout, and chart toolkit built on ui/canvas, ui/font, and ui/layout.
Zero capabilities required; renders 28+ crisp desktop-grade Light & Dark widgets directly into an RGBA32 Canvas.
Theme = struct { bg cv/Color, surface cv/Color, surface_hover cv/Color, border cv/Color, text cv/Color, muted cv/Color, accent cv/Color, accent_text cv/Color, success cv/Color, warning cv/Color, danger cv/Color }
Color theme palette for immediate-mode widgets.
UiState = struct { mouse_x i64 = ..., mouse_y i64 = ..., mouse_down bool = ..., mouse_clicked bool = ..., mouse_rclicked bool = ..., wheel_dy i64 = ..., key_code i64 = ..., text_char i64 = ..., hot_id str = ..., active_id str = ..., focused_id str = ..., selected_id str = ..., open_popup_id str = ..., clipboard str = ..., clipboard_dirty bool = ..., dpi_scale i64 = ..., clip_stack block[Rect] = ..., key_mods i64 = ..., shift_down bool = ..., ctrl_down bool = ..., alt_down bool = ..., key_consumed bool = ..., focus_order block[str] = ..., next_focus_order block[str] = ..., focus_scope_prefix str = ... }
Per-frame pointer, wheel, keyboard, focus, popup, and clipboard state for immediate-mode widgets.
MOD-SHIFT = fn [] i64
Keyboard modifier & virtual key constants (mirroring ui/MOD-* and ui/KEY-* with zero .ui capability).
MOD-CTRL = fn [] i64
MOD-ALT = fn [] i64
KEY-BACKSPACE = fn [] i64
KEY-TAB = fn [] i64
KEY-ENTER = fn [] i64
KEY-SHIFT = fn [] i64
KEY-CTRL = fn [] i64
KEY-ALT = fn [] i64
KEY-ESC = fn [] i64
KEY-SPACE = fn [] i64
KEY-PAGE-UP = fn [] i64
KEY-PAGE-DOWN = fn [] i64
KEY-END = fn [] i64
KEY-HOME = fn [] i64
KEY-LEFT = fn [] i64
KEY-UP = fn [] i64
KEY-RIGHT = fn [] i64
KEY-DOWN = fn [] i64
KEY-DELETE = fn [] i64
SplitResult = struct { first Rect, second Rect, ratio_pct i64 }
Result returned by split-pane-state carrying both pane Rects and updated mouse-dragged ratio_pct.
EditorSnap = struct { text str, cursor i64, anchor i64 }
Undo/redo history snapshot for EditorState.
EditorState = struct { text str = ..., cursor i64 = ..., sel_anchor i64 = ..., pref_col i64 = ..., scroll_line i64 = ..., scroll_col i64 = ..., undo_stack block[EditorSnap] = ..., redo_stack block[EditorSnap] = ..., tab_width i64 = ..., syntax_vk bool = ... }
Persistent state for code-editor (multi-line cursor, selection, scroll, 64-step undo/redo, Veko syntax highlighting).
CommandItem = struct { id str, label str, category str = ..., shortcut str = ... }
Action entry displayed in command-palette.
PaletteState = struct { open bool = ..., query str = ..., selected i64 = ..., scroll i64 = ... }
Persistent state for command-palette.
FileEntry = struct { name str, is_dir bool = ..., size i64 = ... }
Pure-data directory or file entry displayed in file-picker.
FilePickerState = struct { open bool = ..., dir str = ..., filename str = ..., ext_filter str = ..., filter_on bool = ..., selected i64 = ..., scroll_y i64 = ... }
Persistent state for file-picker.
FilePickerResult = struct { action enum, path str = ... }
Result returned each frame by file-picker (action in .none, .selected, .cancelled, .chdir).
TreeNode = struct { id str, label str, depth i64 = ..., expanded bool = ..., has_children bool = ..., badge str = ... }
Hierarchical node descriptor for tree-view.
ModalResult = struct { card Rect, body Rect, closed bool }
Result returned by modal carrying the outer dialog card, inner content Rect, and close-button hit state.
ChartSeries = struct { name str, values block, color cv/Color }
Multi-series data descriptor for line-chart.
register-focusable = fn [mut st UiState, id str] bool
Registers id in the current frame's Tab-focus ring (respecting st.focus_scope_prefix) and returns true when id is focused.
cycle-focus = fn [mut st UiState, reverse bool] str
Advances (reverse == false) or reverses (reverse == true) st.focused_id along st.focus_order.
draw-focus-ring = fn [mut c cv/Canvas, r Rect, radius i64, th Theme]
Draws a soft keyboard focus halo + border ring around r.
apply-key = fn [mut st UiState, key i64, text_ch i64, sh bool, ct bool, al bool]
Injects a deterministic keyboard event (key, text_ch, and optional /shift, /ctrl, /alt modifiers) for scripted UI frames & tests.
apply-mouse = fn [mut st UiState, x i64, y i64, down bool, clicked bool]
Updates pointer coordinates and click state for the current frame.
apply-events = fn [mut st UiState, events block] bool
Feeds a frame batch of ui/UiEvent structs (or maps with .kind, .x, .y, .key, .btn) into st.
rect-contains? = fn [r Rect, px i64, py i64] bool
Returns true if point (px, py) lies inside r.
inset-edges = fn [r Rect, top i64, right i64, bottom i64, left i64] Rect
Insets r asymmetrically by (top, right, bottom, left).
vstack = fn [bounds Rect, heights block, gap i64] block[Rect]
Splits bounds vertically into stacked Rects with fixed heights and spacing gap.
use [w = ui/widgets]
rows = w/vstack (w/Rect { x = 10, y = 10, w = 200, h = 100 }) [20 30] 8
if (len rows) != 2 or rows[1].y != 38 [ err 'vstack' ] else [ .ok ]
hstack = fn [bounds Rect, widths block, gap i64] block[Rect]
Splits bounds horizontally into side-by-side Rects with fixed widths and spacing gap.
flex-row = fn [bounds Rect, tracks block[lay/Track], gap i64] block[Rect]
Solves horizontal flex columns inside bounds using w/px and w/flex tracks.
flex-col = fn [bounds Rect, tracks block[lay/Track], gap i64] block[Rect]
Solves vertical flex rows inside bounds using w/px and w/flex tracks.
grid = fn [bounds Rect, rows i64, cols i64, gap i64] block[Rect]
Solves a rows x cols uniform 2D grid inside bounds (row-major).
push-clip = fn [mut st UiState, mut c cv/Canvas, r Rect]
Pushes a nested clipping rectangle onto st and activates it on c.
pop-clip = fn [mut st UiState, mut c cv/Canvas]
Pops the top clipping rectangle from st and restores the previous clip on c.
panel = fn [mut c cv/Canvas, r Rect, title str, th Theme]
Widget 1: Draws a rounded surface card with a 1px border and optional header title band.
panel-body = fn [r Rect, has_title bool, pad i64] Rect
Returns the usable inner body Rect of a panel below its header band.
label = fn [mut c cv/Canvas, x i64, y i64, text str, scale i64, col cv/Color]
Widget 2: Draws mixed-case proportional UI text at (x, y).
heading = fn [mut c cv/Canvas, x i64, y i64, text str, scale i64, col cv/Color]
Draws semi-bold heading text at (x, y).
button = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, text str, th Theme, is_primary bool] bool
Widget 3: Draws an interactive rounded button and returns true when clicked in this frame.
Supports /primary true for high-emphasis accent fill.
use [cv = ui/canvas, w = ui/widgets]
mut c = cv/new-canvas 120 40
mut st = w/new-state
w/apply-mouse mut st 30 20 true true
th = w/light-theme
hit = w/button mut c mut st 'go' (w/Rect { x = 10, y = 8, w = 80, h = 24 }) 'Run Build' th
if not hit [ err 'button click missed' ] else [ .ok ]
icon-button = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, icon str, th Theme] bool
Widget 4: Draws a compact vector icon button ('plus', 'check', 'close', 'search', 'refresh', 'play', 'folder', 'settings').
badge = fn [mut c cv/Canvas, x i64, y i64, text str, kind str, th Theme] i64
Widget 5: Draws a semantic pill badge (kind in 'ok', 'warn', 'err', 'info', 'neutral') and returns its width.
stat-card = fn [mut c cv/Canvas, r Rect, title str, metric str, delta str, kind str, th Theme]
Widget 6: Draws a KPI metric summary card with muted label, bold scale-2 metric, and delta status badge.
text-input = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, val str, placeholder str, th Theme, masked bool] str
Widget 7: Interactive single-line text input with placeholder, focus ring, keyboard editing, and optional /secret bullet masking.
secret-input = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, mut secret_buf secret bytes, bullet_count i64, placeholder str, th Theme] i64
.secret-safe masked input widget operating directly on a mut secret bytes buffer without converting to str.
text-area = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, val str, th Theme] str
Widget 8: Multi-line editable text area with line numbers and clipped viewport.
checkbox = fn [mut c cv/Canvas, mut st UiState, id str, x i64, y i64, text str, checked bool, th Theme] bool
Widget 9: Interactive checkbox with crisp vector checkmark and clickable label; returns updated checked state.
toggle-switch = fn [mut c cv/Canvas, mut st UiState, id str, x i64, y i64, text str, on bool, th Theme] bool
Widget 10: Interactive pill toggle switch with sliding circular thumb; returns updated on state.
radio-group = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, options block, selected i64, th Theme] i64
Widget 11: Interactive radio button group (options list) stacked vertically inside r; returns selected index.
slider = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, val i64, min_v i64, max_v i64, th Theme] i64
Widget 12: Horizontal range slider (min_v..max_v) with filled track, circular thumb, and value label; returns updated value.
progress-bar = fn [mut c cv/Canvas, r Rect, pct i64, th Theme, show_pct bool]
Widget 13: Draws a horizontal progress bar inside r filled to pct (0..100).
dropdown = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, options block, selected i64, th Theme] i64
Widget 14: Select dropdown trigger + popup menu (st.open_popup_id == id controls open state); returns selected index.
chip-group = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, labels block, active_flags block, th Theme] i64
Widget 15: Horizontal filter/tag chip group (active_flags bool list); toggles clicked chip and returns clicked index (or -1).
tabs = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, labels block, active i64, th Theme] i64
Widget 16: Segmented single-view tab bar (labels); returns the active tab index.
begin-scroll = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, content_h i64, scroll_y i64, th Theme] i64
Widget 17: Begins a clipped scrollable viewport with scrollbar track/thumb and mouse-wheel scrolling; returns updated scroll_y.
end-scroll = fn [mut st UiState, mut c cv/Canvas]
Ends a begin-scroll viewport and restores the parent clip rectangle.
list-view = fn [mut c cv/Canvas, r Rect, items block, selected i64, th Theme]
Widget 18: Draws a selectable list view inside r (backward-compatible 5-arg form).
select-list = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, items block, selected i64, th Theme] i64
Interactive list view returning the newly selected row index on click or Up/Down arrow keys.
data-table = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, headers block, col_tracks block[lay/Track], rows block, selected_row i64, th Theme] i64
Widget 19: Multi-column data table (headers str list, col_tracks lay/Track list, rows 2D block) with zebra rows & row selection.
tree-view = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, nodes block[TreeNode], selected_id str, th Theme] str
Widget 20: Hierarchical tree view (nodes of TreeNode) with disclosure triangles, folder/item icons, and optional badges.
split-pane = fn [mut c cv/Canvas, mut st UiState, id str, bounds Rect, vertical bool, ratio_pct i64, th Theme] block[Rect]
Widget 21: Resizable horizontal or vertical split pane; draws interactive grip handle and returns [first_rect, second_rect].
split-pane-state = fn [mut c cv/Canvas, mut st UiState, id str, bounds Rect, vertical bool, ratio_pct i64, th Theme] SplitResult
Stateful mouse-draggable variant of split-pane returning SplitResult { first, second, ratio_pct }.
modal = fn [mut c cv/Canvas, mut st UiState, id str, viewport Rect, dialog_w i64, dialog_h i64, title str, th Theme] ModalResult
Widget 24: Modal lightbox overlay over viewport; draws dimmed backdrop + centered card + close button, returning ModalResult.
toast = fn [mut c cv/Canvas, r Rect, title str, message str, kind str, th Theme]
Widget 25: Non-blocking toast notification card (kind in 'ok', 'warn', 'err', 'info').
tooltip = fn [mut c cv/Canvas, x i64, y i64, text str, th Theme]
Widget 26: Floating high-contrast tooltip callout anchored at (x, y).
sparkline = fn [mut c cv/Canvas, r Rect, vals block, col cv/Color, th Theme]
Widget 27: Draws an anti-aliased sparkline with soft area tint inside r normalized to [min(vals)..max(vals)].
bar-chart = fn [mut c cv/Canvas, r Rect, categories block, values block, bar_col cv/Color, th Theme]
Widget 28: Labeled vertical column chart with gridlines, Y-axis scale ticks, value labels, and category axis.
line-chart = fn [mut c cv/Canvas, r Rect, x_labels block, series_list block[ChartSeries], th Theme]
Widget 29: Multi-series anti-aliased line chart (series_list of ChartSeries) with gridlines, markers, X labels, and legend.
new-editor = fn [initial str] EditorState
Creates a fresh EditorState initialized with initial source text and cursor at the end.
code-editor = fn [mut c cv/Canvas, mut st UiState, id str, r Rect, mut ed EditorState, th Theme] str
Widget 30: Multi-line Veko studio code editor with line numbers, click/drag & Shift selection,
clipboard (Ctrl+A/C/X/V), 64-step Ctrl+Z/Ctrl+Y undo/redo, auto-indent, and Veko syntax highlighting.
fuzzy-score = fn [query str, candidate str] i64
Pure-Veko subsequence + word-boundary + consecutive-run fuzzy scorer (-1 if query does not match candidate).
command-palette = fn [mut c cv/Canvas, mut st UiState, id str, viewport Rect, mut ps PaletteState, items block[CommandItem], th Theme] str
Widget 31: Fuzzy-searchable Studio Command Palette overlay (Ctrl+K / Ctrl+P style).
Returns the executed CommandItem.id (and closes ps.open = false), or '' if still open / dismissed.
entries-from-list = fn [items block] block[FileEntry]
Converts { name = str, is_dir = bool, size = i64 } maps (e.g. from fs/list-entries) into typed FileEntry values.
file-picker = fn [mut c cv/Canvas, mut st UiState, id str, viewport Rect, mut fp FilePickerState, entries block[FileEntry], th Theme, is_save bool] FilePickerResult
Widget 32: Pure-Veko zero-capability modal File Picker (entries of FileEntry, /save true for Save dialog).
Returns FilePickerResult with action in .none, .selected, .cancelled, or .chdir.