M module-apps/application-calendar/windows/CalendarMainWindow.cpp => module-apps/application-calendar/windows/CalendarMainWindow.cpp +8 -19
@@ 248,34 248,23 @@ namespace gui
}
case KeyCode::KEY_LEFT: {
LOG_DEBUG("Call borderCallback -> go to the previous element");
- std::list<Item *>::iterator it =
- std::find(month->children.begin(), month->children.end(), month->getFocusItem());
- if (std::prev(*it) != nullptr && (*std::prev(it))->activeItem) {
- month->setFocusItem((*std::prev(it)));
+ std::list<Item *>::iterator it = month->getNavigationFocusedItem();
+ if (month->nextNavigationItem(std::prev(it)) != nullptr) {
+ month->setFocusItem(month->nextNavigationItem(std::prev(it)));
}
else {
- auto it = --month->children.end();
- while (*it == nullptr || !(*it)->activeItem) {
- --it;
- }
- month->setFocusItem((*it));
+ month->setFocusOnLastElement();
}
return true;
}
case KeyCode::KEY_RIGHT: {
LOG_DEBUG("Call borderCallback -> go to the next element");
- std::list<Item *>::iterator it =
- std::find(month->children.begin(), month->children.end(), month->getFocusItem());
- if (std::next(*it) != nullptr && (*std::next(it))->activeItem) {
- month->setFocusItem((*std::next(it)));
+ std::list<Item *>::iterator it = month->getNavigationFocusedItem();
+ if (month->nextNavigationItem(std::next(it)) != nullptr) {
+ month->setFocusItem(month->nextNavigationItem(std::next(it)));
}
else {
- auto it = month->children.begin();
- while (*it == nullptr || !(*it)->activeItem) {
- LOG_DEBUG("Call borderCallback -> go to the next element");
- ++it;
- }
- month->setFocusItem((*it));
+ month->setFocusOnElement(0);
}
return true;
}
M => +38 -17
@@ 181,37 181,35 @@ namespace gui
if (inputEvent.state != InputEvent::State::keyReleasedShort) {
return false;
}
if (inputEvent.keyCode == KeyCode::KEY_UP) {
switch (inputEvent.keyCode) {
case KeyCode::KEY_UP: {
LOG_DEBUG("borderCallback -> Up");
std::list<Item *>::iterator it =
std::find(mainMenu->children.begin(), mainMenu->children.end(), mainMenu->getFocusItem());
mainMenu->setFocusItem((*std::next(it, (mainMenu->col_numb - 1) * mainMenu->row_numb)));
std::list<Item *>::iterator it = mainMenu->getNavigationFocusedItem();
mainMenu->setFocusItem((*std::next(it, (mainMenu->rowSize - 1) * mainMenu->colSize)));
return true;
}
else if (inputEvent.keyCode == KeyCode::KEY_DOWN) {
case KeyCode::KEY_DOWN: {
LOG_DEBUG("borderCallback -> Down");
std::list<Item *>::iterator it =
std::find(mainMenu->children.begin(), mainMenu->children.end(), mainMenu->getFocusItem());
mainMenu->setFocusItem((*std::prev(it, (mainMenu->col_numb - 1) * mainMenu->row_numb)));
std::list<Item *>::iterator it = mainMenu->getNavigationFocusedItem();
mainMenu->setFocusItem((*std::prev(it, (mainMenu->rowSize - 1) * mainMenu->colSize)));
return true;
}
else if (inputEvent.keyCode == KeyCode::KEY_LEFT) {
case KeyCode::KEY_LEFT: {
LOG_DEBUG("borderCallback -> Left");
std::list<Item *>::iterator it =
std::find(mainMenu->children.begin(), mainMenu->children.end(), mainMenu->getFocusItem());
mainMenu->setFocusItem((*std::next(it, mainMenu->col_numb - 1)));
std::list<Item *>::iterator it = mainMenu->getNavigationFocusedItem();
mainMenu->setFocusItem((*std::next(it, mainMenu->rowSize - 1)));
return true;
}
else if (inputEvent.keyCode == KeyCode::KEY_RIGHT) {
case KeyCode::KEY_RIGHT: {
LOG_DEBUG("borderCallback -> Right");
std::list<Item *>::iterator it =
std::find(mainMenu->children.begin(), mainMenu->children.end(), mainMenu->getFocusItem());
mainMenu->setFocusItem((*std::prev(it, mainMenu->col_numb - 1)));
std::list<Item *>::iterator it = mainMenu->getNavigationFocusedItem();
mainMenu->setFocusItem((*std::prev(it, mainMenu->rowSize - 1)));
return true;
}
else {
default: {
return false;
}
}
};
toolsMenu = new MenuPage(
@@ 236,6 234,29 @@ namespace gui
}},
});
toolsMenu->borderCallback = [this](const InputEvent &inputEvent) -> bool {
if (inputEvent.state != InputEvent::State::keyReleasedShort) {
return false;
}
switch (inputEvent.keyCode) {
case KeyCode::KEY_LEFT: {
LOG_DEBUG("borderCallback -> Left");
std::list<Item *>::iterator it = toolsMenu->getNavigationFocusedItem();
toolsMenu->setFocusItem((*std::next(it, toolsMenu->rowSize - 1)));
return true;
}
case KeyCode::KEY_RIGHT: {
LOG_DEBUG("borderCallback -> Right");
std::list<Item *>::iterator it = toolsMenu->getNavigationFocusedItem();
toolsMenu->setFocusItem((*std::prev(it, toolsMenu->rowSize - 1)));
return true;
}
default: {
return false;
}
}
};
using namespace style::window;
mainMenu->setSize(this->area().w - default_left_margin - default_right_margin,
bottomBar->area().pos(Axis::Y) - this->title->getOffset(Axis::Y) -
M => +1 -2
@@ 28,8 28,7 @@ namespace gui
bool first_time_selection = true;
/// position of element which should be selected on start
const unsigned int first_time_selected = 3;
const unsigned int col_numb = 3;
const unsigned int row_numb = 3;
UTF8 title;
MenuPage(gui::Item *parent, UTF8 title, std::vector<Tile *> tiles);
/// set child which should be selected on start of desktop
M module-gui/gui/widgets/BoxLayout.cpp => module-gui/gui/widgets/BoxLayout.cpp +7 -2
@@ 238,8 238,8 @@ namespace gui
template <Axis axis> Position BoxLayout::getAxisAlignmentValue(Position calcPos, Length calcSize, Item *el)
{
auto offset = sizeLeftWithoutElem<axis>(this, el, Area::Normal) <= calcSize
- ? 0
- : sizeLeftWithoutElem<axis>(this, el, Area::Normal) - calcSize;
+ ? 0
+ : sizeLeftWithoutElem<axis>(this, el, Area::Normal) - calcSize;
switch (getAlignment(axis).vertical) {
case gui::Alignment::Vertical::Top:
@@ 382,6 382,11 @@ namespace gui
return true;
}
+ std::list<Item *>::iterator BoxLayout::getNavigationFocusedItem()
+ {
+ return std::find(this->children.begin(), this->children.end(), this->getFocusItem());
+ }
+
HBox::HBox() : BoxLayout()
{
type = ItemType::HBOX;
M module-gui/gui/widgets/BoxLayout.hpp => module-gui/gui/widgets/BoxLayout.hpp +1 -0
@@ 95,6 95,7 @@ namespace gui
// set focus on specified box element
void setFocusOnElement(unsigned int elementNumber);
void setFocusOnLastElement();
+ std::list<Item *>::iterator getNavigationFocusedItem();
template <Axis axis>
auto handleRequestResize(const Item *, unsigned short request_w, unsigned short request_h) -> Size;
auto onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) -> bool override;
M module-gui/gui/widgets/GridLayout.cpp => module-gui/gui/widgets/GridLayout.cpp +14 -19
@@ 14,16 14,17 @@ GridLayout::GridLayout(
void GridLayout::resizeItems()
{
-
if (grid.x == 0 || grid.y == 0) {
LOG_ERROR("Grid == 0 - abort");
return;
}
- uint32_t el_in_x = area().w / grid.x;
- uint32_t el_in_y = area().h / grid.y;
+
+ rowSize = area().w / grid.x;
+ colSize = area().h / grid.y;
+
uint32_t strech_x = 0;
uint32_t strech_y = 0;
- uint32_t max_elements = el_in_x * el_in_y;
+ uint32_t max_elements = rowSize * colSize;
/// cant show elements when size is not set
if (area().w == 0 || area().h == 0) {
return;
@@ 35,10 36,10 @@ void GridLayout::resizeItems()
max_elements);
return;
}
- if (el_in_x > 2)
- strech_x = (area().w - grid.x * el_in_x) / (el_in_x - 1);
- if (el_in_y > 2)
- strech_y = (area().h - grid.y * el_in_y) / (el_in_y - 1);
+ if (rowSize > 2)
+ strech_x = (area().w - grid.x * rowSize) / (rowSize - 1);
+ if (colSize > 2)
+ strech_y = (area().h - grid.y * colSize) / (colSize - 1);
int row = 0;
unsigned int col = 0;
@@ 51,7 52,7 @@ void GridLayout::resizeItems()
row * (grid.y + strech_y) + (grid.y - it->area().h) / 2);
// shift row/col
++col;
- if (col == el_in_x) {
+ if (col == rowSize) {
col = 0;
++row;
}
@@ 61,14 62,8 @@ void GridLayout::resizeItems()
// TODO commomize - move loop to lambda
void GridLayout::setNavigation()
{
- int el_in_x = widgetArea.w / grid.x;
- int el_in_y = widgetArea.h / grid.y;
- int max_elements = el_in_x * el_in_y;
-
- LOG_INFO("max_elements %d", max_elements);
-
int i = 0;
- auto offset = el_in_x;
+ int offset = rowSize;
if (children.size() == 0) {
LOG_ERROR("No children to set navigation");
@@ 76,11 71,11 @@ void GridLayout::setNavigation()
for (auto it = children.begin(); it != children.end(); ++it, ++i) {
- if (it != children.begin() && (i + 1) % el_in_x != 1) {
+ if (it != children.begin() && (i + 1) % rowSize != 1) {
(*it)->setNavigationItem(NavigationDirection::LEFT, nextNavigationItem(std::prev(it)));
}
- if (it != std::prev(children.end()) && (i + 1) % el_in_x != 0) {
+ if (it != std::prev(children.end()) && (i + 1) % rowSize != 0) {
(*it)->setNavigationItem(NavigationDirection::RIGHT, nextNavigationItem(std::next(it)));
}
@@ 95,7 90,7 @@ void GridLayout::setNavigation()
Item *GridLayout::nextNavigationItem(std::list<Item *>::iterator it)
{
- if ((*it)->visible && (*it)->activeItem) {
+ if (it != this->children.end() && (*it)->visible && (*it)->activeItem) {
return *it;
}
else {
M module-gui/gui/widgets/GridLayout.hpp => module-gui/gui/widgets/GridLayout.hpp +4 -2
@@ 15,8 15,6 @@ namespace gui
uint32_t y = 0;
} grid;
- Item *nextNavigationItem(std::list<Item *>::iterator it);
-
public:
GridLayout(
Item *parent, const uint32_t &x, const uint32_t &y, const uint32_t &w, const uint32_t &h, GridSize grid);
@@ 30,6 28,10 @@ namespace gui
bool navigationRotate = true;
void resizeItems() override;
void setNavigation() override;
+ Item *nextNavigationItem(std::list<Item *>::iterator it);
+
+ uint32_t rowSize = 0;
+ uint32_t colSize = 0;
};
}; // namespace gui