1
0
mirror of https://github.com/Drezil/imgui.git synced 2024-12-19 06:26:35 +00:00

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;
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_] =
@ -4765,8 +4765,9 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx);
if (var_info->Type == ImGuiDataType_Float)
{
float* pvar = (float*)var_info->GetVarPtr();
GImGui->StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
ImGuiContext& g = *GImGui;
float* pvar = (float*)var_info->GetVarPtr(&g.Style);
g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
*pvar = val;
return;
}
@ -4778,8 +4779,9 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx);
if (var_info->Type == ImGuiDataType_Float2)
{
ImVec2* pvar = (ImVec2*)var_info->GetVarPtr();
GImGui->StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
ImGuiContext& g = *GImGui;
ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style);
g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar));
*pvar = val;
return;
}
@ -4793,9 +4795,9 @@ void ImGui::PopStyleVar(int count)
{
ImGuiStyleMod& backup = g.StyleModifiers.back();
const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx);
if (info->Type == ImGuiDataType_Float) (*(float*)info->GetVarPtr()) = backup.BackupFloat[0];
else if (info->Type == ImGuiDataType_Float2) (*(ImVec2*)info->GetVarPtr()) = ImVec2(backup.BackupFloat[0], backup.BackupFloat[1]);
else if (info->Type == ImGuiDataType_Int) (*(int*)info->GetVarPtr()) = backup.BackupInt[0];
if (info->Type == ImGuiDataType_Float) (*(float*)info->GetVarPtr(&g.Style)) = backup.BackupFloat[0];
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(&g.Style)) = backup.BackupInt[0];
g.StyleModifiers.pop_back();
count--;
}