forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.Scrollbar.lua
More file actions
95 lines (77 loc) · 2.66 KB
/
Copy pathwidgets.Scrollbar.lua
File metadata and controls
95 lines (77 loc) · 2.66 KB
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
93
94
95
config.target = 'core'
local gui = require('gui')
local widgets = require('gui.widgets')
function test.update()
local s = widgets.Scrollbar{}
s.frame_body = {height=100} -- give us some space to work with
-- initial defaults
expect.eq(1, s.top_elem)
expect.eq(1, s.elems_per_page)
expect.eq(1, s.num_elems)
expect.eq(0, s.bar_offset)
expect.eq(2, s.bar_height)
-- top_elem, elems_per_page, num_elems
s:update(1, 10, 0)
expect.eq(1, s.top_elem)
expect.eq(10, s.elems_per_page)
expect.eq(0, s.num_elems)
expect.eq(0, s.bar_offset)
expect.eq(2, s.bar_height)
-- first 10 of 50 shown
s:update(1, 10, 50)
expect.eq(1, s.top_elem)
expect.eq(10, s.elems_per_page)
expect.eq(50, s.num_elems)
expect.eq(0, s.bar_offset)
expect.eq(19, s.bar_height)
-- bottom 10 of 50 shown
s:update(41, 10, 50)
expect.eq(41, s.top_elem)
expect.eq(10, s.elems_per_page)
expect.eq(50, s.num_elems)
expect.eq(79, s.bar_offset)
expect.eq(19, s.bar_height)
-- ~middle 10 of 50 shown
s:update(23, 10, 50)
expect.eq(23, s.top_elem)
expect.eq(10, s.elems_per_page)
expect.eq(50, s.num_elems)
expect.eq(44, s.bar_offset)
expect.eq(19, s.bar_height)
end
function test.onInput()
local spec = nil
local mock_on_scroll = function(scroll_spec) spec = scroll_spec end
local s = widgets.Scrollbar{on_scroll=mock_on_scroll}
s.frame_body = {height=100} -- give us some space to work with
local y = nil
s.getMousePos = function() return 0, y end
-- put scrollbar somewhere in the middle so we can click above and below it
s:update(23, 10, 50)
expect.false_(s:onInput{}, 'no mouse down')
expect.false_(s:onInput{_MOUSE_L=true}, 'no y coord')
spec, y = nil, 0
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('up_small', spec, 'on up arrow')
spec, y = nil, 1
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('up_large', spec, 'on body above bar')
spec, y = nil, 44
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('up_large', spec, 'on body just above bar')
spec, y = nil, 45
expect.true_(s:onInput{_MOUSE_L=true})
expect.nil_(spec, 'on top of bar')
spec, y = nil, 63
expect.true_(s:onInput{_MOUSE_L=true})
expect.nil_(spec, 'on bottom of bar')
spec, y = nil, 64
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('down_large', spec, 'on body just below bar')
spec, y = nil, 98
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('down_large', spec, 'on body below bar')
spec, y = nil, 99
expect.true_(s:onInput{_MOUSE_L=true})
expect.eq('down_small', spec, 'on down arrow')
end