fix: FlashDialog and popups

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 5a9fdb4eb5
commit 12ef9ced2d
7 changed files with 88 additions and 53 deletions
+1
View File
@@ -161,6 +161,7 @@ add_definitions(-DLIBOPENUI)
add_gui_src(fullscreen_dialog.cpp)
add_gui_src(message_dialog.cpp)
add_gui_src(confirm_dialog.cpp)
add_gui_src(popups.cpp)
add_gui_src(timeedit.cpp)
add_gui_src(curve.cpp)
add_gui_src(sourcechoice.cpp)
+14
View File
@@ -332,6 +332,12 @@ LvglWrapper::LvglWrapper()
window->setActiveScreen();
}
LvglWrapper* LvglWrapper::instance()
{
if (!_instance) _instance = new LvglWrapper();
return _instance;
}
void LvglWrapper::run()
{
#if defined(SIMU)
@@ -341,3 +347,11 @@ void LvglWrapper::run()
#endif
lv_timer_handler();
}
void LvglWrapper::pollInputs()
{
lv_indev_t* indev = nullptr;
while((indev = lv_indev_get_next(indev)) != nullptr) {
lv_indev_read_timer_cb(indev->driver->read_timer);
}
}
+10 -13
View File
@@ -61,22 +61,19 @@ class LvglWidgetFactory
bool styleInitialized;
};
class LvglWrapper {
public:
class LvglWrapper
{
public:
static LvglWrapper* instance();
void run();
void pollInputs();
private:
LvglWrapper();
~LvglWrapper() {}
static LvglWrapper* instance()
{
if (!_instance)
_instance = new LvglWrapper();
return _instance;
}
void run();
private:
static LvglWrapper* _instance;
static LvglWrapper *_instance;
tmr10ms_t lastTick = 0;
};
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "popups.h"
#include "libopenui.h"
static MessageDialog * createPopupInformation(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Message", message);
}
static MessageDialog * createPopupWarning(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Warning", message);
}
void POPUP_INFORMATION(const char * message)
{
auto popup = createPopupInformation(message);
while (popup->getParent()) {
WDG_RESET();
lv_refr_now(nullptr);
LvglWrapper::instance()->pollInputs();
RTOS_WAIT_MS(20);
}
}
void POPUP_WARNING(const char * message, const char * info)
{
auto popup = createPopupWarning(message);
if (info) {
popup->setInfoText(std::string(info));
}
while (popup->getParent()) {
WDG_RESET();
lv_refr_now(nullptr);
LvglWrapper::instance()->pollInputs();
RTOS_WAIT_MS(20);
}
}
+3 -37
View File
@@ -19,45 +19,11 @@
* GNU General Public License for more details.
*/
#ifndef _POPUPS_H_
#define _POPUPS_H_
#pragma once
#include "libopenui.h"
#include <functional>
typedef std::function<void(const char *, const char *, int, int)> ProgressHandler;
inline MessageDialog * createPopupInformation(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Message", message);
}
inline MessageDialog * createPopupWarning(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Warning", message);
}
inline void POPUP_INFORMATION(const char * message)
{
auto popup = createPopupInformation(message);
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
inline void POPUP_WARNING(const char * message, const char * info = nullptr)
{
auto popup = createPopupWarning(message);
if (info) {
popup->setInfoText(std::string(info));
}
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
#endif // _POPUPS_H_
void POPUP_INFORMATION(const char * message);
void POPUP_WARNING(const char * message, const char * info = nullptr);
+1 -2
View File
@@ -138,8 +138,7 @@ class FlashDialog: public FullScreenDialog
int total) -> void {
setMessage(message);
progress.setValue(total > 0 ? count * 100 / total : 0);
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
lv_refr_now(nullptr);
});
deleteLater();
}