parent
079b2b53d4
commit
3b3bc64d19
@ -0,0 +1,37 @@ |
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
|
||||
#include "core/lv_group.h" |
||||
#include "core/lv_obj.h" |
||||
#include "core/lv_obj_tree.h" |
||||
#include "lvgl.h" |
||||
#include "widget_top_bar.hpp" |
||||
|
||||
#include "screen.hpp" |
||||
|
||||
namespace ui { |
||||
|
||||
class Modal { |
||||
public: |
||||
Modal(Screen* host); |
||||
virtual ~Modal(); |
||||
|
||||
auto root() -> lv_obj_t* { return root_; } |
||||
auto group() -> lv_group_t* { return group_; } |
||||
|
||||
protected: |
||||
lv_obj_t* const root_; |
||||
lv_group_t* const group_; |
||||
|
||||
private: |
||||
Screen* host_; |
||||
}; |
||||
|
||||
} // namespace ui
|
@ -0,0 +1,29 @@ |
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
#include <vector> |
||||
|
||||
#include "index.hpp" |
||||
#include "lvgl.h" |
||||
|
||||
#include "modal.hpp" |
||||
|
||||
namespace ui { |
||||
namespace modals { |
||||
|
||||
class Confirm : public Modal { |
||||
public: |
||||
Confirm(Screen*, const std::string& title, bool has_cancel); |
||||
|
||||
private: |
||||
lv_obj_t* container_; |
||||
}; |
||||
|
||||
} // namespace modals
|
||||
} // namespace ui
|
@ -0,0 +1,29 @@ |
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
#include <vector> |
||||
|
||||
#include "index.hpp" |
||||
#include "lvgl.h" |
||||
|
||||
#include "modal.hpp" |
||||
|
||||
namespace ui { |
||||
namespace modals { |
||||
|
||||
class Progress : public Modal { |
||||
public: |
||||
Progress(Screen*, std::string title); |
||||
|
||||
private: |
||||
lv_obj_t* container_; |
||||
}; |
||||
|
||||
} // namespace modals
|
||||
} // namespace ui
|
@ -0,0 +1,57 @@ |
||||
|
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#include "misc/lv_color.h" |
||||
#include "modal_progress.hpp" |
||||
|
||||
#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 "ui_events.hpp" |
||||
#include "ui_fsm.hpp" |
||||
#include "widget_top_bar.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_style_bg_color(host->modal_content(), lv_color_black(), 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); |
||||
|
||||
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
|
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#include "modal_confirm.hpp" |
||||
|
||||
#include "core/lv_event.h" |
||||
#include "core/lv_obj.h" |
||||
#include "core/lv_obj_tree.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 "ui_events.hpp" |
||||
#include "ui_fsm.hpp" |
||||
#include "widget_top_bar.hpp" |
||||
#include "widgets/lv_btn.h" |
||||
#include "widgets/lv_label.h" |
||||
|
||||
namespace ui { |
||||
namespace modals { |
||||
|
||||
static void button_cancel_cb(lv_event_t* e) { |
||||
events::Ui().Dispatch(internal::ModalCancelPressed{}); |
||||
} |
||||
|
||||
static void button_confirm_cb(lv_event_t* e) { |
||||
events::Ui().Dispatch(internal::ModalConfirmPressed{}); |
||||
} |
||||
|
||||
Confirm::Confirm(Screen* host, const std::string& title_text, bool has_cancel) |
||||
: Modal(host) { |
||||
lv_obj_set_layout(root_, LV_LAYOUT_FLEX); |
||||
lv_obj_set_flex_flow(root_, LV_FLEX_FLOW_COLUMN); |
||||
lv_obj_set_flex_align(root_, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, |
||||
LV_FLEX_ALIGN_CENTER); |
||||
|
||||
lv_obj_t* title = lv_label_create(root_); |
||||
lv_label_set_text(title, title_text.c_str()); |
||||
lv_obj_set_size(title, LV_SIZE_CONTENT, LV_SIZE_CONTENT); |
||||
|
||||
lv_obj_t* button_container = lv_obj_create(root_); |
||||
lv_obj_set_size(button_container, lv_pct(100), LV_SIZE_CONTENT); |
||||
lv_obj_set_layout(button_container, LV_LAYOUT_FLEX); |
||||
lv_obj_set_flex_flow(button_container, LV_FLEX_FLOW_ROW); |
||||
lv_obj_set_flex_align(button_container, LV_FLEX_ALIGN_SPACE_EVENLY, |
||||
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); |
||||
|
||||
if (has_cancel) { |
||||
lv_obj_t* cancel_btn = lv_btn_create(button_container); |
||||
lv_obj_t* cancel_label = lv_label_create(cancel_btn); |
||||
lv_label_set_text(cancel_label, "Cancel"); |
||||
lv_group_add_obj(group_, cancel_btn); |
||||
lv_obj_add_event_cb(cancel_btn, button_cancel_cb, LV_EVENT_CLICKED, NULL); |
||||
} |
||||
|
||||
lv_obj_t* ok_btn = lv_btn_create(button_container); |
||||
lv_obj_t* ok_label = lv_label_create(ok_btn); |
||||
lv_label_set_text(ok_label, "Okay"); |
||||
lv_group_add_obj(group_, ok_btn); |
||||
lv_obj_add_event_cb(ok_btn, button_confirm_cb, LV_EVENT_CLICKED, NULL); |
||||
} |
||||
|
||||
} // namespace modals
|
||||
} // namespace ui
|
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* Copyright 2023 jacqueline <me@jacqueline.id.au> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#include "modal_progress.hpp" |
||||
|
||||
#include "core/lv_event.h" |
||||
#include "core/lv_obj.h" |
||||
#include "core/lv_obj_tree.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 "ui_events.hpp" |
||||
#include "ui_fsm.hpp" |
||||
#include "widget_top_bar.hpp" |
||||
#include "widgets/lv_label.h" |
||||
|
||||
namespace ui { |
||||
namespace modals { |
||||
|
||||
Progress::Progress(Screen* host, std::string title_text) : Modal(host) { |
||||
lv_obj_set_layout(root_, LV_LAYOUT_FLEX); |
||||
lv_obj_set_flex_flow(root_, LV_FLEX_FLOW_COLUMN); |
||||
lv_obj_set_flex_align(root_, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, |
||||
LV_FLEX_ALIGN_CENTER); |
||||
|
||||
lv_obj_t* title = lv_label_create(root_); |
||||
lv_label_set_text(title, title_text.c_str()); |
||||
lv_obj_set_size(title, LV_SIZE_CONTENT, LV_SIZE_CONTENT); |
||||
|
||||
lv_obj_t* spinner = lv_spinner_create(root_, 3000, 45); |
||||
lv_obj_set_size(spinner, 16, 16); |
||||
} |
||||
|
||||
} // namespace modals
|
||||
} // namespace ui
|
Loading…
Reference in new issue