Skip to content

Commit

Permalink
make errors display in UI like warnings, fix positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Jan 5, 2025
1 parent b103e7f commit edb6a36
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ void buildErrorUI(std::string message, bool fatal) {
ImVec2 errorTextSize = ImGui::CalcTextSize(message.c_str());
ImVec2 errorModalSize(std::max(view::windowWidth / 5.0f, std::min(errorTextSize.x + 50, view::windowWidth / 2.0f)),
0);
ImVec2 errorModalPos((view::windowWidth - errorModalSize.x) / 2, view::windowHeight / 3);

ImGui::SetNextWindowSize(errorModalSize);
ImGui::SetNextWindowPos(errorModalPos, ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImVec4(170. / 255., 0, 0, 1.0));
if (ImGui::BeginPopupModal(errorPopupString.c_str(), NULL, ImGuiWindowFlags_NoMove)) {

Expand Down Expand Up @@ -212,6 +214,12 @@ void error(std::string message) {
std::cout << options::printPrefix << "[ERROR] " << message << std::endl;
}

// Enter a modal UI loop showing the error
if (options::displayMessagePopups && !isHeadless()) {
auto func = std::bind(buildErrorUI, message, false);
pushContext(func, false);
}

if (options::errorsThrowExceptions) {
throw std::logic_error(options::printPrefix + message);
}
Expand Down

0 comments on commit edb6a36

Please sign in to comment.