The widget kit¶
Every panel of the editor, and every panel a module adds, is drawn with the widget kit
(namespace conjure::editor::kit). A kit widget names tokens instead of colours and pixel sizes, paints through a
painter instead of raw draw calls, and is a pure measure() plus a draw(). So every panel follows the current
theme and UI scale, and no stock Dear ImGui widget shows.
Include conjure/editor/kit/kit.h, the umbrella header, or only the part you use. The umbrella includes every kit
header except conjure/editor/kit/catalogue.h. No kit header includes ImGui. Kit functions run on the main thread,
inside an ImGui frame and window, with a current kit context (the editor provides one while it draws).
| Name | The widget kit |
| Module | Editor |
#include |
conjure/editor/kit/catalogue.h, conjure/editor/kit/colour_picker.h, conjure/editor/kit/containers.h, conjure/editor/kit/controls.h, conjure/editor/kit/fields.h, conjure/editor/kit/icons.h, conjure/editor/kit/input.h, conjure/editor/kit/kit.h, conjure/editor/kit/kit_context.h, conjure/editor/kit/layout.h, conjure/editor/kit/paint.h, conjure/editor/kit/popups.h, conjure/editor/kit/record.h, conjure/editor/kit/tokens.h, conjure/editor/kit/views.h, conjure/editor/kit/widget.h, conjure/editor/kit_panel_desc.h, conjure/editor/ui/panels/widget_gallery_panel.h |
| Engineering Handbook | Widget Kit |
Syntax¶
A small widget written the way the kit's own widgets and a module's are: a props struct, a pure measure(), a
draw() through the scope's painter, and a free function that ties them together with submit(). The widget is
copied from tests/editor/kit/test_widget.cpp, which draws it and reads it back from the frame record.
#include "conjure/editor/kit/kit.h"
using namespace conjure;
using namespace conjure::editor::kit;
struct swatch_props {
colour_token colour = colour_token::ACCENT;
std::string_view label = {};
};
[[nodiscard]] math::vec2 measure(const swatch_props &props, const text_metrics &metrics) {
const math::vec2 text = metrics.measure(type_role::BODY, props.label);
return math::vec2(22.0f + 6.0f + text.x, 22.0f);
}
bool draw(widget_scope &scope, const swatch_props &props) {
const painter paint = scope.paint();
const rect box = rect::at(scope.bounds().min, math::vec2(22.0f, 22.0f));
paint.fill(box, props.colour, scope.tokens().px(metric::RADIUS_FIELD));
paint.text_in(type_role::BODY, rect{math::vec2(box.max.x + 6.0f, box.min.y), scope.bounds().max},
colour_token::BODY_TEXT, props.label);
scope.describe(props.colour, colour_token::CLEAR, colour_token::BODY_TEXT, type_role::BODY);
return scope.pressed();
}
bool swatch(std::string_view key, const swatch_props &props) {
widget_options options = {};
options.kind = widget_kind::COLOUR_SWATCH;
return submit(key, props, options);
}
measure() needs no ImGui, so a test checks the size with fixed_text_metrics. submit() measures with the
current kit context, takes a slot of that size at the layout position, opens the widget_scope, and calls draw().
At a glance¶
| If you want to... | Then use... |
|---|---|
| name a colour, a size, a text style, or a chrome fill | colour_token, metric, type_role, fill_token with the context's token_set (Tokens) |
| lay out a row of slots without ImGui | row_layout (fixed, fit, fill), row_layout::from_template("150 170 1fr") (Layout) |
| draw shapes, icons, pictures, and text in tokens | painter (Painting) |
| write a widget of your own | a props struct, measure(), draw(widget_scope &, props), and submit() (The widget pattern) |
| draw a button, toggle, checkbox, badge, label, or dropdown | the controls |
| edit a text, a number, a vector, an angle, an enum, or a colour | the fields, each returning an edit_result |
| lay out a toolbar, a status bar, a panel, or an inspector | the containers |
| open a menu, a list, a dialog, or a tooltip | the popups |
| show many rows or tiles | tree_view, grid_view, list_view, table_view (Views) |
| add an icon | kit_context::icons().add(name, svg), or a module's kit_icon_desc (Icons) |
| add a panel or a property drawer from a module | kit_panel_desc, kit_drawer_desc (What a module adds) |
| see what a frame drew | kit_context::record() (The frame record) |
| see every widget in every state | Window > Widget gallery (The Widget gallery) |
Important
Kit widgets need a current kit context (current()). The editor makes its own context current while the
workspace draws; a test or a tool makes one current with current_kit_scope.
Warning
Widgets, containers, and painters run on the main thread inside an ImGui frame and window; only the pure functions
(measure(), the arrange functions, make_token_set) need none. Drawing outside a frame corrupts ImGui's state.
frame_is_open() tells you whether a frame is open.
Variables and Properties¶
| Name | Access | Purpose |
|---|---|---|
f32 KIT_BASE_FONT_SIZE |
constant | 13, the fonts.size the kit's sizes are given at |
f32 MIN_KIT_SCALE, f32 MAX_KIT_SCALE |
constant | 0.25 and 6, the clamp of the kit's scale, shared by sizes and text |
f64 MIN_STATE_STEP, f64 MIN_HELD_STEP |
constant | 2 and 4, the least CIEDE2000 difference between a fill's states, and between rest and held |
f64 MIN_ICON_CONTRAST |
constant | 3, the contrast ratio an icon keeps on the fill it is drawn on |
f64 KEYBOARD_TOOLTIP_DELAY |
constant | 1 second, how long the keyboard's focus rests on an item before its tooltip shows |
usize MAX_ROW_SLOTS |
constant | 32, the most slots one row_layout holds; it keeps them in place, so laying out allocates nothing |
u32 NO_RECORD_ITEM |
constant | the index the frame record returns when it records nothing |
widget_kind widget_options::kind; bool interactive, hoverable, focusable, allowOverlap, pressOnClick, repeat; mouse_button_flags buttons |
public | how a widget takes part in ImGui's behaviour |
bool edit_result::started, changed, committed, cancelled, submitted |
public | what a field reports in a frame |
The widget pattern¶
conjure/editor/kit/widget.h is the authoring API the kit's own widgets and modules share. Every widget is:
- a props struct: what to show, including state the model owns (a toggle being on). The widget reports the press; the caller turns its state over;
- a pure
measure(props, text_metrics)that returns its size and needs no ImGui; - a
draw(widget_scope &, props)that paints through the scope's painter and returns what happened; - a free function that ties them together.
submit(key, props, options)is that function for any props type.
A widget_scope is one widget's registration for its lifetime. It takes a rectangle at the layout position
(widget_scope(key, size, options)), where the current layout_host puts it, or at an explicit rectangle
(widget_scope(key, rect, options)). It registers the id, runs ImGui's button behaviour when
options.interactive is set, records the widget in the frame record, and reports hovered(), held(),
pressed(), focused(), disabled(), and visible(). It draws nothing itself. A widget draws from look(),
which is its real state plus what a state_preview_scope shows, and acts on its real state.
- Keys. A key hashes like an ImGui label in the current id stack (
widget_id(key)). An interactive widget needs a key unique in its window; an empty one asserts.id_scope(key)orid_scope(index)gives widgets of the same key distinct ids, such as the rows of a list. - Disabled.
disabled_scopedisables what it encloses without ImGui's dimming, since kit widgets draw their disabled look themselves (DISABLED_TEXTcontent,DISABLED_LINEedges). A disabled widget is never hovered, held or pressed: not by the mouse, not by Space or Enter, and not byImGui::ActivateItemByID. - Composites.
save_layout_state(),restore_layout_state(), andlayout_guardput ImGui's layout cursor back after parts were placed at explicit rectangles, so a composite counts as one item.widget_options::hoverablefalse makes a frame that never takes the hover from its parts. - Field marks.
field_mark_flagssays what a field shows about its value:PERSISTED(the value survives Stop),INVALID(an error edge),READ_ONLY(no fill, muted text; it can be selected and copied) andMIXED(the values of a multiple selection differ: a faint dash instead of a value). - Shortcuts and state.
shortcut(key, modifiers, route)is true in the frame a key goes down with exactly those modifiers, honouring aFOCUSEDorGLOBALroute; submit it every frame.stored_f32,store_f32,stored_boolandstore_boolkeep a value per window across frames.set_clipboard_text(text)puts text on the clipboard.
Tokens¶
conjure/editor/kit/tokens.h. make_token_set(theme, uiScale) resolves every token of a theme at one scale; the
current kit context holds the shown theme's set (kit_context::tokens()).
A token is a name a widget draws with instead of a value.
- Colour tokens (
colour_token) are the theme's 30 colour roles, the status text (STATUS_TEXT), the derived states, and fixed constants. A role's token has the role's file name (to_string,find_colour_token):BODY_TEXTis"text"andERRis"error", becauseTEXTandERRORare Windows macros. - Derived states are never authored. A hovered fill moves towards the side its content lies on and a held fill
away from it, each only as far as everything drawn on it stays readable:
CONTROL_HOVERED,CONTROL_HELD,GHOST_HOVERED,GHOST_HELD,ROW_HOVERED,SELECTED_HOVERED,SELECTED_HELD, the play, persist, and alert steps, the accent fill family (ACCENT_FILL,ACCENT_HOVERED,ACCENT_HELD,ACCENT_FILL_TEXT), the disabled content and edge (DISABLED_TEXT,DISABLED_LINE), the popup surface and edge (POPUP,POPUP_LINE), the shade of a modal dim and a shadow (SHADE),DIMMED_TEXT,DROP_LINE,SUNKEN_HELD, andFOCUS_RING(accent).derive_state_stepsandderive_accent_fillcompute the steps for a fill of your own. - Fixed constants are the same in every theme: the axis colours (
AXIS_X#ef5b4f,AXIS_Y#4fcf6a,AXIS_Z#4c8dff), the text on an axis tag, the connected dot (ONLINE) andCLEAR. - Tones (
tone,colours_of) give the fill, edge, and text of an emphasis:NONE,ACCENT,PLAY,PERSIST,PREFAB,WARNING, andERR. - Metrics (
metric,token_set::px) are sizes in pixels at 100 %: bar heights (MENU_BAR26,TOOLBAR40,TAB_BAR28,STATUS_BAR24), control sizes, icon sizes, paddings, gaps, line widths, and radii (metric_base_value). Sizes scale by the kit's scale and snap to whole pixels. Radii follow the theme'smetrics.rounding(RADIUS_CONTROLis 5 at a rounding of 5; a rounding of 0 squares every corner) and are not rounded to whole pixels (is_radius). - Type roles (
type_role,spec_of) are the ten text styles:CAPTION,BODY,CONTROL,HEADING,TITLE,BADGE,AXIS,MONO,MONO_SMALL, andLOG, each a face (the theme's UI or code font), a weight, and a size. Colour is always a separate token. Fonts and code ligatures lists the sizes. - Fill tokens (
fill_token) are the chrome areas a theme may fill with a gradient:TITLE,TOOLBAR,STATUSandVIEWPORT.
The kit's scale is kit_scale(fonts.size, uiScale): fonts.size / 13 x uiScale, held between MIN_KIT_SCALE and
MAX_KIT_SCALE. Here uiScale is a factor, the UI scale the editor works out from your setting and
the monitor (Sizes and the UI scale). A fonts.size that is not a positive number
counts as 13 (kit_font_size).
Layout¶
conjure/editor/kit/layout.h holds rect (screen pixels, max excluded; snap() rounds it to whole pixels) and
the pure row layout, which tests run without ImGui. A row_layout(gap, paddingStart, paddingEnd) takes fixed,
fit and fill(weight, minimum) slots and arrange(origin, extent) places them: fill slots share what the others
and the gaps leave, and with too little room they keep their minimum and overflow says by how much.
from_template("150 170 1fr 150 26", gap) reads a table's column list (pixels, fractions, and fit:<pixels>) and
fails with INVALID_ARGUMENT naming the offending track. centre_in centres a size to whole pixels.
Painting¶
conjure/editor/kit/paint.h. A painter draws with tokens into one draw list. painter::window() paints into the
current window; widget_scope::paint() also records the texts it draws to that widget.
| Method | Draws |
|---|---|
fill(rect, token, radius, corners), fill_colour, fill_gradient |
a filled rectangle, snapped to pixels, in a token or in literal colours (data such as a swatch) |
fill(rect, fill_token) |
a chrome fill: flat, linear, or radial (paint_theme_fill) |
stroke, ring, dashed |
an outline inside the rectangle, a ring outside it (the focus ring), a dashed outline |
line, dashed_line, polyline, dot, circle |
crisp lines, dashed lines, open lines, and filled and outlined circles |
icon(name, position, size, token) |
an icon of the registry; currentColor takes the token |
image(texture, rect, uvMin, uvMax) |
a texture of the ImGui renderer, such as a scene picture |
text(role, position, token, text), text_in(role, rect, token, text, align) |
text in a type role; text_in centres it vertically and ends it in an ellipsis where it does not fit |
shadow(rect, radius, size) |
the soft shadow under popups and menus |
text_metrics is what measure() reads: kit_context::metrics() gives the typography's, set_metrics() injects
another, and fixed_text_metrics(emAdvance, scale) advances every character by the role's size times emAdvance.
measure_text(role, text) measures with the current context. A clip_scope cuts what a painter draws at a
rectangle without changing ImGui's hit testing.
Controls¶
conjure/editor/kit/controls.h. Each control has a props struct, a pure measure(props, text_metrics, token_set),
a draw() and a free function that takes an optional rectangle (a row_layout slot). Without one, the control goes
at the layout cursor at its measured size, or where the current host puts it. Interactive controls need a key unique
in their window; passive ones take none, except sparkline, whose key identifies its hover and tooltip.
| Control | What it is | Returns |
|---|---|---|
button |
a FRAMED, GHOST, DASHED, or PRIMARY button: an icon, the label, a muted detail, a shortcut hint, and a chevron; a tone recolours it |
pressed |
icon_button |
a borderless icon button; its label is the accessible name, recorded and never drawn |
pressed |
toggle |
an icon button with an on state, in the tone's soft fill when on | pressed |
segmented |
exclusive choices on a sunken track, the selected one on |
the index pressed |
checkbox |
a 14 px box, ticked in the accent fill, with an optional label; takes field marks | pressed |
pin_toggle |
the 20 px pin, on, partial, or covered | pressed |
dropdown |
a BUTTON or FIELD dropdown with a chevron, in its own look while open; the menu is the caller's |
pressed |
badge, dot, label, separator |
passive: a pill, a dot, a text in a role and a colour token, a vertical or horizontal rule | nothing |
progress |
a bar filled by a fraction, or indeterminate | nothing |
sparkline |
a line through values on a sunken box, its sample under the pointer in a tooltip | nothing |
States that are not authored are derived: hovered and held fills from the derived tokens, a 1 px FOCUS_RING just
outside a control that keyboard navigation focused, and one disabled look inside a disabled_scope.
Fields¶
conjure/editor/kit/fields.h. The kit paints a field until it is activated: a click anywhere on it, or Enter while it
has the keyboard focus. ImGui then edits the kit's one shared buffer over the field's rectangle. Enter commits,
Escape cancels, and a click elsewhere commits. A field's id is its hidden label's, "##<key>" (field_id(key)).
Every field returns an edit_result. started comes in the frame the edit begins, changed in each frame its text
or value changes, then committed (the value was written) or cancelled (Escape, the same text, or a number that
does not parse) in the frame it ends. The editor's undo stack coalesces on these: one entry from started to
committed.
| Field | Notes |
|---|---|
text_field |
one line of text in a type role, a placeholder in faint while empty. It holds 1 KiB unless unbounded; a longer value is edited read-only. live follows the text as it is typed; takeFocus starts the edit in this frame |
search_field |
a text field with a leading search icon; without an icon, the console's filter |
number_field |
over f64, f32, i64, i32, or u64. Dragging changes the value live (speed per pixel, clamped to minimum and maximum); a click without a drag, a double click, Ctrl+click, or Enter edits the text. inf, -inf, and nan are accepted. Integers stay exact across their whole type. unit shows after the value at rest ("13 px") |
vector_field |
2 to 4 floats, each a number field joined to its tag: AXES (X Y Z W), CHANNELS (R G B A), RECT (X Y W H) or NONE |
angle_field |
1 to 4 angles in degrees, shown with ANGLE_UNIT (°); the caller converts to radians or a quaternion |
enum_field |
a FIELD dropdown that opens a popup list of names; a chosen row reports started and committed in one frame. enum_field_props::enabled, one bool per name in the order of names, greys out single names: a false name is a disabled row of the list and cannot be chosen (Popups). If it is the selected name, the field still shows it as the value, in its normal look. Names past the end of enabled stay enabled |
reference_field |
an entity reference: shows a display name at rest, edits the value itself |
colour_swatch |
an 8-bit colour or 3 or 4 float channels; opens the colour picker, carries its colour by drag and drop, and copies or pastes its hex from its context menu |
asset_slot |
a 22 px thumbnail and a text field with the asset's name |
format_number and parse_number are the text rules of number fields.
Property rows¶
The inspector's rows are property_row scopes inside a property_section of a property_grid
(Containers). A row lays out [change dot][label][values][pin] and is the layout host while it lives,
so the values submitted inside go left to right in its values slot. Pass row.field_marks() in your fields' props
so they take the row's persisted, read-only, and mixed marks.
property_row_props member |
Purpose |
|---|---|
label |
the row's label, in BODY muted |
hint |
the row's tooltip over its label and values; empty: the label where its slot cuts it |
marks |
a row_marks: the change dot, the persisted mark, and the pin during play |
pinLabel, changeLabel |
the pin's accessible name and tooltip, the change dot's tooltip |
lines |
how many value lines the row has (a matrix's four) |
readOnly, mixed |
the values take READ_ONLY or MIXED (field_marks()) |
wrapLabel |
a label its slot would cut wraps between words onto lines of its own, and the row grows as tall as it needs, so the label reads whole |
Without wrapLabel, a label wider than its slot ends in an ellipsis. property_grid_props::labelWidth widens the
label slot of every row of a grid, in pixels at 100 %; the grid takes it as it is, never under the default 78
(property_label_width). A grid of long labels passes the smaller of its widest label and
property_label_room(gridWidth, pinColumn, tokens), so its values keep their 198 px at 100 % (PROPERTY_VALUES_WIDTH).
The colour picker¶
conjure/editor/kit/colour_picker.h. colour_picker(key, value, props) edits an 8-bit colour or 3 or 4 float
channels live: a saturation and value area under the hue, a hue strip, an alpha strip, the colour before the edit
and now as two chips (a press on the before chip puts it back), the hex field, and the channels. A float colour with
hdr may lie past 1; its area then keeps the colour's intensity and the hex field gives way to the intensity. A drag
on the area or a strip is one edit, and Escape puts back the colour it started from. A colour_swatch opens the
picker in a popup.
gradient_stops(key, stops, props) edits a gradient's stops as a bar with a handle per stop: press a handle to
select its stop, drag it between its neighbours, press the bar to add a stop there, and edit the selected stop's
colour and position under the bar. The Theme editor uses it for a theme's
chrome gradients.
Containers¶
conjure/editor/kit/containers.h. Containers are scopes that cannot be copied or moved.
viewport_bar(name, edge, height, navigable)is the window of a fixed bar across the main viewport, at the top (TOP, under the bars submitted before it) or the bottom (BOTTOM). It reserves its strip of the work area from the next frame on. Draw only whilevisible(). The editor's toolbar and status bar are two of them.screen(name, props)is a window over the rest of the work area, behind every other window, with one centred column: the start screen.toolbar_strip(key, size)is a bar across the width left on the line:MAIN40 px with the theme's toolbar fill,SUB32 andTOOL30 on the panel. While it is open it places the widgets submitted inside it left to right.spacer(weight)shares the free space,separator()adds a 1 x 20 rule,slot(width)a fixed column.toolbar_group(strip, look)clusters widgets inside a strip,PLAINor on aSEGMENTEDtrack.status_strip(key)collects up to 16status_segments (a text in a role and colour, an optional dot or icon,trailingfor the right side) and, when it closes, arranges them witharrange_statusand paints them on the theme's status fill, 24 px tall. The segments' texts must outlive the strip.panel_shell(chrome)is the body of every docked panel. Beforebegin()a panel sets its tab decoration (set_icon,set_badge,set_status_dot,set_unsaved) and shape (set_flush,set_scrollable,set_floating_size). After a visiblebegin()it addsheader_actions, shows afooter(start, end), and then opens its scrolling content withbegin_content(), which keeps the footer's height free. The dock chrome (dock_chrome,dockspace_scope) draws each tab from that decoration.property_grid,property_section,property_row,property_groupare the inspector's body: a grid of collapsible sections (a component each), their rows (Property rows) and nested groups. Aproperty_revealsends the grid to a section or a row: it opens it, scrolls it into view, and highlights it.overlay_cardandbannershow spans of text over a picture or in the flow of a panel (the stats chip, the play banner, the prefab banner).picture(key, props)shows a texture of the ImGui renderer over its backdrop, with the play border, as the Scene and Game panels do.
Warning
A strip's spacer() needs the width of everything after it, which an immediate-mode strip learns only at its end.
The strip keeps the last frame's total, so a centred cluster lands one frame after a width change, and in a
strip's first frame what follows its first spacer is hidden.
Popups¶
conjure/editor/kit/popups.h. Popups live on ImGui's popup stack and keep ImGui's behaviour: keyboard navigation,
hover-open submenus, a click outside closing them, Escape closing the top one. The kit alone draws them.
- Menus.
menu_baris the main menu bar;menu(key, props)is a title in the bar or a submenu row;menu_item(key, props)returns true in the frame it is pressed;menu_separator()divides groups of items. An item shows an optional icon, its label, a shortcut hint or a detail, and a check mark. - Opened by a widget.
open_popup(key)in the frame the opener was pressed, then apopup_menu(key)of menu items or apopup_list(key, rows, props)of rows each frame.context_menu(key, props)opens on a right click over the last item or the window.close_popup,close_current_popup, andis_popup_openmanage them. Alist_rowwhoseenabledisfalseis drawn disabled and is never chosen. It takes no hover or keyboard focus, so Up and Down skip it. Ifpopup_list_props::selectednames a disabled row, the list opens with the keyboard on the nearest enabled row (the earlier one when two are as near), so Enter right after opening chooses that row. - Dialogs.
modal_dialog(key, props)dims what is behind it and opens centred. Itsbuttons(row)draws the confirm, alternative, and cancel buttons and returns thedialog_choice. Escape cancels; Enter confirms unless the confirm button is disabled ordestructive. The dialog stays open until the caller callsclose(). - Tooltips.
tooltip(text)shows a tooltip for the widget submitted last, also when it is disabled, so it can say why it cannot be used.show_tooltip(text)shows one at the pointer now, for a widget that knows its own hover; asktooltip_due()first. A long text wraps atTOOLTIP_MAX_WIDTH(480 px at 100 %).
The tooltip rule decides when a tooltip shows, for tooltip() and tooltip_due() alike:
- On the pointer: after ImGui's delay, while the pointer rests on the item.
- On the keyboard's focus: only after a navigation key (an arrow, Tab, Home, End, Page Up, or Page Down) moved
the focus to the item, and the focus rested there for
KEYBOARD_TOOLTIP_DELAY. Focus that a closing popup gave back never shows one. - Never while a mouse button is down, or while the item is held, by the pointer or by Space or Enter.
- Not after a press, or after a popup closed, until the pointer moves.
Views¶
conjure/editor/kit/views.h. A view opens a scrolling child window and submits only the rows it shows, through
ImGui's list clipper, so its cost does not grow with rows out of view. The caller owns the data: it tells the view
how many rows there are, draws the rows the view asks for in a while (view.step()) loop from first() to
last(), and applies the events the view reports. A view never changes the data.
| View | Use |
|---|---|
tree_view |
a hierarchy: selection, expansion, keyboard moves, drag and drop, inline rename; events() reports what the user asked for |
grid_view |
tiles with thumbnails or type icons, dragged out as GRID_DRAG_PAYLOAD |
list_view |
console lines (LOG) or undo history entries (HISTORY), optionally following the bottom |
table_view, table_row |
sortable, resizable columns of cells |
empty_state |
an icon, one line, and an optional action where there is nothing to show |
Every view scrolls under the kit's overlay scrollbar, which lies over the rows' right edge and shows while the pointer is over the view or it scrolls.
Icons¶
conjure/editor/kit/icons.h. Icons are vector files in a strict SVG subset: path, rect, circle, ellipse,
line, polyline, polygon, and g (translate and scale only), with fill, stroke, widths, caps, joins, dash
arrays and opacities. A paint is none, currentColor (the colour the widget passes), var(--<token>) (a colour
token by its theme name, such as var(--accent)) or #rrggbb. Anything else is refused and reported by its path
(svg.path[1].stroke-miterlimit). parse_icon_svg(text) returns the parsed icon and every problem.
- Limits keep a hostile file from exhausting the parser or the mesher:
ICON_MAX_GROUP_DEPTH(32),ICON_MAX_ELEMENTS(1024),ICON_MAX_ATTRIBUTES(64),ICON_MAX_COMMANDS(4096) and the viewBox boundsICON_VIEW_BOX_MIN_SIZEandICON_VIEW_BOX_MAX_EXTENT. Holes and even-odd fills are not supported. - The registry. The kit context's
icon_registryholds 32 built-in icons (builtin_icon_names():tool.*,play.*,persist.pin,history.*,entity.*,component.*,check.tick, and others).add(name, svg)registers one more (ALREADY_EXISTS, orINVALID_ARGUMENTwith the problems) andremove(name)drops it. - Drawing. An icon is flattened once per pixel size and cached. A name with no icon draws a crossed box in the
error colour and warns once.
icon_tint::CALLERgives every paint the caller's colour, which a disabled widget uses.
Input¶
conjure/editor/kit/input.h reads the pointer and the keyboard as the current ImGui frame sees them, for surfaces
that read more than a widget_scope reports (the Scene panel's camera drags). mouse_position, mouse_delta,
mouse_wheel, mouse_down, mouse_clicked, mouse_dragging, modifiers_held, key_pressed,
key_chord_pressed, text_input_active, window_focused, window_hovered, and framebuffer_scale answer with a
neutral value without an ImGui context. leave_input_to_engine(mouse, keyboard) lets the engine, and the game in the
Game panel, have the next frame's events.
The kit context and the stock style¶
conjure/editor/kit/kit_context.h. A kit_context owns the tokens, the typography of the ten type roles, the icon
registry, the edit session text fields share, and the frame record. begin_frame() and end_frame() bracket a kit
frame. current(), set_current(), and current_kit_scope choose the context the free functions use.
apply_theme(theme, uiScale) resolves the tokens at uiScale and writes ImGui's global style through the stock
colour table (stock_colours()), which puts every ImGui colour in one group: PRIMITIVE (a token, drawn by ImGui's
own primitives), HIDDEN (transparent) or STOCK_WIDGET (read only by ImGui's stock widgets).
Warning
In the CANARY stock style, the default in Debug builds, the stock-widget colours are magenta
(CANARY_COLOUR). A stock ImGui widget that slipped into a kit surface shows at once, and end_frame() counts
its vertices and warns once per window. Other builds use COMPAT, the nearest kit look. A legacy module panel
draws in COMPAT; a surface drawn inside a stock_canary_scope shows the canary while canary_enabled().
The frame record¶
conjure/editor/kit/record.h. frame_record lists every kit widget of the frame in submission order: its
widget_kind, ImGui id, key, rectangle, item_state_flags, the tokens and type role it says it drew with
(widget_scope::describe) and the texts it drew (the source text, never a ligature's private glyphs). find(key),
find_id(id) and count(kind) look items up; key_of and text_of read an item's strings. Tests find controls
in it. No protocol command reads it.
The catalogue¶
conjure/editor/kit/catalogue.h describes every kit widget as data. widget_catalogue() lists one widget_desc
per widget: its name, version, the widget_kind the frame record holds for it and for its parts, its public header,
its props (prop_desc: name, kind, default as text, enumeration values, and whether it is bindable, two-way,
nullable, an argument, or required), its events, its children, and an example. find_widget_desc(name) and
find_prop(widget, name) look one up. The Widget gallery draws its sections from the catalogue.
What a module adds¶
conjure/editor/kit_panel_desc.h holds the records a module registers to add editor UI drawn with the kit. They
are trivially copyable extension records: register them with context.registrar().register_extension(desc)
(Registering extensions).
| Record | Adds |
|---|---|
kit_panel_desc { name, title, icon, draw, userData, openByDefault } |
a panel registered as "<module>.<name>"; the Window menu lists it by its title. draw(panel_shell *, userData) draws its body with the kit every frame its window shows; the shell has begun the window, so it may add header actions, call begin_content(), and show a footer |
kit_icon_desc { name, svg } |
an icon in the kit's registry while the module is loaded, for its panels' tabs and its widgets. An SVG the kit refuses, or a built-in icon's name, is left out with a warning, and a widget drawing it shows the crossed box |
kit_drawer_desc { typeName, draw, userData } |
a property drawer for one reflected type. draw(property_row *, json::document *value, userData) edits the value in place and returns true when it changed; the inspector writes it back through component.set |
The editor copies each record when the module attaches, removes it when the module detaches, and makes it again
after a reload. A module whose records are malformed or clash fails to attach with REGISTRATION_CONFLICT: a panel
without a name, a title, or a draw function, or whose name holds a line break, = or ##; two panels of one name, or
a panel name another module registers; an icon without a name or an SVG, or one named twice; a drawer without a type
name or a draw function, or two for one type; or an icon or a drawer that another attached module registers. Module
code never receives the ImGui context through these records: a kit panel draws inside a stock_canary_scope.
Tip
The legacy panel_desc, whose callback takes the raw ImGui context, still loads, but it is drawn with stock
ImGui widgets in the COMPAT look and is deprecated. Use kit_panel_desc for a new panel.
The Widget gallery¶
Window > Widget gallery opens widget_gallery_panel (conjure/editor/ui/panels/widget_gallery_panel.h, registry
name widget_gallery, closed by default). It shows every widget of the catalogue, except the frames it is drawn in
or around (FRAME_WIDGETS), in every state the kit derives, in the current theme. Each section is a table: a row
per widget or variant, and the columns Rest, Hovered, Held, Focused, and Disabled. The Rest column holds live widgets
to try. A theme row switches between the six built-in themes
(show_theme(context, name), which sends editor.theme.set). Each section's title names its widgets in its tooltip
(sections(), section_hint()).
Functions¶
| Signature | Purpose |
|---|---|
token_set make_token_set(const theme &value, f32 uiScale = 1.0f) |
resolves every token of a theme at one scale |
const theme_colour &token_set::colour(colour_token token) const, f32 token_set::px(metric size) const |
reads a colour or a size from a token set |
f32 kit_scale(f32 fontSize, f32 uiScale), f32 kit_font_size(f32 fontSize) |
the kit's scale |
state_steps derive_state_steps(const theme_colour &rest, const theme_colour &partner, f32 hoveredMix, f32 heldMix, const theme_colour &text) |
the hovered and held steps of a fill of your own |
accent_fill_colours derive_accent_fill(const theme_colour &accent, const theme_colour &accentText) |
the accent fill family |
std::optional<colour_token> find_colour_token(std::string_view name) |
a colour token by its theme name; to_string(colour_token) is the reverse |
tone_colours colours_of(tone emphasis) |
the fill, edge, and text of a tone |
f32 metric_base_value(metric size), type_spec spec_of(type_role role) |
a size at 100 %, a type role's face, weight, and size |
row_arrangement row_layout::arrange(f32 origin, f32 extent) const |
places a row's slots; fixed, fit, fill, and from_template add them |
f32 centre_in(f32 start, f32 extent, f32 size) |
centres a size to whole pixels |
static painter painter::window(u32 recordItem = NO_RECORD_ITEM) |
a painter for the current window's draw list |
painter(ImDrawList &drawList, kit_context &kit, u32 recordItem = NO_RECORD_ITEM) |
a painter for any draw list |
u32 paint_theme_fill(ImDrawList &drawList, const rect &area, const theme_fill &fill) |
paints a chrome fill |
math::vec2 measure_text(type_role role, std::string_view text) |
measures text with the current context; fixed_text_metrics(f32 emAdvance = 0.6f, f32 scale = 1.0f) for tests |
widget_scope(std::string_view key, const math::vec2 &size, const widget_options &options = {}) |
one widget's registration at the layout position; a rect overload places it explicitly |
decltype(auto) submit(std::string_view key, const PropsType &props, const widget_options &options = {}) |
measures, places, and draws a widget of the widget pattern |
u32 widget_id(std::string_view key), u32 field_id(std::string_view key) |
the ImGui id of a key, and of a field's hidden label |
id_scope(std::string_view key), id_scope(u64 index), disabled_scope(bool disabled = true), state_preview_scope(item_state_flags look), layout_guard() |
scopes |
bool shortcut(platform::key key, platform::key_modifier_flags modifiers = platform::key_modifier_flags::NONE, shortcut_route route = shortcut_route::FOCUSED) |
true in the frame the key goes down with exactly those modifiers |
f32 stored_f32(std::string_view key, f32 fallback = 0.0f), void store_f32(std::string_view key, f32 value) |
per-window state; stored_bool and store_bool alike |
void set_clipboard_text(std::string_view text) |
puts text on the clipboard |
bool button(std::string_view key, const button_props &props, const std::optional<rect> &bounds = std::nullopt) |
a button; icon_button, toggle, checkbox, pin_toggle, and dropdown take a key, their own props, and the same optional rectangle |
std::optional<usize> segmented(std::string_view key, const segmented_props &props, const std::optional<rect> &bounds = std::nullopt) |
the index pressed |
void badge(const badge_props &props, const std::optional<rect> &bounds = std::nullopt) |
a passive control; dot, label, and progress alike |
edit_result text_field(std::string_view key, std::string &value, const text_field_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
a field; search_field, reference_field, and asset_slot also edit a std::string |
edit_result number_field(std::string_view key, f64 &value, const number_field_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
a number field; overloads for f32, i64, i32, and u64 |
edit_result vector_field(std::string_view key, std::span<f32> values, const vector_field_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
2 to 4 floats; angle_field edits degrees alike |
edit_result enum_field(std::string_view key, usize &selected, const enum_field_props &props, const std::optional<rect> &bounds = std::nullopt) |
a choice from a list of names |
edit_result colour_swatch(std::string_view key, theme_colour &value, const colour_swatch_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
a colour; an overload takes std::span<f32> channels |
std::optional<f64> parse_number(std::string_view text) |
the text rule of number fields; format_number writes one |
edit_result colour_picker(std::string_view key, theme_colour &value, const colour_picker_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
the colour picker; an overload takes float channels |
edit_result gradient_stops(std::string_view key, std::vector<theme_gradient_stop> &stops, const gradient_stops_props &props = {}, const std::optional<rect> &bounds = std::nullopt) |
the gradient stop editor |
hsv_colour to_hsv(f32 r, f32 g, f32 b), math::vec3 to_rgb(const hsv_colour &hsv) |
colour conversions |
viewport_bar(std::string_view name, bar_edge edge, f32 height, bool navigable = true) |
a fixed bar across the main viewport; screen is the start screen's window |
toolbar_strip(std::string_view key, strip_size size = strip_size::MAIN), toolbar_group(toolbar_strip &strip, group_look look = group_look::SEGMENTED) |
a toolbar and its groups |
status_strip(std::string_view key) |
a status bar |
panel_shell(panel_chrome &chrome) |
a docked panel's body; dock_chrome draws the tabs |
property_grid(std::string_view key, const property_grid_props &props = {}) |
an inspector's body; property_section, property_row, and property_group nest in it |
overlay_card(std::string_view key, const overlay_card_props &props), banner(std::string_view key, const banner_props &props = {}) |
text over a picture or in a panel's flow |
picture_reply picture(std::string_view key, const picture_props &props, const std::optional<rect> &bounds = std::nullopt) |
a renderer texture over its backdrop |
menu_bar(), menu(std::string_view key, const menu_props &props) |
the main menu bar and its menus |
bool menu_item(std::string_view key, const menu_item_props &props), void menu_separator() |
menu rows |
void open_popup(std::string_view key), void close_popup(std::string_view key), bool is_popup_open(std::string_view key) |
popups a widget opens; close_current_popup() closes the popup being drawn |
popup_menu(std::string_view key, const popup_menu_props &props = {}), context_menu(std::string_view key = {}, const context_menu_props &props = {}) |
a widget's menu and a right-click menu |
std::optional<usize> popup_list(std::string_view key, std::span<const list_row> rows, const popup_list_props &props = {}) |
a popup list of rows |
modal_dialog(std::string_view key, const dialog_props &props) |
a modal dialog |
bool tooltip(std::string_view text), bool tooltip_due(), void show_tooltip(std::string_view text) |
tooltips |
tree_view(std::string_view key, const tree_view_props &props) |
a hierarchy; grid_view, list_view, and table_view take a key and props alike |
table_row(table_view &table, usize index, const table_row_props &props = {}) |
one row of a table |
bool empty_state(std::string_view key, const empty_state_props &props, const std::optional<rect> &bounds = std::nullopt) |
an empty view's icon, line, and action; true in the frame the action is pressed |
icon_parse_result parse_icon_svg(std::string_view text) |
parses an icon file |
core::result<void> icon_registry::add(std::string_view name, std::string_view svg) |
registers an icon; remove(name) drops it and find(name) looks it up |
std::span<const std::string_view> builtin_icon_names() |
the 32 built-in icons |
std::optional<math::vec2> mouse_position(), math::vec2 mouse_delta(), f32 mouse_wheel(), bool mouse_down(mouse_button button) |
the pointer |
bool key_pressed(platform::key key, bool repeat = false), bool key_chord_pressed(platform::key key, platform::key_modifier_flags modifiers = platform::key_modifier_flags::NONE) |
the keyboard |
void leave_input_to_engine(bool mouse, bool keyboard) |
gives the next frame's events to the engine |
void kit_context::apply_theme(const theme &value, f32 uiScale = 1.0f) |
resolves the tokens and writes ImGui's style |
kit_context *current(), void set_current(kit_context *context), current_kit_scope(kit_context &context) |
the context the free functions use |
stock_canary_scope() |
shows the canary on every stock-widget colour while it lives, when the canary is enabled |
std::span<const stock_colour> stock_colours() |
the stock colour table |
void apply_stock_style(const theme &value, f32 uiScale, stock_style style, ImGuiStyle &target) |
writes a fresh ImGui style for a theme |
f32 density_factor(theme_density density) |
0.75, 1, or 1.5 |
const record_item *frame_record::find(std::string_view key) const |
an item of the frame record; find_id, count, key_of, and text_of alike |
std::span<const widget_desc> widget_catalogue() |
every kit widget as data |
const widget_desc *find_widget_desc(std::string_view name), const prop_desc *find_prop(const widget_desc &widget, std::string_view name) |
looks a widget or a prop up |
core::result<void> widget_gallery_panel::show_theme(editor_context &context, std::string_view name) |
switches the active theme from the Widget gallery |
static std::span<const section_desc> widget_gallery_panel::sections(), static std::string section_hint(const section_desc §ion) |
the gallery's sections and their tooltips |
See also:
- 📘 API: Themes, Fonts and code ligatures, The toolbar and the status bar
- 📘 API: The workspace UI, Writing a module, Glossary
- 🛠 Handbook: Widget Kit, User Interface