Icon Picker
alikit:icon_picker is a complete composite built from public parts: search, a virtualized grid or list
of icon choices, roving keyboard focus, semantic selection, one activation event, and two
appearances that share one behavior contract. It is ordinary copyable Odin source built only on
Alicorn’s public UI and runtime APIs. picker() is a convenience wrapper over
search, grid_begin, item_begin, cell/row,
item_end, and grid_end.
Preview
Section titled “Preview”
Responsibility split
Section titled “Responsibility split”| Layer | Responsibility |
|---|---|
| Alicorn | Modal overlay, focus, text field, virtual list, roving view model, Button owners, semantics, layout, and rendering. |
icon_picker | Query and matches, search part, grid/list appearances, cell/row drawing, active key, reveal, and one activation proposal. |
| Application | Choices, accepted selection, commands, surrounding dialog, and focus restoration. |
Copyable implementation
Section titled “Copyable implementation”Files: icon_picker/icon_picker.odin, icon_picker/icon_picker_test.odin,
examples/icon_picker/main.odin. The example imports the package by relative path, so the pair
builds with only the Alicorn collection; the test suite also proves the copied-source path.
import alicorn "alicorn:runtime"import ui "alicorn:ui"import picker "alikit:icon_picker" // or a relative copy
App :: struct { icon: picker.State, choices: [2]picker.Choice, selected_key: u64, open: bool,}
render_overlays :: proc(app: ^App, ctx: ^ui.UI) { if !app.open { return } if alicorn.modal_overlay_begin(ctx, "icon-dialog") == 0 { return } if ui.panel(ctx, width=420, height=alicorn.LAYOUT_SIZE_FIT_CONTENT, padding=16) { _ = alicorn.semantic_description(ctx, .Dialog, "Choose an icon") event := picker.picker(ctx, &app.icon, app.choices[:], picker.Options{accessible_label="Icons"}, key=alicorn.key_string("app-icon-picker"), instance_id=1) if event.kind == .Activated { app.selected_key = event.key app.open = false } } alicorn.modal_overlay_end(ctx)}
main :: proc() { app := App{ choices={ {key=1, label="Search", icon=.Search}, {key=2, label="Settings", icon=.Settings}, }, } if !picker.init(&app.icon) { return } defer picker.destroy(&app.icon) app.icon.selected_key = app.selected_key ui.run(&app, render, render_overlays=render_overlays, title="Icon Picker", width=640, height=480)}state.selected_key is controlled by the application; the picker never mutates it. Keyboard,
pointer, and semantic activation all produce the same Event{kind=.Activated, key=...} proposal.
Parts and identities
Section titled “Parts and identities”| Part | Public surface | What can be omitted or replaced |
|---|---|---|
| Search | search, Options.hide_search, search_accessible_name, state.query | Use set_query/query_text or provide your own query field. |
| Collection | grid_begin/grid_end, Options.accessible_label, appearance, columns, cell_size, row_height, max_visible_rows | Grid or list layout; pass a scope_owner for the shared keyboard scope. |
| Cell/row | item_begin/item_end, Grid_Item, cell, row | Replace drawing while keeping stable keys and semantics. |
| Identity | choice_semantic_id, collection_semantic_id | Stable application keys and one instance_id. |
| Activation | Event, grid_end | The picker proposes; the application accepts. |
| Navigation | handle_key | Drive navigation from an application-owned query field. |
| Focus | request_search_focus, request_grid_focus | Application input decides when to request focus. |
| Theme | Alicorn core color roles only | No component theme contract is required. |
Three examples cover the paths: the default composite (examples/icon_picker), custom cells and
rows (examples/icon_picker_parts), and a dialog + Segmented appearance host
(examples/icon_picker_composition).
Choice.keywords contributes to search but is not announced. Choice.detail is announced in both
appearances; the grid does not paint it. Choice.label is always the accessible name.
Styling, motion, and theme
Section titled “Styling, motion, and theme”The picker uses Alicorn core roles (Surface, Text, Muted_Text, Selection, Accent) and
has no theme contract. Appearance is controlled by Options.appearance:
.Gridpaints square icon cells with a tooltip-free visual label and an accessible name..Listpaints full-width rows with an icon, label, and detail text.- Both share the same choices, filter, stable keys, semantic IDs, states, actions, and keyboard step. Switching appearance keeps focus on the collection and preserves identity.
- There is no picker-authored motion. Hover, focus, and selected presentation come from Alicorn control recipes; the picker does not own an animation lifecycle.
Keyboard and accessibility contract
Section titled “Keyboard and accessibility contract”| Input | Result |
|---|---|
Up / Down | Grid: one row. List: one item. Disabled choices are skipped. |
Left / Right | Grid: one cell. List: ignored. |
Home / End | First/last enabled cell of the active row (list: first/last). |
Page Up / Page Down | One page of rows/cells. |
Return / Space | Propose the active enabled choice. |
| pointer | Propose the clicked enabled choice. |
| query edit | Refilter; keep the active key when visible, otherwise choose the nearest enabled row. |
- While search owns focus, arrows, Home/End, Page Up/Page Down, and Space drive the grid through
Alicorn’s
text_preempt_keyspolicy. Characters, Backspace, Delete, and IME composition stay with the field. - The collection publishes
List_Box+List_Box_Optionsemantics with logical count, realized range,Selected,Current,Disabled, andSelect/Focusactions. - Virtualization publishes only realized rows;
virtual_list_ensure_visiblereveals the active row. - Not claimed: a dedicated Grid semantic role,
Ctrl+Home/Ctrl+End, fuzzy ranking, or a platform accessibility bridge in headless tests.
Conformance tests
Section titled “Conformance tests”icon_picker/icon_picker_test.odin runs eleven external-package tests:
- token matching, stable identity, and selection reconciliation;
- keyboard, pointer, and semantic activation parity;
- focus versus selection, disabled skipping, removal, and reorder;
- appearance switch with identical cell identity and bounds change;
- filtering, IME yield, and search-focus arrow/Space yield;
- 200-choice virtualization and reveal;
- the
.Modal_Dialogpattern check with a positive run and a negative control; - Escape, outside-click, and nested overlay dismissal with focus restoration;
- teardown idle and an application
Ctrl+Ffocus interaction.
odin test icon_picker -collection:alicorn=<alicorn> -collection:alikit=../out/icon_picker_example.exe --smokeHeadless tests do not exercise OS IME candidate windows, native accessibility bridges, or pixels.
API reference
Section titled “API reference”| Declaration | Notes |
|---|---|
State | Query buffer, filtered matches, active key, focus/reveal flags. Call init and destroy. |
Choice | key, label, icon, keywords, detail, disabled. |
Options | Labels, appearance, columns, cell/row geometry, visible rows, icon size, hide_search. |
Appearance | .Grid or .List. |
Grid / Grid_Item | Per-description collection and cell/row contexts. |
Event / Event_Kind | One-shot Activated proposal carrying key. |
picker | Describe the composite and return an activation event. |
search, grid_begin, grid_end, item_begin, item_end, cell, row, empty | Public parts. |
sync, handle_key | Refresh matches and drive navigation from an application-owned scope. |
set_query, query_text, active_key, match_count | Controlled query and diagnostics. |
request_search_focus, request_grid_focus | Request an after-frame focus. |
choice_semantic_id, collection_semantic_id | Stable semantic identities. |
Limits
Section titled “Limits”- The grid has no dedicated Grid role; it publishes a
List_Boxwith positions. Home/Endare row bounds; there is noCtrl+Home/Ctrl+Endintent.- Filtering is local ASCII case-insensitive substring matching; replace
matchesfor domain ranking. - Space activation is subject to Alicorn’s text-preemption rule when the search field owns focus.
Compatibility
Section titled “Compatibility”47c9d4a7cd1f637876190fec899daeeac00a30ae. See
Compatibility and pinning.