Error notifications

This commit is contained in:
Federico Cecchetto 2021-12-20 18:58:23 +01:00
parent 776a39f0b3
commit bedc3c94f8
2 changed files with 41 additions and 35 deletions

View File

@ -20,14 +20,13 @@ namespace gui
namespace
{
utils::concurrency::container<std::vector<std::function<void()>>> on_frame_callbacks;
utils::concurrency::container<std::vector<notification_t>> notifications;
ID3D11Device* device;
ID3D11DeviceContext* device_context;
bool initialized = false;
bool toggled = false;
std::vector<notification_t> notifications;
void initialize_gui_context()
{
ImGui::CreateContext();
@ -62,41 +61,44 @@ namespace gui
void show_notifications()
{
static auto window_flags = ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove;
static auto window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove;
auto index = 0;
for (auto i = notifications.begin(); i != notifications.end(); ++i)
notifications.access([](std::vector<notification_t>& notifications_)
{
const auto now = std::chrono::high_resolution_clock::now();
if (now - i->creation_time >= i->duration)
auto index = 0;
for (auto i = notifications_.begin(); i != notifications_.end(); ++i)
{
notifications.erase(i--);
continue;
const auto now = std::chrono::high_resolution_clock::now();
if (now - i->creation_time >= i->duration)
{
notifications_.erase(i--);
continue;
}
const auto title = i->title.size() <= 34
? i->title
: i->title.substr(0, 31) + "...";
const auto text = i->text.size() <= 34
? i->text
: i->text.substr(0, 31) + "...";
ImGui::SetNextWindowSizeConstraints(ImVec2(250, 50), ImVec2(250, 50));
ImGui::SetNextWindowBgAlpha(0.6f);
ImGui::Begin(utils::string::va("Notification #%i", index), nullptr, window_flags);
ImGui::SetWindowPos(ImVec2(10, 30.f + static_cast<float>(index) * 60.f));
ImGui::SetWindowSize(ImVec2(250, 0));
ImGui::Text(title.data());
ImGui::Text(text.data());
ImGui::End();
index++;
}
const auto title = i->title.size() <= 34
? i->title
: i->title.substr(0, 31) + "...";
const auto text = i->text.size() <= 34
? i->text
: i->text.substr(0, 31) + "...";
ImGui::SetNextWindowSizeConstraints(ImVec2(250, 50), ImVec2(250, 50));
ImGui::SetNextWindowBgAlpha(0.6f);
ImGui::Begin(utils::string::va("Notification #%i", index), nullptr, window_flags);
ImGui::SetWindowPos(ImVec2(10, 30.f + static_cast<float>(index) * 60.f));
ImGui::SetWindowSize(ImVec2(250, 0));
ImGui::Text(title.data());
ImGui::Text(text.data());
ImGui::End();
index++;
}
});
}
void gui_draw()
@ -231,7 +233,10 @@ namespace gui
notification.duration = duration;
notification.creation_time = std::chrono::high_resolution_clock::now();
notifications.insert(notifications.begin(), notification);
notifications.access([notification](std::vector<notification_t>& notifications_)
{
notifications_.insert(notifications_.begin(), notification);
});
}
class component final : public component_interface

View File

@ -466,7 +466,6 @@ namespace entity_list
}
catch (...)
{
}
}
@ -568,6 +567,7 @@ namespace entity_list
}
catch (...)
{
gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data()));
}
});
}
@ -589,6 +589,7 @@ namespace entity_list
}
catch (...)
{
gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data()));
}
});
}