15 static const ImGuiTableFlags kConfigTableFlags
16 = ImGuiTableFlags_BordersV
17 | ImGuiTableFlags_BordersOuterH
18 | ImGuiTableFlags_Resizable
19 | ImGuiTableFlags_RowBg
20 | ImGuiTableFlags_NoHostExtendX
21 | ImGuiTableFlags_NoBordersInBody;
23 static const ImGuiTreeNodeFlags kConfigGroupNodeFlags
24 = ImGuiTreeNodeFlags_SpanAllColumns
25 | ImGuiTreeNodeFlags_AllowOverlap;
27 static const ImGuiTreeNodeFlags kConfigValueNodeFlags
28 = kConfigGroupNodeFlags
29 | ImGuiTreeNodeFlags_Leaf
30 | ImGuiTreeNodeFlags_Bullet
31 | ImGuiTreeNodeFlags_NoTreePushOnOpen;
41 return ed::strfmt<64>(
"##%s",
get_name(field));
46 const char *brief = info->
brief !=
nullptr ? info->
brief :
"no brief";
47 ImGui::Text(
"brief: %s", brief);
53 ImGui::TextDisabled(
"%s", info->
name);
54 if (ImGui::BeginItemTooltip())
56 ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.f);
59 ImGui::TextUnformatted(
"args: ");
62 for (
size_t i = 0; i < args.
count; i++)
65 ImGui::Text(
"%s", args.
args[i]);
68 ImGui::PopTextWrapPos();
77 ImGui::TextDisabled(
"%s", info->
name);
78 if (ImGui::BeginItemTooltip())
80 ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.f);
89 ImGui::SeparatorText(
"Children");
90 ImGui::Text(
"%zu groups, %zu fields", group_count, field_count);
92 ImGui::PopTextWrapPos();
100 if (ImGui::Checkbox(
get_label(field), &value))
110 if (ImGui::DragInt(
get_label(field), &value, 1.f, cfg->min, cfg->max))
120 char buffer[256] = { 0 };
121 strncpy_s(buffer, value,
std::size(buffer));
133 size_t current = SIZE_MAX;
134 for (
size_t i = 0; i < cfg->
count; i++)
136 if (cfg->options[i].value == value)
143 CTASSERTF(current != SIZE_MAX,
"invalid enum value %zu for field %s", value,
get_name(field));
145 if (ImGui::BeginCombo(
get_label(field), cfg->options[current].text))
147 for (
size_t i = 0; i < cfg->
count; i++)
149 bool is_selected = (current == i);
150 if (ImGui::Selectable(cfg->options[i].text, is_selected))
158 ImGui::SetItemDefaultFocus();
168 const char *edit_flags_popup =
"Edit Flags";
173 if (ImGui::Button(
"Edit"))
175 ImGui::OpenPopup(edit_flags_popup);
178 if (ImGui::BeginPopup(edit_flags_popup))
180 bool changed =
false;
181 for (
size_t i = 0; i < cfg->
count; i++)
184 ImU64 flag = choice->
value;
185 if (ImGui::CheckboxFlags(choice->
text, &value, flag))
226 ImGui::TextDisabled(
"Unknown type");
235 if (cfg->min == INT_MIN && cfg->max == INT_MAX)
237 ImGui::TextDisabled(
"no constraints");
240 else if (cfg->min == INT_MIN)
242 ImGui::Text(
"min (%d)", cfg->max);
245 else if (cfg->max == INT_MAX)
247 ImGui::Text(
"max (%d)", cfg->min);
252 ImGui::Text(
"range (%d, %d)", cfg->min, cfg->max);
272 ImGui::TextDisabled(
"Unknown type");
282 ImGui::TableNextColumn();
283 ImGui::AlignTextToFramePadding();
284 ImGui::TreeNodeEx(info->
name, kConfigValueNodeFlags);
286 ImGui::TableNextColumn();
289 ImGui::TableNextColumn();
292 ImGui::TableNextColumn();
295 ImGui::TableNextColumn();
305 for (
size_t i = 0; i < child_count; ++i)
307 ImGui::TableNextRow();
317 for (
size_t i = 0; i < field_count; ++i)
319 ImGui::TableNextRow();
329 ImGui::TableNextColumn();
332 bool is_group_open = ImGui::TreeNodeEx(info->
name, kConfigGroupNodeFlags);
334 ImGui::TableNextColumn();
335 ImGui::TextDisabled(
"--");
337 ImGui::TableNextColumn();
338 ImGui::TableNextColumn();
339 ImGui::TableNextColumn();
353 if (ImGui::BeginTable(
"Config", 5, kConfigTableFlags))
355 ImGui::TableSetupColumn(
"Name");
356 ImGui::TableSetupColumn(
"Type");
357 ImGui::TableSetupColumn(
"Value");
358 ImGui::TableSetupColumn(
"Constraints");
359 ImGui::TableSetupColumn(
"Info");
361 ImGui::TableHeadersRow();
void draw_group_info(const cfg_group_t *group)
void draw_config_group(cfg_group_t *group)
void draw_config_group_children(cfg_group_t *group)
void draw_enum(cfg_field_t *field)
void draw_int_constraints(const cfg_field_t *field)
void draw_config_entry(cfg_field_t *field)
ed::SmallString< 64 > get_label(const cfg_field_t *field)
void draw_info_preamble(const cfg_info_t *info)
void draw_flags(cfg_field_t *field)
void draw_constraints(const cfg_field_t *field)
const char * get_name(const cfg_field_t *field)
void draw_value(cfg_field_t *field)
void draw_int(cfg_field_t *field)
void draw_config_group_fields(cfg_group_t *group)
void draw_field_info(const cfg_field_t *field)
void draw_bool(cfg_field_t *field)
void draw_string(cfg_field_t *field)
CT_PUREFN CT_CONFIG_API const char * cfg_string_value(const cfg_field_t *field)
get the current string value of a configuration field
CT_PUREFN CT_CONFIG_API size_t cfg_flags_value(const cfg_field_t *field)
get the current flags value of a configuration field
CT_PUREFN CT_CONFIG_API bool cfg_bool_value(const cfg_field_t *field)
get the current boolean value of a configuration field
CT_PUREFN CT_CONFIG_API int cfg_int_value(const cfg_field_t *field)
get the current integer value of a configuration field
CT_PUREFN CT_CONFIG_API size_t cfg_enum_value(const cfg_field_t *field)
get the current enum value of a configuration field
CT_PUREFN CT_CONFIG_API const cfg_info_t * cfg_group_info(const cfg_group_t *config)
get the information about a configuration group
CT_CONSTFN CT_CONFIG_API const char * cfg_type_string(cfg_type_t type)
get the name of a configuration type
CT_PUREFN CT_CONFIG_API typevec_t * cfg_get_groups(const cfg_group_t *config)
get all subgroups in a configuration group
CT_PUREFN CT_CONFIG_API const cfg_int_t * cfg_int_info(const cfg_field_t *field)
get the information about an integer field
CT_PUREFN CT_CONFIG_API const cfg_enum_t * cfg_enum_info(const cfg_field_t *field)
get the information about a choice field
CT_PUREFN CT_CONFIG_API const cfg_enum_t * cfg_flags_info(const cfg_field_t *field)
get the information about a flags field
CT_PUREFN CT_CONFIG_API vector_t * cfg_get_fields(const cfg_group_t *config)
get all fields in a configuration group
CT_PUREFN CT_CONFIG_API cfg_type_t cfg_get_type(const cfg_field_t *field)
get the type of a configuration field
CT_PUREFN CT_CONFIG_API const cfg_info_t * cfg_get_info(const cfg_field_t *field)
get the information about a configuration field
CT_NODISCARD CT_CONFIG_API bool cfg_set_int(cfg_field_t *field, int value)
set the current value of an int field
CT_CONFIG_API void cfg_set_string(cfg_field_t *field, char *value)
set the current value of a string field
CT_CONFIG_API bool cfg_set_enum(cfg_field_t *field, const char *choice)
set the current value of an enum field set the value via a string name
CT_CONFIG_API void cfg_set_bool(cfg_field_t *field, bool value)
set the current value of a bool field
CT_CONFIG_API void cfg_set_flag_value(cfg_field_t *field, size_t value)
set the current value of a flags field set the value via an integer value
cfg_type_t
the type of a configuration field
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
CT_NODISCARD CT_PUREFN CT_STD_API size_t typevec_len(const typevec_t *vec)
get the length of a vector
CT_NODISCARD CT_PUREFN CT_STD_API void * typevec_offset(const typevec_t *vec, size_t index)
get a pointer to the value at the given index
CT_NODISCARD CT_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from a vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t vector_len(const vector_t *vector)
get the length of a vector
void draw_config_panel(cfg_group_t *config)
a choice in a set of options
STA_FIELD_STRING const char * text
the name of this choice
size_t value
the value of this choice
a choice from a set of options
size_t count
the number of choices in this set
information about a configuration field
STA_FIELD_STRING const char * brief
a brief description of this field
cfg_arg_array_t args
the spellings to use for this field
STA_FIELD_STRING const char * name
the name of this field
A vector with a fixed type size.
a generic vector of pointers