mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +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;
|
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_] =
|
||||||
@ -4852,8 +4852,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;
|
||||||
}
|
}
|
||||||
@ -4865,8 +4866,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;
|
||||||
}
|
}
|
||||||
@ -4880,9 +4882,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--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user