GUI: Refactor grid shifting loop into move()

This commit is contained in:
av-dx 2021-06-26 17:25:41 +05:30 committed by Eugene Sandulenko
parent 5d448016e2
commit c58c89b391
2 changed files with 9 additions and 8 deletions

View File

@ -439,6 +439,12 @@ void GridWidget::destroyItems() {
_gridItems.clear();
}
void GridWidget::move(int x, int y) {
for (auto i = _gridItems.begin(); i != _gridItems.end(); ++i) {
(*i)->move(x, y);
}
}
void GridWidget::updateGrid() {
for (auto i = _gridItems.begin(); i != _gridItems.end(); ++i) {
(*i)->update();
@ -501,20 +507,14 @@ void GridWidget::handleMouseWheel(int x, int y, int direction) {
_firstVisibleItem += _itemsPerRow;
// Move the entire grid one row down
for (auto it = _gridItems.begin(); it != _gridItems.end(); ++it) {
GridItemWidget *item = *it;
item->move(0, _gridItemHeight + _gridYSpacing);
}
move(0, _gridItemHeight + _gridYSpacing);
} else if (_gridItems.front()->getRelY() > -_gridItemHeight) {
needsReload = true;
_firstVisibleItem -= _itemsPerRow;
// Move the entire grid one row up
for (auto it = _gridItems.begin(); it != _gridItems.end(); ++it) {
GridItemWidget *item = *it;
item->move(0, -(_gridItemHeight + _gridYSpacing));
}
move(0, -(_gridItemHeight + _gridYSpacing));
}
if (needsReload) {

View File

@ -172,6 +172,7 @@ public:
void destroyItems();
void updateGrid();
void move(int x, int y);
void assignEntriesToItems();
int getThumbnailHeight() const { return _thumbnailHeight; }