Skip to content

Commit

Permalink
Clamp window position/size to graphics surface
Browse files Browse the repository at this point in the history
  • Loading branch information
simtr committed Apr 12, 2024
1 parent 351dc6e commit 3edb8c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/common/Vec2.h
Expand Up @@ -112,6 +112,14 @@ struct Vec2
);
}

Vec2<T> Min(Vec2<T> other) const
{
return Vec2<T>(
std::min(X, other.X),
std::min(Y, other.Y)
);
}

// Return a rectangle starting at origin, whose dimensions match this vector
template<typename S = T, typename = std::enable_if_t<std::is_integral_v<S>>>
constexpr inline Rect<T> OriginRect() const
Expand Down
2 changes: 2 additions & 0 deletions src/gui/interface/Engine.cpp
Expand Up @@ -83,6 +83,8 @@ void Engine::ShowWindow(Window * window)
{
window->Position.Y = (g->Size().Y - window->Size.Y) / 2;
}
window->Size = window->Size.Min(g->Size());
window->Position = window->Position.Clamp(RectBetween<int>({0, 0}, g->Size()));
/*if(window->Position.Y > 0)
{
windowTargetPosition = window->Position;
Expand Down

0 comments on commit 3edb8c4

Please sign in to comment.