Skip to content

Editor → Widget Kit

widget.h

The widget authoring API, used by the kit's own widgets and by modules alike. Every widget has four parts: a props struct, a pure measure, a draw through a widget_scope, and a free function that ties them together.

Structs

File Description
kit::edit_result What a text, number or vector field reports in a frame, which feeds the undo stack's coalescing: started (an edit began), changed (the edit text changed), committed (the edit ended with a new value) or cancelled (it ended without one, Escape or the same text). submitted is true when Enter (or the keypad's) ended the edit, committed or not: a form submits on it, as ImGui's EnterReturnsTrue did.
kit::layout_state The layout cursor of the current window as its last item left it: the position and the line state ImGui keeps for the next item. A composite widget (a vector field, a segmented control) or a container places its parts at explicit rectangles, each of which moves the cursor; it saves the state after taking its own rectangle and puts it back when it closes, so what follows is laid out as if the composite were one item.
kit::widget_options How a widget takes part in ImGui's behaviour.

Classes

File Description
kit::disabled_scope Disables the widgets inside for its lifetime (ImGui's disabled stack) when disabled is true. ImGui's own dimming is off inside it (DisabledAlpha 1): the kit's widgets draw the disabled look themselves, content in faint.
kit::id_scope Pushes a key (or an index) on ImGui's id stack for its lifetime, so widgets inside get distinct ids. A key hashes as an ImGui label does; an empty one asserts (in a build without asserts it pushes what ImGui's empty label does, the current seed). An index hashes as data, its eight bytes.
kit::layout_guard Saves the layout state when made and restores it when it ends. Cannot be copied or moved.
kit::layout_host A container that places the widgets submitted inside it (toolbar_strip, toolbar_group): while it is the current kit context's host, a widget_scope of a measured size asks it for its rectangle instead of taking one at ImGui's cursor. A widget given an explicit rectangle never asks.
kit::state_preview_scope Shows the widgets submitted inside it in a state they are not in, for its lifetime: the Widget gallery draws its hover, held and focus samples with it (the undrawn states). Only the look changes (widget_scope::look()); behaviour, the frame record's state and what the widgets return keep their real state. Flags outside PREVIEWABLE_STATES are ignored; nested scopes add up. Needs a current kit context.
kit::widget_scope One widget's registration, behaviour and record for its lifetime. Cannot be copied or moved.

Enumerations

kit::field_mark_flags

enum class field_mark_flags : u8 {
    NONE = 0,
    PERSISTED = 1 << 0,
    INVALID = 1 << 1,
    READ_ONLY = 1 << 2,
    MIXED = 1 << 3
};

What a field shows about its value: PERSISTED (a persist edge plus a 1 px persistSoft ring outside: the value survives Stop), INVALID (an error edge), READ_ONLY (no fill, muted text; it can be selected and copied, never changed), MIXED (the values of a multiple selection differ: a faint dash where the value's text starts instead of a value; a text edit starts from an empty text, so Enter on it changes nothing, and a drag starts from the value the field is given). Fields take them in their props; a property row gives its own (property_row's field_marks()). Here rather than in fields.h because dropdowns (controls.h) take them too.

kit::mouse_button_flags

enum class mouse_button_flags : u8 {
    NONE = 0,
    LEFT = 1 << 0,
    RIGHT = 1 << 1,
    MIDDLE = 1 << 2,
    ALL = LEFT | RIGHT | MIDDLE
};

The mouse buttons an interactive widget answers to (ButtonBehavior's).

kit::shortcut_route

enum class shortcut_route : u8 {
    FOCUSED = 0,
    GLOBAL
};

Who a shortcut answers to: FOCUSED, only while the window submitting it (or one of its children) has the keyboard focus; GLOBAL, whatever has the focus, unless an item or window that claimed the same keys has it (a text field being edited keeps Ctrl+Z for its own undo).

Constants

Name Type Value Description
kit::PREVIEWABLE_STATES inline constexpr item_state_flags item_state_flags::HOVERED | item_state_flags::HELD | item_state_flags::FOCUSED The states a state_preview_scope can show: hovered, held and focused.

Macros

kit::CONJURE_ENUM_FLAGS

CONJURE_ENUM_FLAGS(mouse_button_flags)

Functions

Public

kit::available_size

[[nodiscard]] CONJURE_API math::vec2 available_size();

The width left on the current line and the height left below the layout cursor in the window's content region, in pixels (a picture that fills the rest of its panel).

kit::available_width

[[nodiscard]] CONJURE_API f32 available_width();

The width left on the current line of the window's layout, in pixels.

kit::field_id

[[nodiscard]] CONJURE_API u32 field_id(std::string_view key);

The id a text field of this key gets: its hidden label "##key", which TempInputText rehashes, so the field and its edit share one id. Tests address fields through it.

kit::is_disabled

[[nodiscard]] CONJURE_API bool is_disabled();

True while the widgets being submitted are disabled (inside an enabled disabled_scope or ImGui's own).

kit::layout_cursor

[[nodiscard]] CONJURE_API math::vec2 layout_cursor();

The current layout position in screen pixels (ImGui's cursor).

kit::require_kit

[[nodiscard]] CONJURE_API kit_context &require_kit();

The current kit context; asserts there is one.

kit::restore_layout_state

CONJURE_API void restore_layout_state(const layout_state &state);

Puts the current window's layout cursor back to a saved state (of the same window, in the same frame).

kit::save_layout_state

[[nodiscard]] CONJURE_API layout_state save_layout_state();

The current window's layout_state.

kit::set_clipboard_text

CONJURE_API void set_clipboard_text(std::string_view text);

Puts text (UTF-8) on the clipboard through ImGui's platform hook, which the engine's ImGui layer routes to the window's clipboard (the Inspector's Copy as JSON). Nothing outside an ImGui frame.

kit::shortcut

[[nodiscard]] CONJURE_API 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 (the engine's key vocabulary, platform/key.h) is pressed with exactly these modifiers held (CONTROL, SHIFT, ALT and SUPER; CONTROL is Cmd on macOS, as ImGui swaps them there; CAPS_LOCK and NUM_LOCK are no part of a shortcut and are ignored), when the route lets this submission have it (ImGui's Shortcut and its routing). Submit it every frame, pressed or not: a route is honoured from the frame after it is claimed. False for a key ImGui has none for (key::UNKNOWN, F25), and outside an ImGui frame.

kit::store_bool

CONJURE_API void store_bool(std::string_view key, bool value);

Stores a flag stored_bool reads back under key in the current id stack.

kit::store_f32

CONJURE_API void store_f32(std::string_view key, f32 value);

Stores a value stored_f32 reads back under key in the current id stack.

kit::stored_bool

[[nodiscard]] CONJURE_API bool stored_bool(std::string_view key, bool fallback = false);

A flag the current window keeps across frames under key (stored_f32's storage); fallback until one is stored.

kit::stored_f32

[[nodiscard]] CONJURE_API f32 stored_f32(std::string_view key, f32 fallback = 0.0f);

A value the current window keeps across frames under key in the current id stack (ImGui's per-window state storage, where sections and groups keep their open state): what a widget remembers of its own, such as the Euler angles a rotation field shows. fallback until a value is stored; an empty key stores nothing and reads the fallback. Inside an ImGui window.

kit::submit

template <typename PropsType> decltype(auto) submit(std::string_view key, const PropsType &props, const widget_options &options = {});

Measures a widget with the current kit context's metrics, takes a slot of that size at the layout position, opens its widget_scope and draws it: the free function of the widget pattern for any props type with a measure(props, text_metrics) and a draw(widget_scope &, props), found by argument-dependent lookup.

kit::to_string

[[nodiscard]] CONJURE_API std::string_view to_string(shortcut_route route) noexcept;

"focused", "global"; "" outside the enumeration.

kit::widget_id

[[nodiscard]] CONJURE_API u32 widget_id(std::string_view key);

The id a widget of this key gets in the current window and id stack (the id ImGui would give a label); 0 for an empty key, as a widget_scope of an empty key has no id.