M changelog.md => changelog.md +1 -0
@@ 14,6 14,7 @@
* Fix absent notifications
* Fix newly added contact recognized as a duplicate of temporary contact.
+* Fix default borderCallback navigation in GridLayout.
## [0.52.1 2020-12-23]
M module-gui/gui/widgets/BoxLayout.cpp => module-gui/gui/widgets/BoxLayout.cpp +1 -1
@@ 31,7 31,7 @@ namespace gui
if (handleNavigation(inputEvent)) {
return true;
}
- if (borderCallback && borderCallback(inputEvent)) {
+ if (borderCallback && isInputNavigation(inputEvent) && borderCallback(inputEvent)) {
outOfDrawAreaItems.clear();
return true;
}
M module-gui/gui/widgets/GridLayout.cpp => module-gui/gui/widgets/GridLayout.cpp +37 -9
@@ 19,25 19,28 @@ GridLayout::GridLayout(
if (inputEvent.state != InputEvent::State::keyReleasedShort) {
return false;
}
+
+ auto it = this->getNavigationFocusedItem();
+ auto distance = std::distance(children.begin(), it);
switch (inputEvent.keyCode) {
case KeyCode::KEY_UP: {
- auto it = this->getNavigationFocusedItem();
- this->setFocusItem((*std::next(it, (this->rowSize - 1) * this->colSize)));
+ auto realRowSize = calculateRowSizeForBorderTransition(distance);
+ this->setFocusItem((*std::next(it, (realRowSize - 1) * this->colSize)));
return true;
}
case KeyCode::KEY_DOWN: {
- auto it = this->getNavigationFocusedItem();
- this->setFocusItem((*std::prev(it, (this->rowSize - 1) * this->colSize)));
+ auto realRowSize = calculateRowSizeForBorderTransition(distance);
+ this->setFocusItem((*std::prev(it, (realRowSize - 1) * this->colSize)));
return true;
}
case KeyCode::KEY_LEFT: {
- auto it = this->getNavigationFocusedItem();
- this->setFocusItem((*std::next(it, this->colSize - 1)));
+ auto realColSize = calculateColumnSizeForBorderTransition(distance);
+ this->setFocusItem((*std::next(it, realColSize - 1)));
return true;
}
case KeyCode::KEY_RIGHT: {
- auto it = this->getNavigationFocusedItem();
- this->setFocusItem((*std::prev(it, this->colSize - 1)));
+ auto realColSize = calculateColumnSizeForBorderTransition(distance);
+ this->setFocusItem((*std::prev(it, realColSize - 1)));
return true;
}
default: {
@@ 47,6 50,25 @@ GridLayout::GridLayout(
};
}
+uint32_t GridLayout::calculateColumnSizeForBorderTransition(const uint32_t currentPosition)
+{
+ auto realColSize = colSize;
+ if (elementsInIncompletedLastRow) {
+ if (((currentPosition / colSize) + 1) >= rowSize)
+ realColSize = elementsInIncompletedLastRow;
+ }
+ return realColSize;
+}
+uint32_t GridLayout::calculateRowSizeForBorderTransition(const uint32_t currentPosition)
+{
+ auto realRowSize = rowSize;
+ if (elementsInIncompletedLastRow) {
+ if (((currentPosition % (colSize)) + 1) > elementsInIncompletedLastRow)
+ realRowSize--;
+ }
+ return realRowSize;
+}
+
void GridLayout::resizeItems()
{
if (grid.x == 0 || grid.y == 0) {
@@ 57,7 79,13 @@ void GridLayout::resizeItems()
uint32_t el_in_y = area().h / grid.y;
colSize = children.size() < area().w / grid.x ? children.size() : area().w / grid.x;
- rowSize = colSize != 0 ? children.size() / colSize : 1;
+ rowSize = colSize != 0 ? (children.size() / colSize) : 1;
+ if (colSize > 1 && (static_cast<double>(children.size()) / colSize) > 1.0) {
+ elementsInIncompletedLastRow = children.size() % colSize;
+ }
+ if (elementsInIncompletedLastRow > 0) {
+ rowSize++;
+ }
uint32_t strech_x = 0;
uint32_t strech_y = 0;
M module-gui/gui/widgets/GridLayout.hpp => module-gui/gui/widgets/GridLayout.hpp +7 -0
@@ 34,6 34,13 @@ namespace gui
uint32_t rowSize = 0;
uint32_t colSize = 0;
+ ///> elementsInIncompletedLastRow describes how many items has been put to last row,
+ /// in case when items for last row is not equal to colSize
+ uint32_t elementsInIncompletedLastRow = 0;
+
+ private:
+ uint32_t calculateColumnSizeForBorderTransition(const uint32_t currentPosition);
+ uint32_t calculateRowSizeForBorderTransition(const uint32_t currentPosition);
};
}; // namespace gui
M module-gui/gui/widgets/Item.cpp => module-gui/gui/widgets/Item.cpp +5 -0
@@ 30,6 30,11 @@ namespace gui
}
}
+ bool isInputNavigation(const InputEvent &evt)
+ {
+ return inputToNavigation(evt) != NavigationDirection::NONE;
+ }
+
Item::Item()
: focus{false}, type{ItemType::ITEM}, parent{nullptr}, radius{0}, visible{true},
verticalPolicy{LayoutVerticalPolicy::LAYOUT_POLICY_VERTICAL_EXPAND},
M module-gui/gui/widgets/Item.hpp => module-gui/gui/widgets/Item.hpp +1 -1
@@ 363,5 363,5 @@ namespace gui
};
NavigationDirection inputToNavigation(const InputEvent &evt);
-
+ bool isInputNavigation(const InputEvent &evt);
} /* namespace gui */