From 0e83add8beed834e8bab3512f6638b8e3ccfdc21 Mon Sep 17 00:00:00 2001 From: Oliver 'kfsone' Smith Date: Wed, 24 Feb 2021 12:19:31 -0800 Subject: [PATCH] Added bordered-rectangle helper functions (without adding users) --- raygui/raygui.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/raygui/raygui.go b/raygui/raygui.go index 9ea0b17..4470a61 100644 --- a/raygui/raygui.go +++ b/raygui/raygui.go @@ -45,3 +45,24 @@ func GetInteractionState(rectangles ...rl.Rectangle) ControlState { return Focused } } + +// 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{ + X: outer.X + inset, Y: outer.Y + inset, + Width: outer.Width - 2*inset, Height: outer.Height - 2*inset, + } +} + +// DrawInsetRectangle is a helper to draw a box inset by a margin of an outer container. +func DrawInsetRectangle(outer rl.RectangleInt32, inset int32, color rl.Color) { + inside := InsetRectangle(outer, inset) + rl.DrawRectangle(inside.X, inside.Y, inside.Width, inside.Height, color) +} + +// DrawBorderedRectangle is a helper to draw a box with a border around it. +func DrawBorderedRectangle(bounds rl.RectangleInt32, borderWidth int32, borderColor, insideColor rl.Color) { + inside := InsetRectangle(bounds, borderWidth) + rl.DrawRectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height, borderColor) + rl.DrawRectangle(inside.X, inside.Y, inside.Width, inside.Height, insideColor) +}