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/UI/Image.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 engine/UI/Image.go (limited to 'engine/UI') diff --git a/engine/UI/Image.go b/engine/UI/Image.go new file mode 100644 index 0000000..f7ac7e2 --- /dev/null +++ b/engine/UI/Image.go @@ -0,0 +1,45 @@ +package ui + +import ( + rl "github.com/gen2brain/raylib-go/raylib" +) + +const ImageTypeName string = "image" + +type Image struct { + Texture *rl.Texture2D + Weight float32 + + Style Style `json:"-"` + parentMenu *Menu `json:"-"` + textureRect *rl.Rectangle +} + +func (base *Image) Init(parent *Menu) { + base.parentMenu = parent + base.textureRect = &rl.Rectangle{ + X: 0, Y: 0, + Width: float32(base.Texture.Width), + Height: float32(base.Texture.Height), + } + if base.Weight == 0 { + base.Weight = 1 + } +} + +func (base *Image) Destroy() { +} + +// Gets the scale width of the element. Works similar to CSS's 'flex-grow' +func (base *Image) GetOccupationWeight() float32 { + return base.Weight +} + +// Draw the element with the given size +func (base *Image) Draw(trg *rl.Rectangle) { + rl.DrawTexturePro(*base.Texture, + *base.textureRect, *trg, + rl.Vector2Zero(), + 0, rl.White) +} + -- cgit v1.3