-
Notifications
You must be signed in to change notification settings - Fork 7
Type Settings
Version: v0.2.0
Supported Types:
-
Primitives:
int,float,double,bool,char, all standard numeric types -
Enums: Any C++ enum (auto-reflected via
magic_enum) -
Strings:
std::string -
Containers:
vector,array,list,deque,map,set, and their variants -
Smart Pointers:
shared_ptr,unique_ptr,weak_ptr -
Utilities:
pair,tuple,optional,variant -
Custom Types: Any struct/class with
IMGUI_REFLECTmacro
Supported: int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float, double, int, long, short, char, and typedefs.
Choose how users interact with numbers:
| Method | Best For | Visual Style |
|---|---|---|
as_input() |
Precise numeric entry | Text field with arrows |
as_slider() |
Visual range selection | Draggable slider |
as_drag() |
Quick adjustments by mouse | Drag-to-modify field |
Default: Input field
.min(0) // Minimum value
.max(100) // Maximum value
.clamp(true) // Auto-clamp to range
.step(1) // Increment/decrement step
.step_fast(10) // Fast step (Ctrl+click)
.speed(0.1f) // Drag sensitivity// Common formats
.format("%.2f") // Custom printf format
.prefix("$") // Add prefix: "$100"
.suffix(" kg") // Add suffix: "100 kg"
// Shortcuts
.as_decimal() // Integer: 123
.as_hex() // Hex: 0x7b
.as_hex(true) // Uppercase: 0X7B
.as_float(2) // Float: 123.45
.as_percentage(1) // Percent: 12.3%
.as_scientific(2) // Scientific: 1.23e+02
// Alignment
.width(8) // Field width
.zero_pad(5) // Zero padding: 00123Slider-specific:
.logarithmic() // Logarithmic scale
.no_round_to_format() // Preserve raw values
.no_input() // Slider only, no text input
.wrap_around() // Loop at boundaries
.clamp_on_input() // Clamp during text entry
.always_clamp() // Always enforce limitsInput-specific:
.chars_decimal() // Only allow 0-9
.chars_hexadecimal() // Allow hex characters
.chars_scientific() // Allow scientific notation
.read_only() // Display only
.auto_select_all() // Select on focus
.enter_returns_true() // Submit on EnterSupported: bool
| Method | Visual Style | Best For |
|---|---|---|
as_checkbox() |
☑ Checkbox | General use (default) |
as_radio() |
◉ True / ○ False buttons | Clear binary choice |
as_dropdown() |
Dropdown: "True" / "False" | Compact layouts |
as_button() |
Toggle button: ON / OFF | Action-style toggles |
.true_text("Enabled") // Custom text for true
.false_text("Disabled") // Custom text for falseSupported: Any C++ enum (automatically reflected via magic_enum)
| Method | Visual Style | Best For |
|---|---|---|
as_dropdown() |
Dropdown list (default) | Many options |
as_radio() |
Radio buttons | 2-5 options, always visible |
as_slider() |
Slider with labels | Ordered progression |
as_drag() |
Drag to cycle values | Quick cycling |
.speed(0.01f) // Drag speed (for as_drag)Supported: std::string
| Method | Description | Use Case |
|---|---|---|
as_singleline() |
Single-line text field (default) | Names, short text |
as_multiline() |
Multi-line text area | Descriptions, paragraphs |
.line_count(5) // Fixed height (5 lines)
.auto_resize(true) // Auto-grow with contentNote: line_count(-1) uses ImGui defaults. line_count(0) enables auto-resize.
Supported: vector, array, list, forward_list, deque, set, multiset, unordered_set, unordered_multiset
.as_dropdown(false) // Show/hide in collapsible treeConfigure what users can do with container elements:
| Setting | Description | Default | vector |
array |
list |
forward_list |
deque |
set |
multiset |
|---|---|---|---|---|---|---|---|---|---|
reorderable(bool) |
Drag-drop reordering, move up/down | true |
✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ |
insertable(bool) |
Add new items | true |
✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
removable(bool) |
Delete items | true |
✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
pop_up_on_insert(bool) |
Show popup when adding items | true |
✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
Why some features are unavailable:
-
array: Fixed size at compile time (no insert/remove) -
forward_list: Forward-only iteration (no reordering) -
set/multiset: Elements maintain sorted order (no manual reordering)
Right-click on elements to access context menu:
- Reorder: Move up/down, to top/bottom, drag-drop
- Insert: Above/below current element
- Duplicate: Copy existing element
- Remove: Delete element
- Clear All: Empty container
Supported: map, multimap, unordered_map, unordered_multimap
.as_dropdown(false) // Show/hide in collapsible tree| Setting | Description | Default |
|---|---|---|
insertable(bool) |
Add new key-value pairs | true |
removable(bool) |
Delete pairs | true |
pop_up_on_insert(bool) |
Show popup when adding pairs | true |
Note: Maps cannot be reordered as they maintain their own key ordering.
- Add (+): Opens popup to enter key and value
- Remove (-): Deletes last element
- Context Menu: Right-click element to remove or clear all
Supported: std::shared_ptr<T>, std::unique_ptr<T>, std::weak_ptr<T>
Smart pointers automatically dereference and display their contained value.
| Pointer State | Display |
|---|---|
| Valid value | Shows the dereferenced object's UI |
nullptr |
Shows <nullptr> (disabled, not editable) |
| Expired | Shows <expired> (weak_ptr only, disabled) |
Supported: std::optional<T>
Displays a checkbox to toggle between having a value (engaged) and being empty (nullopt).
.resettable(bool) // Show reset button (default: false)| State | Display |
|---|---|
| Has value | ☑ Checkbox + value editor |
| Empty | ☐ Checkbox + <nullopt> (grayed out) |
When toggled on, the optional is initialized with T{} (default-constructed value).
Supported: std::variant<Types...>
Displays a dropdown to select the active type, followed by an editor for that type's value.
.as_dropdown(bool) // Hide value editor in collapsible tree (default: false)| State | Display |
|---|---|
| Valid | Type selector + value editor |
| Valueless | Type selector + <valueless> (grayed out) |
Type switching:
- Dropdown shows C++ type names (e.g.,
int,float,std::string) - Only default-constructible types can be selected
- Switching types reconstructs the variant with
T{}
Supported: std::pair<T1, T2>, std::tuple<Types...>
| Method | Description | Default |
|---|---|---|
as_line() |
Elements in a single horizontal row | true |
as_grid() |
Elements in a grid layout | false |
as_dropdown() |
Elements in collapsible tree | false |
.columns(int) // Number of columns (default: 3)Any C++ type with IMGUI_REFLECT macro
Use the IMGUI_REFLECT macro to specify which members to display:
struct GameSettings {
int volume = 50;
float sensitivity = 1.0f;
bool fullscreen = false;
std::string playerName = "Player1";
};
// Register members for reflection
IMGUI_REFLECT(GameSettings, volume, sensitivity, fullscreen, playerName)GameSettings settings;
ImReflect::Input("Settings", settings);
// Automatically creates UI for all reflected membersAll widgets provide response information for tracking user interactions.
static int my_int = 0;
ImResponse response = ImReflect::Input("my_int", my_int);
const auto& int_response = response.get<int>();
ImGui::Text("is_changed: %s", int_response.is_changed() ? "true" : "false");
ImGui::Text("is_hovered: %s", int_response.is_hovered() ? "true" : "false");
ImGui::Text("is_active: %s", int_response.is_active() ? "true" : "false");
ImGui::Text("is_focused: %s", int_response.is_focused() ? "true" : "false");
ImGui::Text("is_clicked left: %s", int_response.is_clicked(0) ? "true" : "false");
ImGui::Text("is_clicked right: %s", int_response.is_clicked(1) ? "true" : "false");
ImGui::Text("is_clicked middle: %s", int_response.is_clicked(2) ? "true" : "false");For containers (vector, list, map, etc.), additional methods track structural changes:
auto& container_response = response.get<std::vector>();
if (container_response.has_inserted()) {
size_t index = container_response.get_inserted_index();
// Item was inserted at index
}
if (container_response.has_erased()) {
size_t index = container_response.get_erased_index();
// Item was removed from index
}
if (container_response.has_moved()) {
auto info = container_response.get_moved_info();
// Item moved from info.from to info.to
}