EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
ErrorModal.cpp
Go to the documentation of this file.
1
7
8#include "ErrorModal.hpp"
9
10#include <imgui.h>
11
12#include "../utility/Logger.hpp"
13
14namespace echomap
15{
16
18 const std::string_view message,
19 DismissedCallbackT&& dismissed_callback
20) :
21 panel_name(std::string("Error!") + get_imgui_stable_name()),
22 dismissed_callback(std::move(dismissed_callback))
23{
24 try {
25 prefix = message;
26 } catch (const std::exception&) {
27 LOG_ERROR("Could not allocate memory to display modal on UI.");
28 return;
29 }
30}
31
33 const std::string_view new_prefix,
34 const std::runtime_error& exception,
35 DismissedCallbackT&& dismissed_callback
36) :
37 panel_name(std::string("Error!") + get_imgui_stable_name()),
38 dismissed_callback(std::move(dismissed_callback))
39{
40 try {
41 detail = exception.what();
42 prefix = new_prefix;
43 } catch (const std::exception&) {
44 LOG_ERROR("Could not allocate memory to display modal on UI.");
45 return;
46 }
47}
48
49void ErrorModal::draw() noexcept
50{
51 ImGui::OpenPopup(get_imgui_name());
52 if (ImGui::BeginPopupModal(get_imgui_name(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
53 ImGui::TextUnformatted(prefix.c_str());
54 ImGui::Separator();
55
56 if (detail.has_value()) {
57 ImGui::TextWrapped("%s", detail->c_str());
58 ImGui::Separator();
59 }
60
61 if (ImGui::Button("Dismiss", button_size)) {
62 ImGui::CloseCurrentPopup();
63 dismissed_callback();
64 }
65
66 ImGui::EndPopup();
67 }
68}
69
70const char* ErrorModal::get_imgui_name() const noexcept
71{
72 return panel_name.c_str();
73}
74
75const char* ErrorModal::get_imgui_stable_name() noexcept
76{
77 return "###ErrorModal";
78}
79
80} // namespace echomap
EchoMap modal error panel specification.
EchoMap portable logger specification.
#define LOG_ERROR(msg)
Logs an unformatted error-level message using echomap::Logger::log.
Definition Logger.hpp:172
void draw() noexcept override
Draw the panel to the active rendering context.
ErrorModal(std::string_view message, DismissedCallbackT &&dismissed_callback)
Raise the modal given a simple unformatted message.
const char * get_imgui_name() const noexcept override
Retrieves the name of the IPanel for Dear ImGui API functions.
The main EchoMap outermost namespace for all non-exported symbols.
STL namespace.
T what(T... args)