mirror of
https://github.com/ocornut/imgui.git
synced 2025-02-25 14:34:40 +01:00
Internals: packing ImGuiDataVarInfo + misc renaming + value of ImGuiDataType_Pointer doesn't need to be Count+1
This commit is contained in:
parent
1e18a6cf60
commit
434b7710f3
18
imgui.cpp
18
imgui.cpp
@ -3367,7 +3367,7 @@ void ImGui::PopStyleColor(int count)
|
||||
}
|
||||
}
|
||||
|
||||
static const ImGuiDataVarInfo GStyleVarInfo[] =
|
||||
static const ImGuiDataVarInfo GStyleVarsInfo[] =
|
||||
{
|
||||
{ ImGuiDataType_Float, 1, (ImU32)offsetof(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha
|
||||
{ ImGuiDataType_Float, 1, (ImU32)offsetof(ImGuiStyle, DisabledAlpha) }, // ImGuiStyleVar_DisabledAlpha
|
||||
@ -3407,15 +3407,15 @@ static const ImGuiDataVarInfo GStyleVarInfo[] =
|
||||
const ImGuiDataVarInfo* ImGui::GetStyleVarInfo(ImGuiStyleVar idx)
|
||||
{
|
||||
IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_COUNT);
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT);
|
||||
return &GStyleVarInfo[idx];
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(GStyleVarsInfo) == ImGuiStyleVar_COUNT);
|
||||
return &GStyleVarsInfo[idx];
|
||||
}
|
||||
|
||||
void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
|
||||
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 1)
|
||||
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 1)
|
||||
{
|
||||
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
|
||||
return;
|
||||
@ -3429,7 +3429,7 @@ void ImGui::PushStyleVarX(ImGuiStyleVar idx, float val_x)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
|
||||
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
|
||||
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
|
||||
{
|
||||
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
|
||||
return;
|
||||
@ -3443,7 +3443,7 @@ void ImGui::PushStyleVarY(ImGuiStyleVar idx, float val_y)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
|
||||
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
|
||||
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
|
||||
{
|
||||
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
|
||||
return;
|
||||
@ -3457,7 +3457,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiDataVarInfo* var_info = GetStyleVarInfo(idx);
|
||||
if (var_info->Type != ImGuiDataType_Float || var_info->Count != 2)
|
||||
if (var_info->DataType != ImGuiDataType_Float || var_info->Count != 2)
|
||||
{
|
||||
IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
|
||||
return;
|
||||
@ -3481,8 +3481,8 @@ void ImGui::PopStyleVar(int count)
|
||||
ImGuiStyleMod& backup = g.StyleVarStack.back();
|
||||
const ImGuiDataVarInfo* info = GetStyleVarInfo(backup.VarIdx);
|
||||
void* data = info->GetVarPtr(&g.Style);
|
||||
if (info->Type == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; }
|
||||
else if (info->Type == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; }
|
||||
if (info->DataType == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; }
|
||||
else if (info->DataType == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; }
|
||||
g.StyleVarStack.pop_back();
|
||||
count--;
|
||||
}
|
||||
|
@ -814,9 +814,9 @@ struct ImDrawDataBuilder
|
||||
|
||||
struct ImGuiDataVarInfo
|
||||
{
|
||||
ImGuiDataType Type;
|
||||
ImU32 Count; // 1+
|
||||
ImU32 Offset; // Offset in parent structure
|
||||
ImGuiDataType DataType : 8;
|
||||
ImU32 Count : 8; // 1+
|
||||
ImU32 Offset : 16; // Offset in parent structure
|
||||
void* GetVarPtr(void* parent) const { return (void*)((unsigned char*)parent + Offset); }
|
||||
};
|
||||
|
||||
@ -837,7 +837,7 @@ struct ImGuiDataTypeInfo
|
||||
// Extend ImGuiDataType_
|
||||
enum ImGuiDataTypePrivate_
|
||||
{
|
||||
ImGuiDataType_Pointer = ImGuiDataType_COUNT + 1,
|
||||
ImGuiDataType_Pointer = ImGuiDataType_COUNT,
|
||||
ImGuiDataType_ID,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user