Skip to content

Commit 434b771

Browse files
committed
Internals: packing ImGuiDataVarInfo + misc renaming + value of ImGuiDataType_Pointer doesn't need to be Count+1
1 parent 1e18a6c commit 434b771

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

imgui.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,7 @@ void ImGui::PopStyleColor(int count)
33673367
}
33683368
}
33693369

3370-
static const ImGuiDataVarInfo GStyleVarInfo[] =
3370+
static const ImGuiDataVarInfo GStyleVarsInfo[] =
33713371
{
33723372
{ ImGuiDataType_Float, 1, (ImU32)offsetof(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha
33733373
{ ImGuiDataType_Float, 1, (ImU32)offsetof(ImGuiStyle, DisabledAlpha) }, // ImGuiStyleVar_DisabledAlpha
@@ -3407,15 +3407,15 @@ static const ImGuiDataVarInfo GStyleVarInfo[] =
34073407
const ImGuiDataVarInfo* ImGui::GetStyleVarInfo(ImGuiStyleVar idx)
34083408
{
34093409
IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_COUNT);
3410-
IM_STATIC_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT);
3411-
return &GStyleVarInfo[idx];
3410+
IM_STATIC_ASSERT(IM_ARRAYSIZE(GStyleVarsInfo) == ImGuiStyleVar_COUNT);
3411+
return &GStyleVarsInfo[idx];
34123412
}
34133413

34143414
void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
34153415
{
34163416
ImGuiContext& g = *GImGui;
34173417
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
3418-
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 1)
3418+
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 1)
34193419
{
34203420
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
34213421
return;
@@ -3429,7 +3429,7 @@ void ImGui::PushStyleVarX(ImGuiStyleVar idx, float val_x)
34293429
{
34303430
ImGuiContext& g = *GImGui;
34313431
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
3432-
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
3432+
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
34333433
{
34343434
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
34353435
return;
@@ -3443,7 +3443,7 @@ void ImGui::PushStyleVarY(ImGuiStyleVar idx, float val_y)
34433443
{
34443444
ImGuiContext& g = *GImGui;
34453445
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
3446-
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
3446+
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
34473447
{
34483448
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
34493449
return;
@@ -3457,7 +3457,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
34573457
{
34583458
ImGuiContext& g = *GImGui;
34593459
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
3460-
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
3460+
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
34613461
{
34623462
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
34633463
return;
@@ -3481,8 +3481,8 @@ void ImGui::PopStyleVar(int count)
34813481
ImGuiStyleMod& backup = g.StyleVarStack.back();
34823482
const ImGuiDataVarInfo* info = GetStyleVarInfo(backup.VarIdx);
34833483
void* data = info->GetVarPtr(&g.Style);
3484-
if (info->Type == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; }
3485-
else if (info->Type == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; }
3484+
if (info->DataType == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; }
3485+
else if (info->DataType == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; }
34863486
g.StyleVarStack.pop_back();
34873487
count--;
34883488
}

imgui_internal.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,9 @@ struct ImDrawDataBuilder
814814

815815
struct ImGuiDataVarInfo
816816
{
817-
ImGuiDataType Type;
818-
ImU32 Count; // 1+
819-
ImU32 Offset; // Offset in parent structure
817+
ImGuiDataType DataType : 8;
818+
ImU32 Count : 8; // 1+
819+
ImU32 Offset : 16; // Offset in parent structure
820820
void* GetVarPtr(void* parent) const { return (void*)((unsigned char*)parent + Offset); }
821821
};
822822

@@ -837,7 +837,7 @@ struct ImGuiDataTypeInfo
837837
// Extend ImGuiDataType_
838838
enum ImGuiDataTypePrivate_
839839
{
840-
ImGuiDataType_Pointer = ImGuiDataType_COUNT + 1,
840+
ImGuiDataType_Pointer = ImGuiDataType_COUNT,
841841
ImGuiDataType_ID,
842842
};
843843

0 commit comments

Comments
 (0)