MCPcopy Create free account
hub / github.com/RenderKit/embree / TempInputScalar

Method TempInputScalar

tutorials/common/imgui/imgui_widgets.cpp:3326–3360  ·  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

3324// This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility.
3325// However this may not be ideal for all uses, as some user code may break on out of bound values.
3326bool 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)
3327{
3328 char fmt_buf[32];
3329 char data_buf[32];
3330 format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf));
3331 DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format);
3332 ImStrTrimBlanks(data_buf);
3333
3334 ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | (ImGuiInputTextFlags)ImGuiInputTextFlags_NoMarkEdited;
3335 flags |= InputScalar_DefaultCharsFilter(data_type, format);
3336
3337 bool value_changed = false;
3338 if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags))
3339 {
3340 // Backup old value
3341 size_t data_type_size = DataTypeGetInfo(data_type)->Size;
3342 ImGuiDataTypeTempStorage data_backup;
3343 memcpy(&data_backup, p_data, data_type_size);
3344
3345 // Apply new value (or operations) then clamp
3346 DataTypeApplyFromText(data_buf, data_type, p_data, format);
3347 if (p_clamp_min || p_clamp_max)
3348 {
3349 if (p_clamp_min && p_clamp_max && DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0)
3350 ImSwap(p_clamp_min, p_clamp_max);
3351 DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max);
3352 }
3353
3354 // Only mark as edited if new value is different
3355 value_changed = memcmp(&data_backup, p_data, data_type_size) != 0;
3356 if (value_changed)
3357 MarkItemEdited(id);
3358 }
3359 return value_changed;
3360}
3361
3362// 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.
3363// 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