feat: Added basic toast popups

This commit is contained in:
WerWolv
2023-12-19 23:21:20 +01:00
parent a6025e72fb
commit 2b5789631f
7 changed files with 183 additions and 3 deletions

View File

@@ -39,6 +39,7 @@
#include <fonts/codicons_font.h>
#include <GLFW/glfw3.h>
#include <hex/ui/toast.hpp>
namespace hex {
@@ -753,6 +754,45 @@ namespace hex {
}
}
// Draw Toasts
{
static std::unique_ptr<impl::ToastBase> currToast;
if (currToast == nullptr) {
if (auto &queuedToasts = impl::ToastBase::getQueuedToasts(); !queuedToasts.empty()) {
currToast = std::move(queuedToasts.front());
queuedToasts.pop_front();
currToast->setAppearTime(ImGui::GetTime());
}
} else {
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5_scaled);
ImGui::SetNextWindowSize(scaled({ 280, 60 }));
ImGui::SetNextWindowPos((ImHexApi::System::getMainWindowPosition() + ImHexApi::System::getMainWindowSize()) - scaled({ 10, 10 }), ImGuiCond_Always, ImVec2(1, 1));
if (ImGui::Begin("##Toast", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs)) {
auto drawList = ImGui::GetWindowDrawList();
const auto min = ImGui::GetWindowPos();
const auto max = min + ImGui::GetWindowSize();
drawList->PushClipRect(min, min + scaled({ 5, 60 }));
drawList->AddRectFilled(min, max, currToast->getColor(), 5_scaled);
drawList->PopClipRect();
ImGui::Indent();
currToast->draw();
ImGui::Unindent();
}
ImGui::End();
ImGui::PopStyleVar();
if ((currToast->getAppearTime() + impl::ToastBase::VisibilityTime) < ImGui::GetTime()) {
currToast.reset();
}
}
}
// Run all deferred calls
TaskManager::runDeferredCalls();