-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyScroll.h
95 lines (84 loc) · 1.51 KB
/
MyScroll.h
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
// Code by L.Geerinckx 28-1-2021 | https://github.com/PierreIsCoding
class MyScroll
{
private:
int _index;
int _len;
bool _loopScroll;
void (*_handler)(int);
int _x; // x start cursor;
int _y; // y start cursor;
String _label;
int minValue;
public:
MyScroll(int, void handler(int), int, int, bool);
int getIndex();
int UP();
int DOWN();
void start();
void toggleIncrement();
void setIndex(int);
int fine = 1;
int course = 10;
int increment = course;
};
MyScroll::MyScroll(int len, void handler(int), int _minValue = 0, int start = 0, bool loopScroll = 0)
{
_len = len;
_loopScroll = loopScroll;
_index = start;
_handler = handler;
minValue = _minValue;
}
int MyScroll::getIndex()
{
return _index;
}
void MyScroll::start()
{
_handler(_index);
}
int MyScroll::UP()
{
if (_index < (_len - increment))
{
_index += increment;
_handler(_index);
}
else if (_loopScroll)
{
_index = 0;
}
return _index;
}
int MyScroll::DOWN()
{
if (_index >= increment + minValue)
{
_index -= increment;
_handler(_index);
}
else if (_loopScroll)
{
_index = _len - 1;
}
return _index;
}
void MyScroll::toggleIncrement()
{
if (increment == course)
{
increment = fine;
}
else
{
increment = course;
}
}
void MyScroll::setIndex(int index)
{
if (index <= _len && index >= minValue)
{
_index = index;
}
}