Cleanup of Notes.cpp (#282)
This commit is contained in:
parent
2691dbb014
commit
ce96474d84
@ -15,14 +15,9 @@ constexpr const char* TAG = "Notes";
|
|||||||
|
|
||||||
class NotesApp : public App {
|
class NotesApp : public App {
|
||||||
|
|
||||||
AppContext* appContext = nullptr;
|
|
||||||
|
|
||||||
lv_obj_t* uiCurrentFileName;
|
lv_obj_t* uiCurrentFileName;
|
||||||
lv_obj_t* uiDropDownMenu;
|
lv_obj_t* uiDropDownMenu;
|
||||||
lv_obj_t* uiNoteText;
|
lv_obj_t* uiNoteText;
|
||||||
lv_obj_t* uiMessageBox;
|
|
||||||
lv_obj_t* uiMessageBoxButtonOk;
|
|
||||||
lv_obj_t* uiMessageBoxButtonNo;
|
|
||||||
|
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
std::string saveBuffer;
|
std::string saveBuffer;
|
||||||
@ -36,12 +31,6 @@ class NotesApp : public App {
|
|||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
lv_obj_t* obj = lv_event_get_target_obj(e);
|
lv_obj_t* obj = lv_event_get_target_obj(e);
|
||||||
|
|
||||||
if (code == LV_EVENT_CLICKED) {
|
|
||||||
if (obj == uiMessageBoxButtonOk || obj == uiMessageBoxButtonNo) {
|
|
||||||
lv_obj_del(uiMessageBox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||||
if (obj == uiDropDownMenu) {
|
if (obj == uiDropDownMenu) {
|
||||||
switch (lv_dropdown_get_selected(obj)) {
|
switch (lv_dropdown_get_selected(obj)) {
|
||||||
@ -77,7 +66,6 @@ class NotesApp : public App {
|
|||||||
} else { //Reset
|
} else { //Reset
|
||||||
resetFileContent();
|
resetFileContent();
|
||||||
}
|
}
|
||||||
lv_obj_delete(uiMessageBox);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,68 +77,6 @@ class NotesApp : public App {
|
|||||||
lv_label_set_text(uiCurrentFileName, "Untitled");
|
lv_label_set_text(uiCurrentFileName, "Untitled");
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiMessageBoxShow(std::string title, std::string message, bool isSelectable) {
|
|
||||||
uiMessageBox = lv_obj_create(lv_scr_act());
|
|
||||||
lv_obj_set_size(uiMessageBox, lv_display_get_horizontal_resolution(nullptr), lv_display_get_vertical_resolution(nullptr));
|
|
||||||
lv_obj_align(uiMessageBox, LV_ALIGN_TOP_MID, 0, 0);
|
|
||||||
lv_obj_remove_flag(uiMessageBox, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
lv_obj_t* uiMessageBoxTitle = lv_label_create(uiMessageBox);
|
|
||||||
lv_label_set_text(uiMessageBoxTitle, title.c_str());
|
|
||||||
lv_obj_set_size(uiMessageBoxTitle, lv_display_get_horizontal_resolution(nullptr) - 30, 30);
|
|
||||||
lv_obj_align(uiMessageBoxTitle, LV_ALIGN_TOP_MID, 0, 0);
|
|
||||||
|
|
||||||
lv_obj_t* messageLabel = lv_label_create(uiMessageBox);
|
|
||||||
lv_obj_align(messageLabel, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
lv_obj_set_width(messageLabel, LV_PCT(80));
|
|
||||||
lv_obj_set_style_text_align(messageLabel, LV_TEXT_ALIGN_CENTER, 0);
|
|
||||||
lv_label_set_text(messageLabel, message.c_str());
|
|
||||||
lv_label_set_long_mode(messageLabel, LV_LABEL_LONG_WRAP);
|
|
||||||
|
|
||||||
lv_obj_t* buttonWrapper = lv_obj_create(uiMessageBox);
|
|
||||||
lv_obj_set_flex_flow(buttonWrapper, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_size(buttonWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
|
||||||
lv_obj_set_style_pad_all(buttonWrapper, 0, 0);
|
|
||||||
lv_obj_set_flex_align(buttonWrapper, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_set_style_border_width(buttonWrapper, 0, 0);
|
|
||||||
lv_obj_align(buttonWrapper, LV_ALIGN_BOTTOM_MID, 0, 5);
|
|
||||||
|
|
||||||
if (isSelectable == true) {
|
|
||||||
lv_obj_t* buttonYes = lv_button_create(buttonWrapper);
|
|
||||||
lv_obj_t* buttonLabelYes = lv_label_create(buttonYes);
|
|
||||||
lv_obj_align(buttonLabelYes, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
|
||||||
lv_label_set_text(buttonLabelYes, "Yes");
|
|
||||||
lv_obj_add_event_cb(buttonYes, [](lv_event_t* e) {
|
|
||||||
auto *self = static_cast<NotesApp *>(lv_event_get_user_data(e));
|
|
||||||
self->appNotesEventCb(e); }, LV_EVENT_CLICKED, this);
|
|
||||||
|
|
||||||
uiMessageBoxButtonNo = lv_button_create(buttonWrapper);
|
|
||||||
lv_obj_t* buttonLabelNo = lv_label_create(uiMessageBoxButtonNo);
|
|
||||||
lv_obj_align(buttonLabelNo, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
|
|
||||||
lv_label_set_text(buttonLabelNo, "No");
|
|
||||||
lv_obj_add_event_cb(uiMessageBoxButtonNo, [](lv_event_t* e) {
|
|
||||||
auto *self = static_cast<NotesApp *>(lv_event_get_user_data(e));
|
|
||||||
self->appNotesEventCb(e); }, LV_EVENT_CLICKED, this);
|
|
||||||
} else {
|
|
||||||
uiMessageBoxButtonOk = lv_button_create(buttonWrapper);
|
|
||||||
lv_obj_t* buttonLabelOk = lv_label_create(uiMessageBoxButtonOk);
|
|
||||||
lv_obj_align(buttonLabelOk, LV_ALIGN_BOTTOM_MID, 0, 0);
|
|
||||||
lv_label_set_text(buttonLabelOk, "Ok");
|
|
||||||
lv_obj_add_event_cb(uiMessageBoxButtonOk,
|
|
||||||
[](lv_event_t* e) {
|
|
||||||
auto *self = static_cast<NotesApp *>(lv_event_get_user_data(e));
|
|
||||||
self->appNotesEventCb(e);
|
|
||||||
},
|
|
||||||
LV_EVENT_CLICKED,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!filePath.empty()) {
|
|
||||||
openFile(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region Open_Events_Functions
|
#pragma region Open_Events_Functions
|
||||||
|
|
||||||
void openFile(const std::string& path) {
|
void openFile(const std::string& path) {
|
||||||
@ -184,8 +110,6 @@ class NotesApp : public App {
|
|||||||
#pragma endregion Open_Events_Functions
|
#pragma endregion Open_Events_Functions
|
||||||
|
|
||||||
void onShow(AppContext& context, lv_obj_t* parent) override {
|
void onShow(AppContext& context, lv_obj_t* parent) override {
|
||||||
appContext = &context;
|
|
||||||
|
|
||||||
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user