Skip to content

Commit a79f5d3

Browse files
committed
debugui: improve the slider behavior to enable to select the maximum value
1 parent 83221f7 commit a79f5d3

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

example/gallery/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Game struct {
4747
num3_1 float64
4848
num3_2 float64
4949
num4 float64
50+
num5 int
5051
}
5152

5253
func NewGame() (*Game, error) {

example/gallery/ui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func (g *Game) testWindow(ctx *debugui.Context) {
156156
ctx.NumberFieldF(&g.num3_1, 0.1, 2)
157157
ctx.NumberFieldF(&g.num3_2, 0.1, 2)
158158
ctx.SliderF(&g.num4, 0, 10, 0.1, 2)
159+
ctx.Slider(&g.num5, 0, 2, 1)
159160
})
160161
ctx.Header("Licenses", false, func() {
161162
ctx.Text(`The photograph by Chris Nokleberg is licensed under the Creative Commons Attribution 4.0 License

slider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (c *Context) slider(value *int, low, high, step int, id widgetID, opt optio
6969
var e EventHandler
7070
if c.focus == id && c.pointing.pressed() {
7171
if w := bounds.Dx() - defaultStyle.thumbSize; w > 0 {
72-
v = low + (c.pointingPosition().X-bounds.Min.X)*(high-low)/w
72+
v = low + (c.pointingPosition().X-bounds.Min.X-defaultStyle.thumbSize/2)*(high-low+step)/w
7373
}
7474
if step != 0 {
7575
v = v / step * step
@@ -112,7 +112,7 @@ func (c *Context) sliderF(value *float64, low, high, step float64, digits int, i
112112
var e EventHandler
113113
if c.focus == id && c.pointing.pressed() {
114114
if w := float64(bounds.Dx() - defaultStyle.thumbSize); w > 0 {
115-
v = low + float64(c.pointingPosition().X-bounds.Min.X)*(high-low)/w
115+
v = low + float64(c.pointingPosition().X-bounds.Min.X-defaultStyle.thumbSize/2)*(high-low+step)/w
116116
}
117117
if step != 0 {
118118
v = math.Round(v/step) * step

0 commit comments

Comments
 (0)