-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathslider.go
77 lines (59 loc) · 1.7 KB
/
slider.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
*/
package winc
import "github.com/tadvi/winc/w32"
type Slider struct {
ControlBase
prevPos int
onScroll EventManager
}
func NewSlider(parent Controller) *Slider {
tb := new(Slider)
tb.InitControl("msctls_trackbar32", parent, 0, w32.WS_TABSTOP|w32.WS_VISIBLE|w32.WS_CHILD /*|w32.TBS_AUTOTICKS*/)
RegMsgHandler(tb)
tb.SetFont(DefaultFont)
tb.SetText("Slider")
tb.SetSize(200, 32)
tb.SetRange(0, 100)
tb.SetPage(10)
return tb
}
func (tb *Slider) OnScroll() *EventManager {
return &tb.onScroll
}
func (tb *Slider) Value() int {
ret := w32.SendMessage(tb.hwnd, w32.TBM_GETPOS, 0, 0)
return int(ret)
}
func (tb *Slider) SetValue(v int) {
tb.prevPos = v
w32.SendMessage(tb.hwnd, w32.TBM_SETPOS, uintptr(w32.BoolToBOOL(true)), uintptr(v))
}
func (tb *Slider) Range() (min, max int) {
min = int(w32.SendMessage(tb.hwnd, w32.TBM_GETRANGEMIN, 0, 0))
max = int(w32.SendMessage(tb.hwnd, w32.TBM_GETRANGEMAX, 0, 0))
return min, max
}
func (tb *Slider) SetRange(min, max int) {
w32.SendMessage(tb.hwnd, w32.TBM_SETRANGE, uintptr(w32.BoolToBOOL(true)), uintptr(w32.MAKELONG(uint16(min), uint16(max))))
}
func (tb *Slider) SetPage(pagesize int) {
w32.SendMessage(tb.hwnd, w32.TBM_SETPAGESIZE, 0, uintptr(pagesize))
}
func (tb *Slider) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
/*
// REMOVE:
// following code did not work, used workaround below
code := w32.LOWORD(uint32(wparam))
switch code {
case w32.TB_ENDTRACK:
tb.onScroll.Fire(NewEvent(tb, nil))
}*/
newPos := tb.Value()
if newPos != tb.prevPos {
tb.onScroll.Fire(NewEvent(tb, nil))
tb.prevPos = newPos
}
return w32.DefWindowProc(tb.hwnd, msg, wparam, lparam)
}