-
Notifications
You must be signed in to change notification settings - Fork 7
/
TextureSelector.go
44 lines (40 loc) · 1.43 KB
/
TextureSelector.go
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
package render
import (
"fmt"
"github.com/inkyblackness/imgui-go/v3"
"github.com/inkyblackness/hacked/editor/graphics"
"github.com/inkyblackness/hacked/ss1/resource"
)
// TextureSelector renders a horizontal list of game textures, with selection capability.
func TextureSelector(label string, width float32, guiScale float32,
count int, selectedIndex int, cache *graphics.TextureCache, keyResolver func(int) resource.Key,
tooltipText func(int) string,
changeCallback func(int)) {
if imgui.BeginChildV(label, imgui.Vec2{X: width * guiScale, Y: 100 * guiScale}, true,
imgui.WindowFlagsHorizontalScrollbar|imgui.WindowFlagsNoScrollWithMouse) {
for i := 0; i < count; i++ {
key := keyResolver(i)
imgui.PushStyleVarVec2(imgui.StyleVarWindowPadding, imgui.Vec2{X: 0, Y: 0})
if imgui.BeginChildV(fmt.Sprintf("%3d", i), imgui.Vec2{X: 80 * guiScale, Y: 64 * guiScale}, false,
imgui.WindowFlagsNoNav|imgui.WindowFlagsNoScrollWithMouse) {
imgui.BeginGroup()
if imgui.SelectableV("", selectedIndex == i, 0, imgui.Vec2{X: 0, Y: 64 * guiScale}) {
changeCallback(i)
}
imgui.SameLine()
TextureImage(fmt.Sprintf("%3d", i), cache, key, imgui.Vec2{X: 64 * guiScale, Y: 64 * guiScale})
imgui.EndGroup()
if imgui.IsItemHovered() {
text := tooltipText(i)
if len(text) > 0 {
imgui.SetTooltip(text)
}
}
}
imgui.EndChild()
imgui.PopStyleVar()
imgui.SameLine()
}
}
imgui.EndChild()
}