summaryrefslogtreecommitdiff
path: root/engine/UI/Image.go
blob: f7ac7e274a74623611f8ae60f96535984f5026cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)
}