summaryrefslogtreecommitdiff
path: root/engine/Dynamic/Descriptors
diff options
context:
space:
mode:
Diffstat (limited to 'engine/Dynamic/Descriptors')
-rw-r--r--engine/Dynamic/Descriptors/Menu.go21
-rw-r--r--engine/Dynamic/Descriptors/UIElement.go20
2 files changed, 41 insertions, 0 deletions
diff --git a/engine/Dynamic/Descriptors/Menu.go b/engine/Dynamic/Descriptors/Menu.go
new file mode 100644
index 0000000..fc0c2de
--- /dev/null
+++ b/engine/Dynamic/Descriptors/Menu.go
@@ -0,0 +1,21 @@
+package descriptors
+
+import ui "github.com/DegustatorPonos/RuinesOfRafdolon/UI"
+
+type MenuDescriptor struct {
+ PaddingX float32
+ PaddingY float32
+ Contents UIElementDescriptor
+}
+
+func (base *MenuDescriptor) Parse() (*ui.Menu, error) {
+ var contents, contentsErr = base.Contents.Parse()
+ if contentsErr != nil {
+ return nil, contentsErr
+ }
+ return &ui.Menu {
+ PaddingX: base.PaddingX,
+ PaddingY: base.PaddingY,
+ Contents: contents,
+ }, nil
+}
diff --git a/engine/Dynamic/Descriptors/UIElement.go b/engine/Dynamic/Descriptors/UIElement.go
index 9b88ab3..1b19ba2 100644
--- a/engine/Dynamic/Descriptors/UIElement.go
+++ b/engine/Dynamic/Descriptors/UIElement.go
@@ -22,11 +22,13 @@ type UIElementDescriptor struct {
Spacing float32
}
+// We have to initialize the map so that we avoid the circular reference in the recursive parsing
func InitUIParser() {
typeParsers = map[string]func(*UIElementDescriptor) ui.UIElement {
ui.VoidTypeName: parseAsVoid,
ui.LabelTypeName: parseAsLabel,
ui.GridRowTypeName: parseAsGridRow,
+ ui.GridColumnTypeName: parseAsGridColumn,
}
}
@@ -82,3 +84,21 @@ func parseAsGridRow(base *UIElementDescriptor) ui.UIElement {
}
return &outp
}
+
+func parseAsGridColumn(base *UIElementDescriptor) ui.UIElement {
+ var outp = ui.GridColumn {
+ Weight: base.Weight,
+ Spacing: base.Spacing,
+ Style: base.Style.Parse(),
+ Objects: make([]ui.UIElement, 0, len(base.Children)),
+ }
+ for _, v := range base.Children {
+ var child, parseErr = v.Parse()
+ if parseErr != nil {
+ rl.TraceLog(rl.LogWarning, "Failed to parse a parent element of a grid column: %v", parseErr.Error())
+ continue
+ }
+ outp.Objects = append(outp.Objects, child)
+ }
+ return &outp
+}