~aleteoryx/muditaos

ref: 6665a43d2b901b89809c4f18338d8ea6c0b08df7 muditaos/module-apps/application-calendar/widgets/MonthBox.cpp -rw-r--r-- 2.8 KiB
6665a43d — Lefucjusz [BH-1780] Fix uncaught std::filesystem::file_size exception 2 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DayLabel.hpp"
#include "MonthBox.hpp"
#include <application-calendar/widgets/CalendarStyle.hpp>
#include <windows/CalendarMainWindow.hpp>

namespace gui
{
    MonthBox::MonthBox(app::ApplicationCommon *app,
                       gui::Item *parent,
                       const int &offsetTop,
                       const uint32_t &width,
                       const uint32_t &height,
                       const uint32_t &dayWidth,
                       const uint32_t &dayHeight,
                       const std::unique_ptr<MonthModel> &model,
                       std::array<bool, 31> &isDayEmpty)
        : GridLayout(parent, style::window::default_left_margin, offsetTop, width, height, {dayWidth, dayHeight})
    {
        assert(parent);
        parent->addWidget(this);
        month            = model->getMonthText();
        monthFilterValue = model->getYear() / model->getMonth();
        grid.x           = dayWidth;
        grid.y           = dayHeight;

        uint32_t firstDayOffset = model->getFirstWeekOffset();
        uint32_t lastDay        = model->getLastDay();
        uint32_t iterations     = style::window::calendar::week_days_number + firstDayOffset + lastDay;

        uint32_t i;
        for (i = 0; i < iterations; ++i) {
            if (i < style::window::calendar::week_days_number + firstDayOffset) {
                auto day = new DayLabel(app,
                                        this,
                                        i,
                                        firstDayOffset,
                                        style::window::calendar::day_cell_width,
                                        style::window::calendar::day_cell_height,
                                        true);
                addWidget(day);
            }
            else {
                auto day = new DayLabel(app,
                                        this,
                                        i,
                                        firstDayOffset,
                                        style::window::calendar::day_cell_width,
                                        style::window::calendar::day_cell_height,
                                        isDayEmpty[i - (style::window::calendar::week_days_number + firstDayOffset)]);
                addWidget(day);
            }
        }
        date::year_month_day actualDate = TimePointToYearMonthDay(TimePointNow());
        if (model->getYear() == actualDate.year() && model->getMonth() == actualDate.month()) {
            focusChangedCallback = [=](Item &item) {
                setFocusOnElement(unsigned(actualDate.day()) - 1);
                return true;
            };
        }
    }
} /* namespace gui */