~aleteoryx/muditaos

ref: 3c69244f4db9f310c328687052326659aad29146 muditaos/module-apps/windows/NoEvents.cpp -rw-r--r-- 2.4 KiB
3c69244f — Przemyslaw Brudny [EGD-6773] Added light BarGraph type and updated UpdateProgress 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NoEvents.hpp"
#include "Dialog.hpp"
#include "DialogMetadataMessage.hpp"
#include "log/log.hpp"

#include <service-appmgr/Controller.hpp>
#include <Image.hpp>

using namespace gui;

namespace style
{
    namespace arrow
    {
        const inline uint32_t x = 30;
        const inline uint32_t y = 62;
    } // namespace arrow

    namespace cross
    {
        const inline uint32_t x = 48;
        const inline uint32_t y = 55;
    } // namespace cross

    namespace icon
    {
        constexpr inline auto x = 176;
        constexpr inline auto y = 195;
    } // namespace icon

    namespace text
    {
        constexpr inline auto x = 40;
        constexpr inline auto y = 333;
    } // namespace text
} // namespace style

NoEvents::NoEvents(app::Application *app, const std::string &name) : gui::Dialog(app, name)
{
    arrow = new gui::Image(this, style::arrow::x, style::arrow::y, 0, 0, "arrow_left");
    cross = new gui::Image(this, style::cross::x, style::cross::y, 0, 0, "cross");
}

void NoEvents::onBeforeShow(ShowMode mode, SwitchData *data)
{
    Dialog::onBeforeShow(mode, data);
    auto metadata = dynamic_cast<DialogMetadataMessage *>(data);
    if (metadata != nullptr) {
        auto foo      = metadata->get().action;
        inputCallback = [foo](Item &, const InputEvent &inputEvent) -> bool {
            if (foo && inputEvent.isShortRelease(KeyCode::KEY_LEFT)) {
                return foo();
            }
            return false;
        };
    }

    if (title->getText() == utils::translate("app_calendar_title_main")) {
        bottomBar->setActive(gui::BottomBar::Side::LEFT, true);
        bottomBar->setText(gui::BottomBar::Side::LEFT, utils::translate("app_calendar_bar_month"));
    }
}

bool NoEvents::onInput(const gui::InputEvent &inputEvent)
{
    if (inputEvent.isShortRelease(gui::KeyCode::KEY_RF) &&
        title->getText() == utils::translate("app_calendar_title_main")) {
        app::manager::Controller::switchBack(application);
        return true;
    }

    if (AppWindow::onInput(inputEvent)) {
        return true;
    }

    if (inputEvent.isShortRelease(gui::KeyCode::KEY_LF) &&
        title->getText() == utils::translate("app_calendar_title_main")) {
        application->switchWindow(gui::name::window::main_window);
        return true;
    }

    return false;
}