summaryrefslogtreecommitdiff
path: root/engine/UI
diff options
context:
space:
mode:
authorphyscik <mynameisgennadiy@vk.com>2026-03-27 14:49:41 +0500
committerphyscik <mynameisgennadiy@vk.com>2026-03-27 14:50:00 +0500
commit6f1a05cfa4d9323b55dc4da3221d10c58c2327d4 (patch)
tree8812ad103641f0711b650b62e4b27d30405ffdb2 /engine/UI
parent3f6bf25f2ed5fc5626c46a4218cc1d627ec401c2 (diff)
Stacked elements display logic separated
Diffstat (limited to 'engine/UI')
-rw-r--r--engine/UI/Label.go33
-rw-r--r--engine/UI/StackedElement.go33
2 files changed, 44 insertions, 22 deletions
diff --git a/engine/UI/Label.go b/engine/UI/Label.go
index 08f5943..64bb8d0 100644
--- a/engine/UI/Label.go
+++ b/engine/UI/Label.go
@@ -53,9 +53,17 @@ func (base *Label) Init(menu *Menu) {
func (base *Label) Destroy() {
}
+func (base *Label) GetBackgroundElement() UIElement {
+ return base.BackgroundElement
+}
+
+func (base *Label) GetOccupationWeight() float32 {
+ return base.Weight
+}
+
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)
- base.drawBackground(position)
+ drawStackedElementBackground(base, position)
var textHeight = base.getTextHeight(position)
var textY = int32(position.Y + *base.Style.Padding)
if base.Alignment == Center {
@@ -68,27 +76,8 @@ 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
+func (base *Label) GetStyle() *Style {
+ return &base.Style
}
// Returns the size of the text that will not overflow in the side
diff --git a/engine/UI/StackedElement.go b/engine/UI/StackedElement.go
new file mode 100644
index 0000000..1c41a19
--- /dev/null
+++ b/engine/UI/StackedElement.go
@@ -0,0 +1,33 @@
+package ui
+
+import rl "github.com/gen2brain/raylib-go/raylib"
+
+// An element that can use another element as a background
+type StackedElement interface {
+ // Returns an applied style
+ GetStyle() *Style
+
+ // Returns a background element. Should return nil if it is not uupposed to be drawn
+ GetBackgroundElement() UIElement
+}
+
+func drawStackedElementBackground(base StackedElement, targetPosition *rl.Rectangle) {
+ var bgElement = base.GetBackgroundElement()
+ if bgElement == nil {
+ _drawSimpleBackground(base.GetStyle(), targetPosition)
+ } else {
+ _drawElement(bgElement, targetPosition)
+ }
+}
+
+func _drawSimpleBackground(style *Style, trg *rl.Rectangle) {
+ rl.DrawRectangleRounded(*trg,
+ *style.Roundness,
+ 0, // Assume the segments param is always 0 - it doesn't really matter without a border
+ *style.BacgroundColor)
+}
+
+// Should not be used outside of the scope of this file
+func _drawElement(elem UIElement, trg *rl.Rectangle) {
+ elem.Draw(trg)
+}