summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/MainMenu.json10
-rw-r--r--engine/Dynamic/Descriptors/UIElement.go16
-rw-r--r--engine/UI/Label.go30
3 files changed, 45 insertions, 11 deletions
diff --git a/assets/MainMenu.json b/assets/MainMenu.json
index d44ab69..9054627 100644
--- a/assets/MainMenu.json
+++ b/assets/MainMenu.json
@@ -14,12 +14,12 @@
"Spacing": 0.01,
"Children": [
{
- "Type": "image",
- "TextureName": "testPackage/water.png"
- },
- {
"Type": "label",
- "Text": "Ruines of Rafdalon"
+ "Text": "Ruines of Rafdalon",
+ "BackgroundElement": {
+ "Type": "image",
+ "TextureName": "testPackage/water.png"
+ }
},
{
"Type": "label",
diff --git a/engine/Dynamic/Descriptors/UIElement.go b/engine/Dynamic/Descriptors/UIElement.go
index da523e9..0e59c9a 100644
--- a/engine/Dynamic/Descriptors/UIElement.go
+++ b/engine/Dynamic/Descriptors/UIElement.go
@@ -14,6 +14,9 @@ type UIElementDescriptor struct {
Weight float32
Style StyleDescriptor
+ // For recursive elements
+ BackgroundElement *UIElementDescriptor
+
// For labels
Text string
Alignment string
@@ -64,11 +67,22 @@ func parseAsLabel(base *UIElementDescriptor) ui.UIElement {
alignment = ui.Start
}
+ var child ui.UIElement = nil
+ if base.BackgroundElement != nil {
+ var parsed, err = base.BackgroundElement.Parse()
+ if err == nil {
+ child = parsed
+ } else {
+ rl.TraceLog(rl.LogWarning, "Failed to parse a background element of a label: %v", err.Error())
+ }
+ }
+
return &ui.Label {
Weight: base.Weight,
Text: base.Text,
Alignment: alignment,
Style: base.Style.Parse(),
+ BackgroundElement: child,
}
}
@@ -111,7 +125,7 @@ func parseAsGridColumn(base *UIElementDescriptor) ui.UIElement {
func parseAsImage(base *UIElementDescriptor) ui.UIElement {
var texture, err = components.Resources.Textures.GetTextureByName(base.TextureName)
if err != nil {
- rl.TraceLog(rl.LogWarning, "Failed to parse a texture %s requested by an inage UI element: %v", base.TextureName, err.Error())
+ rl.TraceLog(rl.LogWarning, "Failed to parse a texture %s requested by an image UI element: %v", base.TextureName, err.Error())
return nil
}
var outp = ui.Image {
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
}