From a4d30665a9aeddc9777761a322a48d56d9f44378 Mon Sep 17 00:00:00 2001 From: physcik Date: Mon, 23 Mar 2026 18:04:56 +0500 Subject: Image UI element basics --- engine/Dynamic/Descriptors/UIElement.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'engine/Dynamic') 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 +} -- cgit v1.3