mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
PushStyleVar/PopStyleVar: internal tweaks
This commit is contained in:
parent
7c9e38f60a
commit
9693fd5351
18
imgui.cpp
18
imgui.cpp
@ -4822,7 +4822,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_] =
|
||||
@ -4852,8 +4852,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;
|
||||
}
|
||||
@ -4865,8 +4866,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;
|
||||
}
|
||||
@ -4880,9 +4882,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--;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user