From bc456c69124fa559f10eab273fbd96f48c5b0b74 Mon Sep 17 00:00:00 2001 From: Oliver 'kfsone' Smith Date: Wed, 24 Feb 2021 13:26:40 -0800 Subject: [PATCH] Added ConstrainRectangle helper --- raygui/raygui.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/raygui/raygui.go b/raygui/raygui.go index 4470a61..6224a8a 100644 --- a/raygui/raygui.go +++ b/raygui/raygui.go @@ -46,6 +46,17 @@ func GetInteractionState(rectangles ...rl.Rectangle) ControlState { } } +// Constrain rectangle will ensure that if width/height are below given minimums, they will +// be set to an ideal minimum. +func ConstrainRectangle(bounds *rl.Rectangle, minWidth, idealWidth, minHeight, idealHeight int32) { + if int32(bounds.Width) < minWidth { + bounds.Width = float32(idealWidth) + } + if int32(bounds.Height) < minHeight { + bounds.Height = float32(idealHeight) + } +} + // InsetRectangle returns the dimensions of a rectangle inset by a margin within an outer rectangle. func InsetRectangle(outer rl.RectangleInt32, inset int32) rl.RectangleInt32 { return rl.RectangleInt32{