From a0914b534c3584f4b21e260e5571a05a5ea79d67 Mon Sep 17 00:00:00 2001 From: Wojciech Rzepecki Date: Thu, 25 Nov 2021 13:05:19 +0100 Subject: [PATCH] [EGD-5374] Fix call gui issues fixed state icons to use box layout plus string and allignement fixes --- .../application-call/data/CallAppStyle.hpp | 22 ++------ .../application-call/widgets/StateIcon.hpp | 56 ++++++------------- .../application-call/widgets/StateIcons.cpp | 14 ++--- .../application-call/widgets/StateIcons.hpp | 8 +-- .../application-call/windows/CallWindow.cpp | 53 +++++++----------- .../application-call/windows/CallWindow.hpp | 1 + .../windows/EnterNumberWindow.cpp | 9 ++- module-gui/gui/widgets/ImageBoxWithText.cpp | 6 +- module-gui/gui/widgets/ImageBoxWithText.hpp | 4 +- 9 files changed, 69 insertions(+), 104 deletions(-) diff --git a/module-apps/application-call/data/CallAppStyle.hpp b/module-apps/application-call/data/CallAppStyle.hpp index 67b23a0f707f803efeb31550d37f6e5bf1e9e0cd..3d339f91a52da0de8871b947ce8d23fa8cfdb0d8 100644 --- a/module-apps/application-call/data/CallAppStyle.hpp +++ b/module-apps/application-call/data/CallAppStyle.hpp @@ -54,11 +54,11 @@ namespace callAppStyle // ENTER NUMBER WINDOW namespace enterNumberWindow { - namespace newContactIcon + namespace iconsBox { - inline constexpr auto x = 190U - icon::x_margin; inline constexpr auto y = 411U; - } // namespace newContactIcon + inline constexpr auto h = 100U; + } // namespace iconsBox } // namespace enterNumberWindow // CALL WINDOW @@ -83,20 +83,10 @@ namespace callAppStyle inline constexpr auto w = 240U; inline constexpr auto h = 20U; } // namespace durationLabel - namespace speakerIcon + namespace iconsBox { - inline constexpr auto x = 260U - icon::x_margin; inline constexpr auto y = 411U; - } // namespace speakerIcon - namespace microphoneIcon - { - inline constexpr auto x = 120U - icon::x_margin; - inline constexpr auto y = 411U; - } // namespace microphoneIcon - namespace sendMessageIcon - { - inline constexpr auto x = 190U - icon::x_margin; - inline constexpr auto y = 411U; - } // namespace sendMessageIcon + inline constexpr auto h = 100U; + } // namespace iconsBox } // namespace callWindow } // namespace callAppStyle diff --git a/module-apps/application-call/widgets/StateIcon.hpp b/module-apps/application-call/widgets/StateIcon.hpp index 0d7a6350c27ad8298e12a0f8321d628b8c854204..53dbaf66957eeead6886dc0a3421e5125c0e4e00 100644 --- a/module-apps/application-call/widgets/StateIcon.hpp +++ b/module-apps/application-call/widgets/StateIcon.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -17,19 +18,7 @@ namespace gui { constexpr uint32_t w = 100; constexpr uint32_t h = 100; - - namespace label - { - constexpr uint32_t x = 0; - constexpr uint32_t y = 58; - constexpr uint32_t w = icon::w; - constexpr uint32_t h = 22; - } // namespace label - namespace img - { - constexpr uint32_t x = 34; - constexpr uint32_t y = 15; - } // namespace img + constexpr uint32_t defaultSideMargin = 20; } // namespace icon /// @brief Icon widget with custom predefined images and strings @@ -40,29 +29,19 @@ namespace gui /// icon::h where w = icon::w + 2 * w_margin. It is necessary as it is possible that text will exceed Icon visible /// area - template class StateIcon : public Rect + template class StateIcon : public ImageBoxWithText { public: using IconMap = std::map>; StateIcon() = delete; - StateIcon( - Item *parent, const uint32_t &x, const uint32_t &y, const uint32_t &w_margin, T state, const IconMap &data) - : Rect(parent, x, y, icon::w + 2 * w_margin, icon::h), data(data) + StateIcon(Item *parent, T state, const IconMap &data) + : ImageBoxWithText(parent, + new gui::Image(data.at(state).first, ImageTypeSpecifier::W_M), + utils::translate(data.at(state).second)), + state(state), data(data) { - setEdges(RectangleEdge::None); - setPenFocusWidth(style::window::default_border_no_focus_w); - setPenWidth(style::window::default_border_no_focus_w); - boundingRect = new Rect(this, w_margin, 0, icon::w, icon::h); - boundingRect->setEdges(RectangleEdge::Bottom | RectangleEdge::Top); - boundingRect->setPenFocusWidth(style::window::default_border_focus_w); - boundingRect->setPenWidth(style::window::default_border_no_focus_w); - - img = new gui::Image(boundingRect, icon::img::x, icon::img::y, 0, 0); - label = new gui::Label(this, icon::label::x, icon::label::y, icon::label::w + 2 * w_margin, icon::label::h); - label->setEdges(RectangleEdge::None); - label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); - label->setFont(style::window::font::verysmall); - + setSize(icon::w, icon::h); + setMargins({icon::defaultSideMargin, 0, icon::defaultSideMargin, 0}); set(state); } @@ -75,10 +54,13 @@ namespace gui virtual void set(const T &state) { this->state = state; - img->set(data.at(state).first, ImageTypeSpecifier::W_M); - label->setText(utils::translate(data.at(state).second)); - using namespace style::window; - label->setFont(data.find(state) != data.begin() ? font::verysmallbold : font::verysmall); + image->set(data.at(state).first, ImageTypeSpecifier::W_M); + + text->setFont(data.find(state) != data.begin() ? imageBoxWithText::fontBold : imageBoxWithText::font); + text->setText(utils::translate(data.at(state).second)); + text->setMinimumWidthToFitText(utils::translate(data.at(state).second)); + text->setMinimumHeightToFitText(); + text->informContentChanged(); } T get() const @@ -103,15 +85,11 @@ namespace gui bool onFocus(bool state) override { Item::onFocus(state); - setFocusItem(state ? boundingRect : nullptr); return true; } protected: - Image *img = nullptr; - Label *label = nullptr; - Rect *boundingRect = nullptr; T state; const IconMap data; // internal map with predefined sets of images and strings to be displayed }; diff --git a/module-apps/application-call/widgets/StateIcons.cpp b/module-apps/application-call/widgets/StateIcons.cpp index a5168bf6e06cde667097c52951b54a1bc44fc09f..f642dd70de85b3dace834c707f2c76a12dd9d0b4 100644 --- a/module-apps/application-call/widgets/StateIcons.cpp +++ b/module-apps/application-call/widgets/StateIcons.cpp @@ -19,7 +19,7 @@ namespace gui constexpr auto speakerImg = "call_speaker"; constexpr auto speakerOnImg = "call_speaker_on"; constexpr auto speakerStr = "app_call_speaker"; - constexpr auto speakerOnStr = "app_call_speaker_on"; + constexpr auto speakerOnStr = "app_call_speaker"; const StateIcon::IconMap contactIconMap = { {AddContactIconState::ADD_CONTACT, {crossImg, addContactStr}}}; @@ -32,20 +32,16 @@ namespace gui {SpeakerIconState::SPEAKERON, {speakerOnImg, speakerOnStr}}}; } // namespace - AddContactIcon::AddContactIcon(Item *parent, std::uint32_t x, std::uint32_t y) - : StateIcon(parent, x, y, callAppStyle::icon::x_margin, AddContactIconState::ADD_CONTACT, contactIconMap) + AddContactIcon::AddContactIcon(Item *parent) : StateIcon(parent, AddContactIconState::ADD_CONTACT, contactIconMap) {} - SendSmsIcon::SendSmsIcon(Item *parent, std::uint32_t x, std::uint32_t y) - : StateIcon(parent, x, y, callAppStyle::icon::x_margin, SendSmsIconState::SEND_SMS, smsIconMap) + SendSmsIcon::SendSmsIcon(Item *parent) : StateIcon(parent, SendSmsIconState::SEND_SMS, smsIconMap) {} - MicrophoneIcon::MicrophoneIcon(Item *parent, std::uint32_t x, std::uint32_t y) - : StateIcon(parent, x, y, callAppStyle::icon::x_margin, MicrophoneIconState::MUTE, microphoneIconMap) + MicrophoneIcon::MicrophoneIcon(Item *parent) : StateIcon(parent, MicrophoneIconState::MUTE, microphoneIconMap) {} - SpeakerIcon::SpeakerIcon(Item *parent, std::uint32_t x, std::uint32_t y) - : StateIcon(parent, x, y, callAppStyle::icon::x_margin, SpeakerIconState::SPEAKER, speakerIconMap) + SpeakerIcon::SpeakerIcon(Item *parent) : StateIcon(parent, SpeakerIconState::SPEAKER, speakerIconMap) {} } // namespace gui diff --git a/module-apps/application-call/widgets/StateIcons.hpp b/module-apps/application-call/widgets/StateIcons.hpp index 7922ecb155aa4043b2b278175cfadba54ad4e03c..84b82d802fed29b66860d675bc27145393da0f4f 100644 --- a/module-apps/application-call/widgets/StateIcons.hpp +++ b/module-apps/application-call/widgets/StateIcons.hpp @@ -18,7 +18,7 @@ namespace gui { public: AddContactIcon() = delete; - AddContactIcon(Item *parent, std::uint32_t x, std::uint32_t y); + AddContactIcon(Item *parent); }; enum class SendSmsIconState @@ -29,7 +29,7 @@ namespace gui { public: SendSmsIcon() = delete; - SendSmsIcon(Item *parent, std::uint32_t x, std::uint32_t y); + SendSmsIcon(Item *parent); }; enum class MicrophoneIconState @@ -42,7 +42,7 @@ namespace gui { public: MicrophoneIcon() = delete; - MicrophoneIcon(Item *parent, std::uint32_t x, std::uint32_t y); + MicrophoneIcon(Item *parent); }; enum class SpeakerIconState @@ -55,6 +55,6 @@ namespace gui { public: SpeakerIcon() = delete; - SpeakerIcon(Item *parent, std::uint32_t x, std::uint32_t y); + SpeakerIcon(Item *parent); }; } // namespace gui diff --git a/module-apps/application-call/windows/CallWindow.cpp b/module-apps/application-call/windows/CallWindow.cpp index 925fc5ed0efc6a6c85780660faf20f1052569dd4..09c822596f60ae77c0fe1a401a77524b0e12ed01 100644 --- a/module-apps/application-call/windows/CallWindow.cpp +++ b/module-apps/application-call/windows/CallWindow.cpp @@ -76,15 +76,25 @@ namespace gui numberLabel->setFont(style::window::font::largelight); numberLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); - speakerIcon = new SpeakerIcon(this, speakerIcon::x, speakerIcon::y); - speakerIcon->focusChangedCallback = [=](gui::Item &item) { - LOG_DEBUG("speakerIcon get/lost focus"); - navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::Switch), item.focus); + iconsBox = new HBox( + this, style::window::default_left_margin, iconsBox::y, style::window::default_body_width, iconsBox::h); + iconsBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + iconsBox->setEdges(RectangleEdge::None); + + microphoneIcon = new MicrophoneIcon(iconsBox); + microphoneIcon->activatedCallback = [=](gui::Item &item) { + microphoneIcon->setNext(); + LOG_INFO("Mic activated %d", static_cast(microphoneIcon->get())); + + microphoneIcon->get() == MicrophoneIconState::MUTED ? interface->sendAudioEvent(AudioEvent::Mute) + : interface->sendAudioEvent(AudioEvent::Unmute); + return true; }; + + speakerIcon = new SpeakerIcon(iconsBox); speakerIcon->activatedCallback = [=](gui::Item &item) { speakerIcon->setNext(); - application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); LOG_INFO("Speaker activated %d", static_cast(speakerIcon->get())); switch (speakerIcon->get()) { @@ -104,29 +114,7 @@ namespace gui return true; }; - microphoneIcon = new MicrophoneIcon(this, microphoneIcon::x, microphoneIcon::y); - microphoneIcon->focusChangedCallback = [=](gui::Item &item) { - LOG_DEBUG("microphoneIcon get/lost focus"); - navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::Switch), item.focus); - return true; - }; - microphoneIcon->activatedCallback = [=](gui::Item &item) { - microphoneIcon->setNext(); - application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); - LOG_INFO("Mic activated %d", static_cast(microphoneIcon->get())); - - microphoneIcon->get() == MicrophoneIconState::MUTED ? interface->sendAudioEvent(AudioEvent::Mute) - : interface->sendAudioEvent(AudioEvent::Unmute); - - return true; - }; - - sendSmsIcon = new gui::SendSmsIcon(this, sendMessageIcon::x, sendMessageIcon::y); - sendSmsIcon->focusChangedCallback = [=](gui::Item &item) { - LOG_DEBUG("Send message get/lost focus"); - navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::send), item.focus); - return true; - }; + sendSmsIcon = new gui::SendSmsIcon(iconsBox); sendSmsIcon->activatedCallback = [=](gui::Item &item) { LOG_INFO("Send message template and reject the call"); constexpr auto preventAutoLock = true; @@ -180,6 +168,7 @@ namespace gui } else { navBar->setActive(gui::nav_bar::Side::Center, true); + navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::send), true); sendSmsIcon->setVisible(true); setFocusItem(sendSmsIcon); } @@ -208,20 +197,19 @@ namespace gui navBar->setActive(gui::nav_bar::Side::Left, false); navBar->setActive(gui::nav_bar::Side::Center, false); navBar->setText(gui::nav_bar::Side::Right, utils::translate(strings::endcall), true); + navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::Switch), true); durationLabel->setVisible(true); sendSmsIcon->setVisible(false); speakerIcon->setVisible(true); microphoneIcon->setVisible(true); - auto focusItem = getFocusItem(); - if (focusItem != microphoneIcon || focusItem != speakerIcon) { - setFocusItem(microphoneIcon); - } + setFocusItem(microphoneIcon); } break; case State::OUTGOING_CALL: { interface->startAudioRouting(); navBar->setActive(gui::nav_bar::Side::Left, false); navBar->setActive(gui::nav_bar::Side::Center, false); navBar->setText(gui::nav_bar::Side::Right, utils::translate(strings::endcall), true); + navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::Switch), true); durationLabel->setText(utils::translate(strings::calling)); durationLabel->setVisible(true); sendSmsIcon->setVisible(false); @@ -244,6 +232,7 @@ namespace gui setFocusItem(nullptr); break; }; + iconsBox->resizeItems(); } auto CallWindow::getState() const noexcept -> State diff --git a/module-apps/application-call/windows/CallWindow.hpp b/module-apps/application-call/windows/CallWindow.hpp index 1e90a5d644c31a389c29557ab282a0c59fd02cac..d53487b7fe1be034ba04a134734633760660b0e2 100644 --- a/module-apps/application-call/windows/CallWindow.hpp +++ b/module-apps/application-call/windows/CallWindow.hpp @@ -44,6 +44,7 @@ namespace gui // used to inform user about call state of call and display duration of call gui::Label *durationLabel = nullptr; + gui::HBox *iconsBox = nullptr; gui::SendSmsIcon *sendSmsIcon = nullptr; gui::MicrophoneIcon *microphoneIcon = nullptr; gui::SpeakerIcon *speakerIcon = nullptr; diff --git a/module-apps/application-call/windows/EnterNumberWindow.cpp b/module-apps/application-call/windows/EnterNumberWindow.cpp index 6c3feb677e1441ac7ea8a0f60621baaac4b50ad9..26b0fea84dfa7c4223a20239a4c65a002a3ab543 100644 --- a/module-apps/application-call/windows/EnterNumberWindow.cpp +++ b/module-apps/application-call/windows/EnterNumberWindow.cpp @@ -35,9 +35,16 @@ namespace gui navBar->setText(nav_bar::Side::Center, utils::translate("common_add")); navBar->setText(nav_bar::Side::Right, utils::translate("app_call_clear")); - newContactIcon = new gui::AddContactIcon(this, newContactIcon::x, newContactIcon::y); + auto iconsBox = new HBox( + this, style::window::default_left_margin, iconsBox::y, style::window::default_body_width, iconsBox::h); + iconsBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + iconsBox->setEdges(RectangleEdge::None); + + newContactIcon = new gui::AddContactIcon(iconsBox); newContactIcon->activatedCallback = [=](gui::Item &item) { return addNewContact(); }; setFocusItem(newContactIcon); + + iconsBox->resizeItems(); } status_bar::Configuration EnterNumberWindow::configureStatusBar(status_bar::Configuration appConfiguration) diff --git a/module-gui/gui/widgets/ImageBoxWithText.cpp b/module-gui/gui/widgets/ImageBoxWithText.cpp index 918e47ad997cac820f5537d5eb8cff86618ae143..4b3487f64c2fdceedc07ec26d73fc6cfb645bc26 100644 --- a/module-gui/gui/widgets/ImageBoxWithText.cpp +++ b/module-gui/gui/widgets/ImageBoxWithText.cpp @@ -37,16 +37,18 @@ void ImageBoxWithText::setText(const UTF8 &description) { text = new TextFixedSize(this); text->drawUnderline(false); - text->setMargins(Margins(0, imageBoxWithText::text_margin, 0, imageBoxWithText::text_margin)); + text->setMargins(Margins(0, imageBoxWithText::text_margin_top, 0, imageBoxWithText::text_margin_bottom)); text->setFont(imageBoxWithText::font); text->setText(description); text->setMinimumWidthToFitText(description); text->setMinimumHeightToFitText(); + text->setAlignment(Alignment::Horizontal::Center); + text->activeItem = false; } void ImageBoxWithText::setMinimumSizeToFitImage() { auto minW = std::max(image->getWidth(), text->widgetMinimumArea.w); - auto minH = image->getHeight() + imageBoxWithText::text_margin + text->widgetMinimumArea.h; + auto minH = image->getHeight() + imageBoxWithText::text_margin_top + text->widgetMinimumArea.h; setMinimumSize(minW, minH); } diff --git a/module-gui/gui/widgets/ImageBoxWithText.hpp b/module-gui/gui/widgets/ImageBoxWithText.hpp index adec034d8f7b942c177a9541dabe0578cbc08882..e1268282addfda034c51d8f16f6982c9bac88ca3 100644 --- a/module-gui/gui/widgets/ImageBoxWithText.hpp +++ b/module-gui/gui/widgets/ImageBoxWithText.hpp @@ -12,8 +12,10 @@ namespace gui namespace imageBoxWithText { inline constexpr auto wh = 100; - inline constexpr auto text_margin = 5; + inline constexpr auto text_margin_top = 11; + inline constexpr auto text_margin_bottom = 5; inline constexpr auto font = style::window::font::verysmall; + inline constexpr auto fontBold = style::window::font::verysmallbold; } // namespace imageBoxWithText class ImageBoxWithText : public ImageBox