Implemented MixedValue item flag for DragScalars

This commit is contained in:
Michael Martz 2022-09-12 10:05:26 -07:00
parent 513c1ba996
commit 5f1a307cdc
1 changed files with 8 additions and 4 deletions

View File

@ -2360,8 +2360,10 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
if (!ItemAdd(total_bb, id, &frame_bb, temp_input_allowed ? ImGuiItemFlags_Inputable : 0))
return false;
// Default format string when passing NULL
if (format == NULL)
bool mixed_value = (g.LastItemData.InFlags & ImGuiItemFlags_MixedValue) != 0;
if (mixed_value) // Dash when value is mixed
format = "-";
else if (format == NULL) // Default format string when passing NULL
format = DataTypeGetInfo(data_type)->PrintFmt;
else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
format = PatchFormatStringFloatToInt(format);
@ -3378,8 +3380,10 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG
DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max);
}
// Only mark as edited if new value is different
value_changed = memcmp(&data_backup, p_data, data_type_size) != 0;
// Mark as edited if value is mixed or new value is different
ImGuiContext& g = *GImGui;
bool mixed_value = (g.LastItemData.InFlags & ImGuiItemFlags_MixedValue) != 0;
value_changed = mixed_value || memcmp(&data_backup, p_data, data_type_size) != 0;
if (value_changed)
MarkItemEdited(id);
}