-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollbar.go
92 lines (72 loc) · 2.12 KB
/
scrollbar.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package rlyeh
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type Scrollbar struct {
scrollable Scrollable
layout Layout
state State
}
func NewScrollbar(fill Fill, scrollable Scrollable) *Scrollbar {
self := &Scrollbar{}
self.scrollable = scrollable
self.state = Normal
switch fill {
case Vertical:
self.layout = NewVBox(Right, Vertical)
self.layout.Add(NewButton(Top, Horizontal, "-", func() { self.scrollable.Scroll(-1) }))
self.layout.Add(NewButton(Auto, Both, "=", nil))
self.layout.Add(NewButton(Bottom, Horizontal, "+", func() { self.scrollable.Scroll(1) }))
case Horizontal:
self.layout = NewHBox(Bottom, Horizontal)
self.layout.Add(NewButton(Left, Vertical, "-", func() { self.scrollable.Scroll(-1) }))
self.layout.Add(NewButton(Auto, Both, "=", nil))
self.layout.Add(NewButton(Right, Vertical, "+", func() { self.scrollable.Scroll(1) }))
default:
panic("fill should be 'Vertical' or 'Horizontal'")
}
return self
}
func (self *Scrollbar) GetId() int32 {
return self.layout.GetId()
}
func (self *Scrollbar) SetId(id int32) {
self.layout.SetId(id)
}
func (self *Scrollbar) GetParent() Widget {
return self.layout.GetParent()
}
func (self *Scrollbar) SetParent(parent Widget) {
self.layout.SetParent(parent)
}
func (self *Scrollbar) GetBounds() rl.Rectangle {
return self.layout.GetBounds()
}
func (self *Scrollbar) SetBounds(bounds rl.Rectangle) {
self.layout.SetBounds(bounds)
}
func (self *Scrollbar) GetAlign() Align {
return self.layout.GetAlign()
}
func (self *Scrollbar) GetFill() Fill {
return self.layout.GetFill()
}
func (self *Scrollbar) GetDataSize() Size {
return self.layout.GetDataSize()
}
func (self *Scrollbar) Update(dt float32) {
self.layout.Update(dt)
bounds := self.GetBounds()
button := self.layout.GetWidgets()[0]
w := button.GetBounds().Width
h := button.GetBounds().Height
slider := self.layout.GetWidgets()[1]
slider.SetBounds(rl.Rectangle{X: bounds.X,
Y: bounds.Y + h + (bounds.Height-3*h)*float32(1+self.scrollable.GetCurrent())/float32(self.scrollable.GetCount()),
Width: w,
Height: h,
})
}
func (self *Scrollbar) Draw() {
self.layout.Draw()
}