Clean up number rounding. Now it is more obvious what code is doing. (#2862)

Add IM_ROUND() macro
Replace IM_FLOOR(n + 0.5f) and ImFloor(n + 0.5f) with IM_ROUND(n)
This commit is contained in:
Rokas Kupstys
2019-10-29 17:04:13 +01:00
committed by omar
parent 0b2d35f63f
commit c863c1f6a1
5 changed files with 24 additions and 23 deletions

View File

@ -4747,8 +4747,8 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size
g.NextWindowData.SizeCallback(&data);
new_size = data.DesiredSize;
}
new_size.x = ImFloor(new_size.x);
new_size.y = ImFloor(new_size.y);
new_size.x = IM_FLOOR(new_size.x);
new_size.y = IM_FLOOR(new_size.y);
}
// Minimum size
@ -6453,7 +6453,7 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con
if (size.x > 0.0f)
{
window->AutoFitFramesX = 0;
window->SizeFull.x = ImFloor(size.x);
window->SizeFull.x = IM_FLOOR(size.x);
}
else
{
@ -6463,7 +6463,7 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con
if (size.y > 0.0f)
{
window->AutoFitFramesY = 0;
window->SizeFull.y = ImFloor(size.y);
window->SizeFull.y = IM_FLOOR(size.y);
}
else
{
@ -8267,7 +8267,7 @@ static void ImGui::NavUpdate()
{
// *Fallback* manual-scroll with Nav directional keys when window has no navigable item
ImGuiWindow* window = g.NavWindow;
const float scroll_speed = ImFloor(window->CalcFontSize() * 100 * g.IO.DeltaTime + 0.5f); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * g.IO.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest)
{
if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)