mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
add missing error handling to gui_util::* functions
This commit is contained in:
parent
73837082c2
commit
ea64560b5d
1 changed files with 31 additions and 11 deletions
|
|
@ -12,6 +12,9 @@
|
||||||
#include "gui_xml.hpp"
|
#include "gui_xml.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
#include "debug/Logger.hpp"
|
||||||
|
|
||||||
|
debug::Logger logger("gui-util");
|
||||||
|
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
|
|
@ -25,6 +28,20 @@ std::shared_ptr<gui::UINode> guiutil::create(
|
||||||
return reader.readXML("[string]", source);
|
return reader.readXML("[string]", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool notify_callback(const runnable& callback, std::string_view name) {
|
||||||
|
if (callback == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
callback();
|
||||||
|
return true;
|
||||||
|
} catch (std::exception& err) {
|
||||||
|
logger.error()
|
||||||
|
<< "exception thrown in " << name << ": " << err.what();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void guiutil::alert(
|
void guiutil::alert(
|
||||||
Engine& engine, const std::wstring& text, const runnable& on_hidden
|
Engine& engine, const std::wstring& text, const runnable& on_hidden
|
||||||
) {
|
) {
|
||||||
|
|
@ -47,9 +64,7 @@ void guiutil::alert(
|
||||||
auto& menu = *menuPtr;
|
auto& menu = *menuPtr;
|
||||||
runnable on_hidden_final = [on_hidden, &menu]() {
|
runnable on_hidden_final = [on_hidden, &menu]() {
|
||||||
menu.removePage("<alert>");
|
menu.removePage("<alert>");
|
||||||
if (on_hidden) {
|
if (!notify_callback(on_hidden, "on_hidden") && !menu.back()) {
|
||||||
on_hidden();
|
|
||||||
} else if (!menu.back()) {
|
|
||||||
menu.reset();
|
menu.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -119,18 +134,16 @@ void guiutil::confirm(
|
||||||
|
|
||||||
runnable on_confirm_final = [on_confirm, menu]() {
|
runnable on_confirm_final = [on_confirm, menu]() {
|
||||||
menu->removePage("<confirm>");
|
menu->removePage("<confirm>");
|
||||||
if (on_confirm) {
|
|
||||||
on_confirm();
|
if (!notify_callback(on_confirm, "on_confirm") && !menu->back()) {
|
||||||
} else if (!menu->back()) {
|
|
||||||
menu->reset();
|
menu->reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
runnable on_deny_final = [on_deny, menu]() {
|
runnable on_deny_final = [on_deny, menu]() {
|
||||||
menu->removePage("<confirm>");
|
menu->removePage("<confirm>");
|
||||||
if (on_deny) {
|
|
||||||
on_deny();
|
if (!notify_callback(on_deny, "on_deny") && !menu->back()) {
|
||||||
} else if (!menu->back()) {
|
|
||||||
menu->reset();
|
menu->reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -189,9 +202,16 @@ void guiutil::confirm_with_memo(
|
||||||
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
||||||
subpanel->setColor(glm::vec4(0));
|
subpanel->setColor(glm::vec4(0));
|
||||||
|
|
||||||
|
runnable on_confirm_final = [on_confirm, menu]() {
|
||||||
|
menu->removePage("<confirm>");
|
||||||
|
|
||||||
|
if (!notify_callback(on_confirm, "on_confirm") && !menu->back()) {
|
||||||
|
menu->reset();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
subpanel->add(std::make_shared<Button>(gui, yestext, glm::vec4(8.f), [=](GUI&) {
|
subpanel->add(std::make_shared<Button>(gui, yestext, glm::vec4(8.f), [=](GUI&) {
|
||||||
if (on_confirm) on_confirm();
|
on_confirm_final();
|
||||||
menu->back();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
subpanel->add(std::make_shared<Button>(gui, notext, glm::vec4(8.f), [=](GUI&) {
|
subpanel->add(std::make_shared<Button>(gui, notext, glm::vec4(8.f), [=](GUI&) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue