diff options
Diffstat (limited to 'engine/Dynamic')
| -rw-r--r-- | engine/Dynamic/Descriptors/UIElement.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/engine/Dynamic/Descriptors/UIElement.go b/engine/Dynamic/Descriptors/UIElement.go index 1b19ba2..da523e9 100644 --- a/engine/Dynamic/Descriptors/UIElement.go +++ b/engine/Dynamic/Descriptors/UIElement.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + components "github.com/DegustatorPonos/RuinesOfRafdolon/Components" ui "github.com/DegustatorPonos/RuinesOfRafdolon/UI" rl "github.com/gen2brain/raylib-go/raylib" ) @@ -20,6 +21,9 @@ type UIElementDescriptor struct { // For grid elements Children []UIElementDescriptor Spacing float32 + + // For images + TextureName string } // We have to initialize the map so that we avoid the circular reference in the recursive parsing @@ -27,6 +31,7 @@ func InitUIParser() { typeParsers = map[string]func(*UIElementDescriptor) ui.UIElement { ui.VoidTypeName: parseAsVoid, ui.LabelTypeName: parseAsLabel, + ui.ImageTypeName: parseAsImage, ui.GridRowTypeName: parseAsGridRow, ui.GridColumnTypeName: parseAsGridColumn, } @@ -102,3 +107,17 @@ func parseAsGridColumn(base *UIElementDescriptor) ui.UIElement { } return &outp } + +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()) + return nil + } + var outp = ui.Image { + Weight: base.Weight, + Texture: texture, + Style: base.Style.Parse(), + } + return &outp +} |
