From 64f718a1cd694be0952fd3700636d81ba05d30f0 Mon Sep 17 00:00:00 2001 From: Physcik Date: Sat, 7 Feb 2026 23:20:48 +0500 Subject: Dynamic menus --- engine/Dynamic/Descriptors/Menu.go | 21 +++++++++++++++++++++ engine/Dynamic/Descriptors/UIElement.go | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 engine/Dynamic/Descriptors/Menu.go (limited to 'engine/Dynamic/Descriptors') 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 +} -- cgit v1.3