~aleteoryx/muditaos

10714ca71dad1e64e531191f88eea58a0ce3fc68 — Pawel.Paprocki 4 years ago 028804e
[BH-501] MainMenu

Add Bell main menu window and option menu
M image/assets/lang/English.json => image/assets/lang/English.json +6 -0
@@ 567,6 567,12 @@
  "app_desktop_update_ready_for_reset": "Ready for reset...",
  "app_desktop_update_success": "MuditaOS has been updated to ver. $VERSION succesfully.",
  "app_call_private_number": "Private number",
  "app_bellmain_next_alarm": "Next alarm",
  "app_bellmain_power_nap": "Power nap",
  "app_bellmain_meditation_timer": "Meditation timer",
  "app_bellmain_media_library": "Media Library",
  "app_bellmain_settings": "Settings",
  "app_bellmain_main_window_title": "Bell Hybrid+",
  "tethering": "Tethering",
  "tethering_turn_off_question": "Turn tethering off?",
  "tethering_enable_question": "<text>You're connected to the computer.<br />Turn tethering on?<br /><text color='9'>(some functions may be disabled)</text></text>",

M module-apps/application-bell-main/ApplicationBellMain.cpp => module-apps/application-bell-main/ApplicationBellMain.cpp +11 -0
@@ 3,6 3,8 @@

#include "ApplicationBellMain.hpp"
#include "windows/BellMainWindow.hpp"
#include "windows/BellMainMenuWindow.hpp"
#include <windows/Dialog.hpp>

namespace app
{


@@ 30,6 32,15 @@ namespace app
        windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) {
            return std::make_unique<gui::BellMainWindow>(app);
        });

        windowsFactory.attach(gui::window::name::bell_main_menu, [](Application *app, const std::string &name) {
            return std::make_unique<gui::BellMainMenuWindow>(app);
        });

        // for demo only - to be removed
        windowsFactory.attach(gui::window::name::bell_main_menu_dialog, [](Application *app, const std::string &name) {
            return std::make_unique<gui::Dialog>(app, name);
        });
    }

    sys::MessagePointer ApplicationBellMain::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)

M module-apps/application-bell-main/ApplicationBellMain.hpp => module-apps/application-bell-main/ApplicationBellMain.hpp +7 -0
@@ 5,6 5,13 @@

#include <Application.hpp>

namespace gui::window::name
{
    inline constexpr auto bell_main_menu        = "BellMainMenu";
    inline constexpr auto bell_main_menu_dialog = "BellMainMenuDialog";

} // namespace gui::window::name

namespace app
{
    inline constexpr auto applicationBellName = "ApplicationBell";

M module-apps/application-bell-main/CMakeLists.txt => module-apps/application-bell-main/CMakeLists.txt +6 -0
@@ 4,4 4,10 @@ target_sources(application-bell-main
    INTERFACE
        ApplicationBellMain.cpp
        windows/BellMainWindow.cpp
        windows/BellMainMenuWindow.cpp
)

target_link_libraries(${PROJECT_NAME}
     PRIVATE
        bellgui
)

A module-apps/application-bell-main/data/BellMainStyle.hpp => module-apps/application-bell-main/data/BellMainStyle.hpp +15 -0
@@ 0,0 1,15 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

namespace bellMainStyle
{
    namespace mainMenuWindow
    {
        inline constexpr gui::Length options_list_x     = 40;
        inline constexpr gui::Length options_list_y     = 85;
        inline constexpr gui::Length default_body_width = 400;
    } // namespace mainMenuWindow

} // namespace bellMainStyle

A module-apps/application-bell-main/windows/BellMainMenuWindow.cpp => module-apps/application-bell-main/windows/BellMainMenuWindow.cpp +84 -0
@@ 0,0 1,84 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BellMainMenuWindow.hpp"
#include <OptionBellMenu.hpp>
#include <service-appmgr/Controller.hpp>
#include <application-bell-main/ApplicationBellMain.hpp>
#include <windows/Dialog.hpp>
#include <DialogMetadataMessage.hpp>
#include <application-bell-main/data/BellMainStyle.hpp>

namespace gui
{

    BellMainMenuWindow::BellMainMenuWindow(app::Application *app) : OptionWindow(app, gui::window::name::bell_main_menu)
    {
        addOptions(mainMenuOptionsList());
        buildInterface();
    }

    void BellMainMenuWindow::buildInterface()
    {
        bottomBar->setVisible(false);
        statusBar->setVisible(false);
        title->visible = false;
        optionsList->setPosition(bellMainStyle::mainMenuWindow::options_list_x,
                                 bellMainStyle::mainMenuWindow::options_list_y);
        optionsList->setMaximumWidth(bellMainStyle::mainMenuWindow::default_body_width);
        optionsList->setBoundaries(listview::Boundaries::Continuous);
    }

    std::list<Option> BellMainMenuWindow::mainMenuOptionsList()
    {
        std::list<gui::Option> menuOptionList;
        auto addWinMenu = [&](const UTF8 &name, const std::string &window) {
            menuOptionList.emplace_back(std::make_unique<gui::option::OptionBellMenu>(
                name,
                [=](gui::Item &item) {
                    if (window.empty()) {
                        return false;
                    }
                    application->switchWindow(
                        window,
                        gui::ShowMode::GUI_SHOW_INIT,
                        std::make_unique<gui::DialogMetadataMessage>(gui::DialogMetadata{name, "search_big", " "}));
                    return true;
                },
                [=](gui::Item &item) {
                    // put focus change callback here
                    return true;
                },
                this));
        };

        auto addAppMenu = [&](const UTF8 &name, const std::string &appName) {
            menuOptionList.emplace_back(std::make_unique<gui::option::OptionBellMenu>(
                name,
                [=](gui::Item &item) {
                    if (appName.empty()) {
                        return false;
                    }
                    return app::manager::Controller::sendAction(application,
                                                                app::manager::actions::Launch,
                                                                std::make_unique<app::ApplicationLaunchData>(appName));
                },
                [=](gui::Item &item) {
                    // put focus change callback here
                    return true;
                },
                this));
        };

        addAppMenu(utils::translate("app_bellmain_next_alarm"), "");

        // for demo only - to be replaced by call o final window
        addWinMenu(utils::translate("app_bellmain_power_nap"), gui::window::name::bell_main_menu_dialog);
        addWinMenu(utils::translate("app_bellmain_meditation_timer"), gui::window::name::bell_main_menu_dialog);
        addWinMenu(utils::translate("app_bellmain_media_library"), gui::window::name::bell_main_menu_dialog);
        addWinMenu(utils::translate("app_bellmain_settings"), gui::window::name::bell_main_menu_dialog);

        return menuOptionList;
    }

} // namespace gui

A module-apps/application-bell-main/windows/BellMainMenuWindow.hpp => module-apps/application-bell-main/windows/BellMainMenuWindow.hpp +21 -0
@@ 0,0 1,21 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <OptionWindow.hpp>

namespace gui
{

    class BellMainMenuWindow : public OptionWindow
    {
      public:
        BellMainMenuWindow(app::Application *app);

      private:
        std::list<Option> mainMenuOptionsList();
        void buildInterface() override;
    };

} // namespace gui

M module-apps/application-bell-main/windows/BellMainWindow.cpp => module-apps/application-bell-main/windows/BellMainWindow.cpp +24 -1
@@ 3,6 3,10 @@

#include "BellMainWindow.hpp"
#include <i18n/i18n.hpp>
#include <log/log.hpp>
#include <service-appmgr/Controller.hpp>
#include <gui/input/InputEvent.hpp>
#include <application-bell-main/ApplicationBellMain.hpp>

namespace gui
{


@@ 17,7 21,26 @@ namespace gui

        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setText(gui::BottomBar::Side::CENTER, utils::translate(style::strings::common::start));
        setTitle(utils::translate("app_bellmain_main_window_title"));
    }

    bool BellMainWindow::onInput(const InputEvent &inputEvent)
    {
        if (inputEvent.isShortRelease()) {
            switch (inputEvent.getKeyCode()) {
            case KeyCode::KEY_ENTER:
                LOG_INFO("Open MainMenu");
                application->switchWindow(gui::window::name::bell_main_menu, nullptr);
                return true;
            case KeyCode::KEY_RF:
                return true;
            default:
                break;
            }
        }

        setTitle("Bell Hybrid+");
        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
    }

} // namespace gui

M module-apps/application-bell-main/windows/BellMainWindow.hpp => module-apps/application-bell-main/windows/BellMainWindow.hpp +1 -0
@@ 13,5 13,6 @@ namespace gui
        explicit BellMainWindow(app::Application *app);

        void buildInterface() override;
        bool onInput(const InputEvent &inputEvent) override;
    };
} // namespace gui

M module-apps/apps-common/CMakeLists.txt => module-apps/apps-common/CMakeLists.txt +18 -1
@@ 100,4 100,21 @@ target_compile_options(apps-common
        $<$<COMPILE_LANGUAGE:CXX>:-fno-non-call-exceptions>
        $<$<COMPILE_LANGUAGE:CXX>:-Wno-literal-suffix>

)
\ No newline at end of file
)

# Bell Hybrid related libs
add_library(bellgui)
target_sources( bellgui
   PRIVATE
      ${CMAKE_CURRENT_SOURCE_DIR}/options/type/OptionBellMenu.cpp
      ${CMAKE_CURRENT_SOURCE_DIR}/options/type/OptionBellMenu.hpp
)
target_include_directories( bellgui
   PUBLIC
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/options/type>
)

target_link_libraries( bellgui
   PRIVATE
      module-gui
)

M module-apps/apps-common/options/OptionStyle.hpp => module-apps/apps-common/options/OptionStyle.hpp +7 -0
@@ 49,4 49,11 @@ namespace gui::option
        inline constexpr uint32_t optionsListH                = style::window::default_body_height;
    } // namespace window

    namespace bell::window
    {
        inline constexpr gui::Length option_bottom_margin = 9;
        inline constexpr gui::Length option_left_margin   = 10;
        inline constexpr gui::Length default_text_width   = 400;
    } // namespace bell::window

} // namespace gui::option

A module-apps/apps-common/options/type/OptionBellMenu.cpp => module-apps/apps-common/options/type/OptionBellMenu.cpp +39 -0
@@ 0,0 1,39 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <TextFixedSize.hpp>
#include "OptionBellMenu.hpp"

namespace gui::option
{
    auto OptionBellMenu::build() const -> ListItem *
    {
        auto optionItem = new gui::ListItem();
        optionItem->setMinimumSize(bell::window::default_text_width, style::window::label::big_h);
        optionItem->setMargins(Margins(0, 0, 0, bell::window::option_bottom_margin));
        optionItem->setAlignment(gui::Alignment::Horizontal::Center);
        optionItem->activatedCallback    = activatedCallback;
        optionItem->focusChangedCallback = focusChangedCallback;

        auto optionBodyHBox = new HBox(optionItem, 0, 0, 0, 0);
        optionBodyHBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
        style::window::decorate(optionBodyHBox);

        optionItem->dimensionChangedCallback = [optionBodyHBox](gui::Item &, const BoundingBox &newDim) -> bool {
            optionBodyHBox->setPosition(0, 0);
            optionBodyHBox->setSize(newDim.w, newDim.h);
            return true;
        };

        auto optionText = new TextFixedSize(optionBodyHBox, 0, 0, 0, 0);
        optionText->setUnderline(false);
        optionText->setAlignment(gui::Alignment::Vertical::Center);
        optionText->setAlignment(gui::Alignment::Horizontal::Center);
        optionText->setMaximumSize(bell::window::default_text_width, style::window::label::big_h);
        optionText->setMargins(Margins(bell::window::option_left_margin, 0, 0, 0));
        optionText->setFont(style::window::font::largelight);
        optionText->setRichText(text);

        return optionItem;
    }
} // namespace gui::option

A module-apps/apps-common/options/type/OptionBellMenu.hpp => module-apps/apps-common/options/type/OptionBellMenu.hpp +32 -0
@@ 0,0 1,32 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "OptionWindow.hpp"

namespace gui::option
{
    class OptionBellMenu : public option::Base
    {
      private:
        UTF8 text;
        std::function<bool(Item &)> activatedCallback    = nullptr;
        std::function<bool(Item &)> focusChangedCallback = nullptr;
        AppWindow *app                                   = nullptr;

      public:
        OptionBellMenu(const UTF8 &text,
                       std::function<bool(Item &)> activatedCallback,
                       std::function<bool(Item &)> focusChangedCallback,
                       AppWindow *app)
            : text(std::move(text)), activatedCallback(std::move(activatedCallback)),
              focusChangedCallback(std::move(focusChangedCallback)), app(app)
        {}
        [[nodiscard]] auto build() const -> ListItem * override;
        [[nodiscard]] auto str() const -> std::string override
        {
            return text;
        }
    };
} // namespace gui::option