From 3e3e1f480f87192cf1042bec0ee0d4bb7c356e62 Mon Sep 17 00:00:00 2001 From: physcik Date: Mon, 23 Mar 2026 18:43:07 +0500 Subject: Recursive UI elements support --- engine/UI/Label.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'engine/UI/Label.go') diff --git a/engine/UI/Label.go b/engine/UI/Label.go index 8f60f10..9d47187 100644 --- a/engine/UI/Label.go +++ b/engine/UI/Label.go @@ -37,13 +37,17 @@ type Label struct { Alignment TextAlignment Style Style `json:"-"` + BackgroundElement UIElement } -func (base *Label) Init(*Menu) { +func (base *Label) Init(menu *Menu) { base.Style.FillMissing(defaultLabelStyle) if base.Weight == 0 { base.Weight = 1 } + if base.BackgroundElement != nil { + base.BackgroundElement.Init(menu) + } } func (base *Label) Destroy() { @@ -51,10 +55,7 @@ func (base *Label) Destroy() { 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.DrawRectangleRounded(*position, - *base.Style.Roundness, - 0, // Assume the segments param is always 0 - it doesn't really matter without a border - *base.Style.BacgroundColor) + base.drawBackground(position) var textHeight = base.getTextHeight(position) var textY = int32(position.Y + *base.Style.Padding) if base.Alignment == Center { @@ -67,6 +68,25 @@ func (base *Label) Draw(position *rl.Rectangle) { *base.Style.FontColor) } +func (base *Label) drawBackground(position *rl.Rectangle) { + if base.BackgroundElement == nil { + base.drawSimpleBackground(position) + } else { + base.drawBackgroundElement(position) + } +} + +func (base *Label) drawSimpleBackground(position *rl.Rectangle) { + 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) +} + +func (base *Label) drawBackgroundElement(position *rl.Rectangle) { + base.BackgroundElement.Draw(position) +} + func (base *Label) GetOccupationWeight() float32 { return base.Weight } -- cgit v1.3