Fix some std::clamp() calls: max value cannot be less than min value

This commit is contained in:
David Capello 2023-07-31 10:31:08 -03:00
parent ab2d7f79a3
commit 2e1d50bf33
2 changed files with 4 additions and 4 deletions

View File

@ -2567,8 +2567,8 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom,
// extra space for the zoom)
gfx::Rect visibleBounds = editorToScreen(
getViewportBounds().createIntersection(gfx::Rect(gfx::Point(0, 0), canvasSize())));
screenPos.x = std::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1);
screenPos.y = std::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1);
screenPos.x = std::clamp(screenPos.x, visibleBounds.x, std::max(visibleBounds.x, visibleBounds.x2()-1));
screenPos.y = std::clamp(screenPos.y, visibleBounds.y, std::max(visibleBounds.y, visibleBounds.y2()-1));
spritePos = screenToEditor(screenPos);

View File

@ -147,8 +147,8 @@ void fit_bounds(const Display* parentDisplay,
if (fitLogic)
fitLogic(displayBounds, frame, [](Widget* widget){ return widget->bounds(); });
frame.x = std::clamp(frame.x, 0, displayBounds.w - frame.w);
frame.y = std::clamp(frame.y, 0, displayBounds.h - frame.h);
frame.x = std::clamp(frame.x, 0, std::max(0, displayBounds.w - frame.w));
frame.y = std::clamp(frame.y, 0, std::max(0, displayBounds.h - frame.h));
window->setBounds(frame);
}