GUI: Set ScrollContainer single step to kLineHeight instead of 1 pixel

The single step is the amount of scroll done when clicking once on
the scrollbar up or down arrow. It used to be 1 entry, but for the
ScrollContainer 1 entry is 1 pixel, which was too litle. Now the
single step can be set to a multiple entries.
This commit is contained in:
Thierry Crozat 2018-07-23 23:36:37 +01:00
parent f7a4b74130
commit 211ef61fdf
3 changed files with 9 additions and 6 deletions

View file

@ -47,6 +47,7 @@ ScrollBarWidget::ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h)
_numEntries = 0; _numEntries = 0;
_entriesPerPage = 0; _entriesPerPage = 0;
_currentPos = 0; _currentPos = 0;
_singleStep = 1;
_repeatTimer = 0; _repeatTimer = 0;
} }
@ -60,12 +61,12 @@ void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount)
if (y <= UP_DOWN_BOX_HEIGHT) { if (y <= UP_DOWN_BOX_HEIGHT) {
// Up arrow // Up arrow
_currentPos--; _currentPos -= _singleStep;
_repeatTimer = g_system->getMillis() + kRepeatInitialDelay; _repeatTimer = g_system->getMillis() + kRepeatInitialDelay;
_draggingPart = kUpArrowPart; _draggingPart = kUpArrowPart;
} else if (y >= _h - UP_DOWN_BOX_HEIGHT) { } else if (y >= _h - UP_DOWN_BOX_HEIGHT) {
// Down arrow // Down arrow
_currentPos++; _currentPos += _singleStep;
_repeatTimer = g_system->getMillis() + kRepeatInitialDelay; _repeatTimer = g_system->getMillis() + kRepeatInitialDelay;
_draggingPart = kDownArrowPart; _draggingPart = kDownArrowPart;
} else if (y < _sliderPos) { } else if (y < _sliderPos) {
@ -93,9 +94,9 @@ void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) {
return; return;
if (direction < 0) { if (direction < 0) {
_currentPos--; _currentPos -= _singleStep;
} else { } else {
_currentPos++; _currentPos += _singleStep;
} }
// Make sure that _currentPos is still inside the bounds // Make sure that _currentPos is still inside the bounds
@ -146,9 +147,9 @@ void ScrollBarWidget::handleTickle() {
const int old_pos = _currentPos; const int old_pos = _currentPos;
if (_part == kUpArrowPart) if (_part == kUpArrowPart)
_currentPos -= 3; _currentPos -= 3 * _singleStep;
else if (_part == kDownArrowPart) else if (_part == kDownArrowPart)
_currentPos += 3; _currentPos += 3 * _singleStep;
checkBounds(old_pos); checkBounds(old_pos);

View file

@ -60,6 +60,7 @@ public:
int _numEntries; int _numEntries;
int _entriesPerPage; int _entriesPerPage;
int _currentPos; int _currentPos;
int _singleStep;
public: public:
ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h); ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h);

View file

@ -73,6 +73,7 @@ void ScrollContainerWidget::recalc() {
_verticalScroll->_numEntries = h; _verticalScroll->_numEntries = h;
_verticalScroll->_currentPos = _scrolledY; _verticalScroll->_currentPos = _scrolledY;
_verticalScroll->_entriesPerPage = _limitH; _verticalScroll->_entriesPerPage = _limitH;
_verticalScroll->_singleStep = kLineHeight;
_verticalScroll->setPos(_w - scrollbarWidth, _scrolledY+1); _verticalScroll->setPos(_w - scrollbarWidth, _scrolledY+1);
_verticalScroll->setSize(scrollbarWidth, _limitH -2); _verticalScroll->setSize(scrollbarWidth, _limitH -2);
} }