MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TempInputScalar

Method TempInputScalar

KBotExt/imgui/imgui_widgets.cpp:3398–3437  ·  view source on GitHub ↗

Note that Drag/Slider functions are only forwarding the min/max values clamping values if the ImGuiSliderFlags_AlwaysClamp flag is set! This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility. However this may not be ideal for all uses, as some user code may break on out of bound values.

Source from the content-addressed store, hash-verified

3396// This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility.
3397// However this may not be ideal for all uses, as some user code may break on out of bound values.
3398bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min, const void* p_clamp_max)
3399{
3400 // FIXME: May need to clarify display behavior if format doesn't contain %.
3401 // "%d" -> "%d" / "There are %d items" -> "%d" / "items" -> "%d" (fallback). Also see #6405
3402 const ImGuiDataTypeInfo* type_info = DataTypeGetInfo(data_type);
3403 char fmt_buf[32];
3404 char data_buf[32];
3405 format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf));
3406 if (format[0] == 0)
3407 format = type_info->PrintFmt;
3408 DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format);
3409 ImStrTrimBlanks(data_buf);
3410
3411 ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited;
3412 flags |= InputScalar_DefaultCharsFilter(data_type, format);
3413
3414 bool value_changed = false;
3415 if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags))
3416 {
3417 // Backup old value
3418 size_t data_type_size = type_info->Size;
3419 ImGuiDataTypeTempStorage data_backup;
3420 memcpy(&data_backup, p_data, data_type_size);
3421
3422 // Apply new value (or operations) then clamp
3423 DataTypeApplyFromText(data_buf, data_type, p_data, format);
3424 if (p_clamp_min || p_clamp_max)
3425 {
3426 if (p_clamp_min && p_clamp_max && DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0)
3427 ImSwap(p_clamp_min, p_clamp_max);
3428 DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max);
3429 }
3430
3431 // Only mark as edited if new value is different
3432 value_changed = memcmp(&data_backup, p_data, data_type_size) != 0;
3433 if (value_changed)
3434 MarkItemEdited(id);
3435 }
3436 return value_changed;
3437}
3438
3439// Note: p_data, p_step, p_step_fast are _pointers_ to a memory address holding the data. For an Input widget, p_step and p_step_fast are optional.
3440// Read code of e.g. InputFloat(), InputInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.

Callers

nothing calls this directly

Calls 4

ImStrTrimBlanksFunction · 0.85
ImSwapFunction · 0.85

Tested by

no test coverage detected