diff options
| author | Physcik <mynameisgennadiy@vk.com> | 2026-02-07 23:20:48 +0500 |
|---|---|---|
| committer | Physcik <mynameisgennadiy@vk.com> | 2026-02-07 23:20:48 +0500 |
| commit | 64f718a1cd694be0952fd3700636d81ba05d30f0 (patch) | |
| tree | 3e9a19e34328072e15b2c8e1387484c7a3099265 /engine/Dynamic/Descriptors | |
| parent | 08242fe7c284d8e02c662d65831a08a6482e87a3 (diff) | |
Dynamic menus
Diffstat (limited to 'engine/Dynamic/Descriptors')
| -rw-r--r-- | engine/Dynamic/Descriptors/Menu.go | 21 | ||||
| -rw-r--r-- | engine/Dynamic/Descriptors/UIElement.go | 20 |
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 +} |
