EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::ErrorModal Class Referencefinal

Provides a persistent ImGui state to raise errors as a modal. More...

#include <ErrorModal.hpp>

Inheritance diagram for echomap::ErrorModal:
[legend]

Public Member Functions

 ErrorModal (std::string_view message, DismissedCallbackT &&dismissed_callback)
 Raise the modal given a simple unformatted message.
 ErrorModal (std::string_view new_prefix, const std::runtime_error &exception, DismissedCallbackT &&dismissed_callback)
 Raise the modal given a prefix and a detailed exception.
void draw () noexcept override
 Draw the panel to the active rendering context.
const char * get_imgui_name () const noexcept override
 Retrieves the name of the IPanel for Dear ImGui API functions.
Public Member Functions inherited from echomap::IPanel
virtual void update_gpu (const wgpu::CommandEncoder &command_encoder)
 Delegate work to the GPU via the WebGPU platform.

Static Public Member Functions

static const char * get_imgui_stable_name () noexcept

Private Types

using DismissedCallbackT = sigc::slot<void()>

Private Attributes

std::string prefix = "An unknown error occurred."
std::optional< std::stringdetail
std::string panel_name
DismissedCallbackT dismissed_callback

Additional Inherited Members

Static Protected Attributes inherited from echomap::IPanel
static constexpr ImVec2 button_size {80.0f, 20.0f}
static constexpr auto table_flags

Detailed Description

Provides a persistent ImGui state to raise errors as a modal.

Error modals provide a message, an optional detail string derived from an exception, and a single button to dismiss the modal.

Definition at line 26 of file ErrorModal.hpp.

Member Typedef Documentation

◆ DismissedCallbackT

using echomap::ErrorModal::DismissedCallbackT = sigc::slot<void()>
private

Definition at line 28 of file ErrorModal.hpp.

Constructor & Destructor Documentation

◆ ErrorModal() [1/2]

echomap::ErrorModal::ErrorModal ( std::string_view message,
DismissedCallbackT && dismissed_callback )
explicit

Raise the modal given a simple unformatted message.

Parameters
messageThe unformatted string literal to display.
dismissed_callbackCallback to invoke when the ErrorModal is cancelled.

Definition at line 17 of file ErrorModal.cpp.

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}
#define LOG_ERROR(msg)
Logs an unformatted error-level message using echomap::Logger::log.
Definition Logger.hpp:172

◆ ErrorModal() [2/2]

echomap::ErrorModal::ErrorModal ( std::string_view new_prefix,
const std::runtime_error & exception,
DismissedCallbackT && dismissed_callback )

Raise the modal given a prefix and a detailed exception.

Parameters
new_prefixAn unformatted string literal to display as the major text.
exceptionAn exception containing a message to display as the minor text.
dismissed_callbackCallback to invoke when the ErrorModal is cancelled.

Since this routine will often be called from exception handlers, it provides a no-exception guarantee (to prevent program termination). If a low-level system call fails, such as memory allocation to copy the error text, the exception is caught and logged with the system logger; the modal is not raised.

Definition at line 32 of file ErrorModal.cpp.

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}
T what(T... args)

Member Function Documentation

◆ draw()

void echomap::ErrorModal::draw ( )
overridevirtualnoexcept

Draw the panel to the active rendering context.

Implements echomap::IPanel.

Definition at line 49 of file ErrorModal.cpp.

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}
const char * get_imgui_name() const noexcept override
Retrieves the name of the IPanel for Dear ImGui API functions.

◆ get_imgui_name()

const char * echomap::ErrorModal::get_imgui_name ( ) const
nodiscardoverridevirtualnoexcept

Retrieves the name of the IPanel for Dear ImGui API functions.

Returns
The human-readable name of the window as a NULL-terminated C string.

Implements echomap::IPanel.

Definition at line 70 of file ErrorModal.cpp.

71{
72 return panel_name.c_str();
73}

◆ get_imgui_stable_name()

const char * echomap::ErrorModal::get_imgui_stable_name ( )
staticnoexcept

Definition at line 75 of file ErrorModal.cpp.

76{
77 return "###ErrorModal";
78}

Member Data Documentation

◆ detail

std::optional<std::string> echomap::ErrorModal::detail
private

Definition at line 67 of file ErrorModal.hpp.

◆ dismissed_callback

DismissedCallbackT echomap::ErrorModal::dismissed_callback
private

Definition at line 69 of file ErrorModal.hpp.

◆ panel_name

std::string echomap::ErrorModal::panel_name
private

Definition at line 68 of file ErrorModal.hpp.

◆ prefix

std::string echomap::ErrorModal::prefix = "An unknown error occurred."
private

Definition at line 66 of file ErrorModal.hpp.


The documentation for this class was generated from the following files: