summaryrefslogtreecommitdiff
path: root/engine/UI
diff options
context:
space:
mode:
authorphyscik <mynameisgennadiy@vk.com>2026-03-23 18:04:56 +0500
committerphyscik <mynameisgennadiy@vk.com>2026-03-23 18:04:56 +0500
commita4d30665a9aeddc9777761a322a48d56d9f44378 (patch)
tree13b7a2d48dfbcd9b29b191c6dd572ce4cd39d070 /engine/UI
parentd470cca696d98b2a84f1667f29139c750888cdcd (diff)
Image UI element basics
Diffstat (limited to 'engine/UI')
-rw-r--r--engine/UI/Image.go45
1 files changed, 45 insertions, 0 deletions
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)
+}
+