Internals: Using ImFloor().when appropriate.

This commit is contained in:
omar 2018-01-10 16:11:29 +01:00
parent 0cabd81071
commit f610e25682

View File

@ -4163,14 +4163,13 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
{ {
// Retrieve settings from .ini file // Retrieve settings from .ini file
// Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
window->PosFloat = ImVec2(60, 60); window->Pos = window->PosFloat = ImVec2(60, 60);
window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID))
{ {
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
window->PosFloat = settings->Pos; window->PosFloat = settings->Pos;
window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); window->Pos = ImFloor(window->PosFloat);
window->Collapsed = settings->Collapsed; window->Collapsed = settings->Collapsed;
if (ImLengthSqr(settings->Size) > 0.00001f) if (ImLengthSqr(settings->Size) > 0.00001f)
size = settings->Size; size = settings->Size;
@ -4494,7 +4493,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Popup first latch mouse position, will position itself when it appears next frame // Popup first latch mouse position, will position itself when it appears next frame
window->AutoPosLastDirection = ImGuiDir_None; window->AutoPosLastDirection = ImGuiDir_None;
if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api) if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api)
window->PosFloat = g.CurrentPopupStack.back().OpenPopupPos; window->Pos = window->PosFloat = g.CurrentPopupStack.back().OpenPopupPos;
} }
// Collapse window by double-clicking on title bar // Collapse window by double-clicking on title bar
@ -4648,7 +4647,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->PosFloat = ImMin(window->PosFloat, g.IO.DisplaySize - padding); window->PosFloat = ImMin(window->PosFloat, g.IO.DisplaySize - padding);
} }
} }
window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); window->Pos = ImFloor(window->PosFloat);
// Default item width. Make it proportional to window size if window manually resizes // Default item width. Make it proportional to window size if window manually resizes
if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize)) if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize))
@ -4765,7 +4764,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
} }
if (pos_target.x != FLT_MAX) if (pos_target.x != FLT_MAX)
{ {
window->Pos = window->PosFloat = ImVec2((float)(int)pos_target.x, (float)(int)pos_target.y); window->Pos = window->PosFloat = ImFloor(pos_target);
MarkIniSettingsDirty(window); MarkIniSettingsDirty(window);
} }
@ -5593,7 +5592,7 @@ static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond)
// Set // Set
const ImVec2 old_pos = window->Pos; const ImVec2 old_pos = window->Pos;
window->PosFloat = pos; window->PosFloat = pos;
window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); window->Pos = ImFloor(pos);
window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected. window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected.
} }