summaryrefslogtreecommitdiff
path: root/src/ui/modal.cpp
blob: 88f6d3effebfc5deb4da4a5c062f7748bf2dbd1e (plain)
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

/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#include "modal.hpp"

#include "misc/lv_color.h"

#include "core/lv_event.h"
#include "esp_log.h"

#include "core/lv_group.h"
#include "core/lv_obj_pos.h"
#include "event_queue.hpp"
#include "extra/widgets/list/lv_list.h"
#include "extra/widgets/menu/lv_menu.h"
#include "extra/widgets/spinner/lv_spinner.h"
#include "hal/lv_hal_disp.h"
#include "index.hpp"
#include "misc/lv_area.h"
#include "screen.hpp"
#include "themes.hpp"
#include "ui_events.hpp"
#include "ui_fsm.hpp"
#include "widgets/lv_label.h"

namespace ui {

Modal::Modal(Screen* host)
    : root_(lv_obj_create(host->modal_content())),
      group_(lv_group_create()),
      host_(host) {
  lv_obj_set_style_bg_opa(host->modal_content(), LV_OPA_40, 0);

  lv_obj_set_size(root_, 120, LV_SIZE_CONTENT);
  lv_obj_center(root_);

  lv_obj_set_style_bg_opa(root_, LV_OPA_COVER, 0);
  lv_obj_set_style_bg_color(root_, lv_color_white(), 0);

  themes::Theme::instance()->ApplyStyle(root_, themes::Style::kPopup);

  host_->modal_group(group_);
}

Modal::~Modal() {
  host_->modal_group(nullptr);
  lv_obj_set_style_bg_opa(host_->modal_content(), LV_OPA_TRANSP, 0);

  // The group *must* be deleted first. Otherwise, focus events will be
  // generated whilst deleting the object tree, which causes a big mess.
  lv_group_del(group_);
  lv_obj_del(root_);
}

}  // namespace ui