PushStyleVar/PopStyleVar: internal tweaks

This commit is contained in:
omar 2017-08-15 19:19:00 +08:00
parent 18f217e631
commit 1e162dfc74

View File

@ -4735,7 +4735,7 @@ struct ImGuiStyleVarInfo
{ {
ImGuiDataType Type; ImGuiDataType Type;
ImU32 Offset; ImU32 Offset;
void* GetVarPtr() const { return (void*)((unsigned char*)&GImGui->Style + Offset); } void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); }
}; };
static const ImGuiStyleVarInfo GStyleVarInfo[ImGuiStyleVar_Count_] = static const ImGuiStyleVarInfo GStyleVarInfo[ImGuiStyleVar_Count_] =
@ -4765,8 +4765,9 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx);
if (var_info->Type == ImGuiDataType_Float) if (var_info->Type == ImGuiDataType_Float)
{ {
float* pvar = (float*)var_info->GetVarPtr(); ImGuiContext& g = *GImGui;
GImGui->StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); float* pvar = (float*)var_info->GetVarPtr(&g.Style);
g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
*pvar = val; *pvar = val;
return; return;
} }
@ -4778,8 +4779,9 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx);
if (var_info->Type == ImGuiDataType_Float2) if (var_info->Type == ImGuiDataType_Float2)
{ {
ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(); ImGuiContext& g = *GImGui;
GImGui->StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style);
g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
*pvar = val; *pvar = val;
return; return;
} }
@ -4793,9 +4795,9 @@ void ImGui::PopStyleVar(int count)
{ {
ImGuiStyleMod& backup = g.StyleModifiers.back(); ImGuiStyleMod& backup = g.StyleModifiers.back();
const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx); const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx);
if (info->Type == ImGuiDataType_Float) (*(float*)info->GetVarPtr()) = backup.BackupFloat[0]; if (info->Type == ImGuiDataType_Float) (*(float*)info->GetVarPtr(&g.Style)) = backup.BackupFloat[0];
else if (info->Type == ImGuiDataType_Float2) (*(ImVec2*)info->GetVarPtr()) = ImVec2(backup.BackupFloat[0], backup.BackupFloat[1]); else if (info->Type == ImGuiDataType_Float2) (*(ImVec2*)info->GetVarPtr(&g.Style)) = ImVec2(backup.BackupFloat[0], backup.BackupFloat[1]);
else if (info->Type == ImGuiDataType_Int) (*(int*)info->GetVarPtr()) = backup.BackupInt[0]; else if (info->Type == ImGuiDataType_Int) (*(int*)info->GetVarPtr(&g.Style)) = backup.BackupInt[0];
g.StyleModifiers.pop_back(); g.StyleModifiers.pop_back();
count--; count--;
} }