diff options
| author | physcik <mynameisgennadiy@vk.com> | 2026-03-23 18:43:07 +0500 |
|---|---|---|
| committer | physcik <mynameisgennadiy@vk.com> | 2026-03-23 18:43:07 +0500 |
| commit | 3e3e1f480f87192cf1042bec0ee0d4bb7c356e62 (patch) | |
| tree | 7998bacf5657c83cbee0cb97f5b0a65c66cabe3d /engine/UI | |
| parent | a4d30665a9aeddc9777761a322a48d56d9f44378 (diff) | |
Recursive UI elements support
Diffstat (limited to 'engine/UI')
| -rw-r--r-- | engine/UI/Label.go | 30 |
1 files changed, 25 insertions, 5 deletions
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 } |
