From 9fb8432b410a2161e93f34c08d220420e338c52c Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Tue, 31 Jan 2023 14:34:18 +0100 Subject: [PATCH] [MOS-592] Fix right arrow behavior in search field Fix of the issue that clicking right arrow in search field caused the focus to be moved to image on the right, what made inputting text impossible. Additionally minor code cleanup. --- .../windows/PhonebookSearch.cpp | 6 +-- module-apps/apps-common/widgets/InputBox.cpp | 17 +++++---- module-apps/apps-common/windows/AppWindow.cpp | 7 ++-- module-gui/gui/widgets/BoxLayout.cpp | 31 ++++++++------- module-gui/gui/widgets/Item.cpp | 38 ++++++++++++------- pure_changelog.md | 5 ++- 6 files changed, 60 insertions(+), 44 deletions(-) diff --git a/module-apps/application-phonebook/windows/PhonebookSearch.cpp b/module-apps/application-phonebook/windows/PhonebookSearch.cpp index 62f7c85381d641f52fe12c13d541bc1fce5ce951..512856da43481cef4b9f5e1512b4351b1cd5b405 100644 --- a/module-apps/application-phonebook/windows/PhonebookSearch.cpp +++ b/module-apps/application-phonebook/windows/PhonebookSearch.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "PhonebookSearch.hpp" @@ -48,12 +48,12 @@ namespace gui return false; } - std::string searchFilter = utils::trim(inputField->getText()); + const auto searchFilter = utils::trim(inputField->getText()); if (searchFilter.empty()) { return false; } - auto app = dynamic_cast(application); + const auto app = dynamic_cast(application); if (app == nullptr) { LOG_ERROR("Failed to get phonebook application."); return false; diff --git a/module-apps/apps-common/widgets/InputBox.cpp b/module-apps/apps-common/widgets/InputBox.cpp index a70159cbfea2cdf9eb6bab1b2294eb7592162483..4c35ca711f0154fc46a77509fe5c6b8d2e65b271 100644 --- a/module-apps/apps-common/widgets/InputBox.cpp +++ b/module-apps/apps-common/widgets/InputBox.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "InputBox.hpp" @@ -30,13 +30,13 @@ namespace gui input_Box::h); verticalBox->setEdges(RectangleEdge::None); - auto l = new Label(verticalBox); - l->setMinimumHeight(input_Box::label_h); - l->setMaximumWidth(style::window::default_body_width); - l->setFont(style::window::font::small); - l->setEdges(RectangleEdge::None); - l->setText(header); - l->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Bottom)); + auto label = new Label(verticalBox); + label->setMinimumHeight(input_Box::label_h); + label->setMaximumWidth(style::window::default_body_width); + label->setFont(style::window::font::small); + label->setEdges(RectangleEdge::None); + label->setText(header); + label->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Bottom)); auto horizontalBox = new HBox(verticalBox); horizontalBox->setAlignment({gui::Alignment::Vertical::Top}); @@ -60,6 +60,7 @@ namespace gui if (!icon.empty()) { auto imageBox = new ImageBox(horizontalBox, new Image(icon)); imageBox->setMinimumSizeToFitImage(); + imageBox->activeItem = false; // Prevent switching focus to the image } verticalBox->resizeItems(); diff --git a/module-apps/apps-common/windows/AppWindow.cpp b/module-apps/apps-common/windows/AppWindow.cpp index e2a131c20c59d76675132c931d04c8f80588f354..772889b3503bb62427cac28ebcff23146960a45a 100644 --- a/module-apps/apps-common/windows/AppWindow.cpp +++ b/module-apps/apps-common/windows/AppWindow.cpp @@ -9,14 +9,13 @@ #include #include #include -#include using namespace style::header; namespace gui { - AppWindow::AppWindow(app::ApplicationCommon *app, std::string name) : Window(name), application{app} + AppWindow::AppWindow(app::ApplicationCommon *app, std::string name) : Window(std::move(name)), application{app} { setSize(style::window_width, style::window_height); } @@ -126,7 +125,7 @@ namespace gui void AppWindow::updatePhoneMode(sys::phone_modes::PhoneMode mode) { auto fn = [&](gui::status_bar::Configuration cfg) -> gui::status_bar::Configuration { - gui::status_bar::Configuration ret(cfg); + gui::status_bar::Configuration ret(std::move(cfg)); ret.setPhoneMode(mode); return ret; }; @@ -190,7 +189,7 @@ namespace gui } } - if ((inputEvent.isShortRelease())) { + if (inputEvent.isShortRelease()) { switch (inputEvent.getKeyCode()) { case KeyCode::HEADSET_VOLUP: [[fallthrough]]; diff --git a/module-gui/gui/widgets/BoxLayout.cpp b/module-gui/gui/widgets/BoxLayout.cpp index 736e712aebe1fa05ebc9ee1f80e78293b5ca966e..5d734a033a8dbdde2da003208e414e141d4d12ba 100644 --- a/module-gui/gui/widgets/BoxLayout.cpp +++ b/module-gui/gui/widgets/BoxLayout.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "BoxLayout.hpp" @@ -41,10 +41,13 @@ namespace gui bool BoxLayout::onFocus(bool state) { - if (state) + if (state) { this->setVisible(state); - else + } + else { this->setFocusItem(nullptr); + } + this->setNavigation(); if (this->focusChangedCallback && state != focus) { this->focusChangedCallback(*this); @@ -78,7 +81,7 @@ namespace gui bool BoxLayout::removeWidget(Item *item) { - bool ret = Rect::removeWidget(item); + const auto ret = Rect::removeWidget(item); outOfDrawAreaItems.remove(item); resizeItems(); @@ -109,7 +112,7 @@ namespace gui void BoxLayout::setVisible(bool value, bool previous) { visible = value; // maybe use parent setVisible(...)? would be better but which one? - if (value == true) { + if (value) { resizeItems(); // move items in box in proper places setNavigation(); // set navigation through kids -> TODO handle out of last/first to parent if (children.size()) { // set first visible kid as focused item - TODO should check for actionItems too... @@ -189,7 +192,7 @@ namespace gui void BoxLayout::addFromOutOfDrawAreaList() { - if (children.size() != 0) { + if (!children.empty()) { for (auto it : outOfDrawAreaItems) { it->setVisible(true); it->setFocusItem(nullptr); @@ -212,8 +215,9 @@ namespace gui for (auto &el : children) { - if (!el->visible) + if (!el->visible) { continue; + } auto axisItemPosition = 0; auto orthogonalItemPosition = 0; @@ -237,8 +241,9 @@ namespace gui orthogonalItemPosition = calculateElemOrtAxisPosition(el, orthogonalItemSize); // 6. If element still visible (not added to outOfDrawAreaList) set it Area with calculated values. - if (el->visible) + if (el->visible) { el->setAreaInAxis(axis, axisItemPosition, orthogonalItemPosition, axisItemSize, orthogonalItemSize); + } } Rect::updateDrawArea(); @@ -293,14 +298,14 @@ namespace gui Length BoxLayout::calculateElemOrtAxisSize(Item *el) { // Get maximum size that element in orthogonal axis can occupy in current layout size. - Length maxOrthogonalItemInParentSize = + const Length maxOrthogonalItemInParentSize = static_cast(this->area(Area::Normal).size(orthogonal(axis))) <= el->getMargins().getSumInAxis(orthogonal(axis)) ? 0 : this->area(Area::Normal).size(orthogonal(axis)) - el->getMargins().getSumInAxis(orthogonal(axis)); // Get maximum size of element in orthogonal axis based on its min-max. - Length maxOrthogonalItemSize = + const Length maxOrthogonalItemSize = el->area(Area::Max).size(orthogonal(axis)) > el->area(Area::Min).size(orthogonal(axis)) ? el->area(Area::Max).size(orthogonal(axis)) : el->area(Area::Min).size(orthogonal(axis)); @@ -318,7 +323,7 @@ namespace gui auto axisItemPosition = 0; // Check if elements in axis can fit with margins in layout free space. - if (((Position)(axisItemSize + el->getMargins().getSumInAxis(axis))) <= leftPosition) { + if (static_cast(axisItemSize + el->getMargins().getSumInAxis(axis)) <= leftPosition) { if (reverseOrder) { startingPosition -= el->getMargins().getMarginInAxis(axis, MarginInAxis::Second); @@ -464,8 +469,8 @@ namespace gui { if (parent != nullptr) { auto [w, h] = requestSize(request_w, request_h); - request_w = std::min(w, (Length)request_w); - request_h = std::min(h, (Length)request_h); + request_w = std::min(w, static_cast(request_w)); + request_h = std::min(h, static_cast(request_h)); } auto el = std::find(children.begin(), children.end(), child); diff --git a/module-gui/gui/widgets/Item.cpp b/module-gui/gui/widgets/Item.cpp index d507ae066073045e48be213cccfd983828ddcb85..797fbe84de7d588ce42bf0eb60c71fc554ccec39 100644 --- a/module-gui/gui/widgets/Item.cpp +++ b/module-gui/gui/widgets/Item.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Item.hpp" @@ -47,11 +47,13 @@ namespace gui Item::~Item() { - for (auto &widget : children) + for (auto &widget : children) { delete widget; + } - if (navigationDirections) + if (navigationDirections) { delete navigationDirections; + } } bool Item::erase(Item *item) @@ -72,8 +74,9 @@ namespace gui void Item::addWidget(Item *item) { - if (item == nullptr) + if (item == nullptr) { return; + } if (item->parent) { item->parent->removeWidget(item); } @@ -85,8 +88,9 @@ namespace gui bool Item::removeWidget(Item *item) { - if (item == nullptr) + if (item == nullptr) { return false; + } if (item == focusItem) { focusItem = nullptr; } @@ -358,11 +362,13 @@ namespace gui { auto tempAlignment = getAlignment(axis); - if (parent->getAlignment(axis).vertical != Alignment::Vertical::None) + if (parent->getAlignment(axis).vertical != Alignment::Vertical::None) { tempAlignment.vertical = parent->getAlignment(axis).vertical; + } - if (parent->getAlignment(axis).horizontal != Alignment::Horizontal::None) + if (parent->getAlignment(axis).horizontal != Alignment::Horizontal::None) { tempAlignment.horizontal = parent->getAlignment(axis).horizontal; + } switch (tempAlignment.vertical) { case gui::Alignment::Vertical::Top: @@ -414,7 +420,7 @@ namespace gui result.x += parentItem->widgetArea.x; result.y += parentItem->widgetArea.y; BoundingBox newResult; - if (BoundingBox::intersect(parentItem->widgetArea, result, newResult) == false) { + if (!BoundingBox::intersect(parentItem->widgetArea, result, newResult)) { result.clear(); break; } @@ -425,8 +431,9 @@ namespace gui drawArea = result; - for (gui::Item *it : children) + for (const auto &it : children) { it->updateDrawArea(); + } } Item *Item::getNavigationItem(NavigationDirection direction) @@ -439,8 +446,9 @@ namespace gui void Item::setNavigationItem(gui::NavigationDirection direction, Item *item) { - if (navigationDirections == nullptr) + if (navigationDirections == nullptr) { navigationDirections = new Navigation(); + } navigationDirections->setDirectionItem(direction, item); } @@ -475,8 +483,9 @@ namespace gui if (state != focus) { focus = state; onFocus(state); - if (focusChangedCallback) + if (focusChangedCallback) { focusChangedCallback(*this); + } }; return state; } @@ -502,15 +511,16 @@ namespace gui return nullptr; } - bool Item::onFocus(bool state) + bool Item::onFocus([[maybe_unused]] bool state) { return true; } - bool Item::onActivated(void *data) + bool Item::onActivated([[maybe_unused]] void *data) { - if (activatedCallback) + if (activatedCallback) { return activatedCallback(*this); + } return false; } diff --git a/pure_changelog.md b/pure_changelog.md index f91ff7409acd39614dd36db0df06160eacaa9c12..99a3f3557ec7f9da5a2dd4fae7db0e7e1e8fad90 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -45,9 +45,10 @@ * Fixed broken French translation on 'Configure passcode' screen in Onboarding * Fixed time disappearing in SMS thread * Fixed scrollbar behavior in call log view -* Fixed contacts imported from SIM do not show up in Mudita Center +* Fixed contacts imported from SIM not showing up in Mudita Center * Fixed broken events counter on main screen for more than 99 events -* Fixed for incorrect signal strength displayed in Center +* Fixed incorrect signal strength displayed in Center +* Fixed inability to enter text in search field after clicking right arrow ### Added