-
Notifications
You must be signed in to change notification settings - Fork 7
/
StepSliderInt.go
42 lines (39 loc) · 1.09 KB
/
StepSliderInt.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
package gui
import (
"github.com/inkyblackness/imgui-go/v3"
)
// StepSliderIntV creates a SliderInt with additional buttons to make single digit steps.
// min and max parameters are inclusive. Returns true on change.
func StepSliderIntV(label string, value *int, min, max int, format string) bool {
imgui.PushID(label)
changed := false
if imgui.Button("-") && (*value > min) {
*value--
changed = true
}
innerSpacing := imgui.CurrentStyle().ItemInnerSpacing()
imgui.SameLineV(0, innerSpacing.X)
if imgui.Button("+") && (*value < max) {
*value++
changed = true
}
imgui.SameLineV(0, innerSpacing.X)
value32 := int32(*value)
if imgui.SliderIntV(label, &value32, int32(min), int32(max), format, imgui.SlidersFlagsNone) {
switch {
case int(value32) < min:
*value = min
case int(value32) > max:
*value = max
default:
*value = int(value32)
}
changed = true
}
imgui.PopID()
return changed
}
// StepSliderInt calls StepSliderIntV(label, value, min, max, "%d").
func StepSliderInt(label string, value *int, min, max int) bool {
return StepSliderIntV(label, value, min, max, "%d")
}