From b4bb2cc1de2004153a1357e2e6678df7377b42e3 Mon Sep 17 00:00:00 2001 From: Physcik Date: Sun, 1 Feb 2026 16:29:13 +0500 Subject: UI button --- engine/UI/Label.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'engine/UI/Label.go') diff --git a/engine/UI/Label.go b/engine/UI/Label.go index a1fdf00..f412eff 100644 --- a/engine/UI/Label.go +++ b/engine/UI/Label.go @@ -3,6 +3,7 @@ package ui import rl "github.com/gen2brain/raylib-go/raylib" var defaultLabelPadding float32 = 5 +var defaultLabelRoundness float32 = 0.2 // If the text formation formula is applied without it the text is // overlowing on the right due to rounding errors @@ -12,6 +13,7 @@ var defaultLabelStyle = &Style{ BacgroundColor: &rl.LightGray, FontColor: &rl.DarkGray, Padding: &defaultLabelPadding, + Roundness: &defaultLabelRoundness , } type Label struct { @@ -28,12 +30,12 @@ func (base *Label) Init(*Menu) { func (base *Label) Destroy() { } -func (base *Label) Update() { -} - func (base *Label) Draw(position *rl.Rectangle) { // rl.TraceLog(rl.LogInfo, "Drawn at %v/%v/%v/%v", position.X, position.Y, position.Width, position.Height) - rl.DrawRectangleRec(*position, *base.Style.BacgroundColor) + rl.DrawRectangleRounded(*position, + *base.Style.Roundness, + 0, // Assume the segments param is always 0 - it doesn't really matter without a border + *base.Style.BacgroundColor) rl.DrawText(base.Text, int32(position.X+*base.Style.Padding), int32(position.Y+*base.Style.Padding), @@ -45,6 +47,7 @@ func (base *Label) GetOccupationWeight() float32 { return base.WidthWeight } +// Returns the size of the text that will not overflow in the side func (base *Label) getTextHeight(position *rl.Rectangle) int32 { var width = position.Width - 2 * *base.Style.Padding var outp = position.Height - 2 * *base.Style.Padding -- cgit v1.3