#pragma once #include "gui/ImGuiNotify.hpp" #include #include #include #include #include class Toast { public: template static void Info(std::string_view fmt, Args&&... args) { ImGui::InsertNotification({ImGuiToastType::Info, 3000, Format(fmt, std::forward(args)...).c_str()}); } template static void Warning(std::string_view fmt, Args&&... args) { ImGui::InsertNotification({ImGuiToastType::Warning, 4000, Format(fmt, std::forward(args)...).c_str()}); } template static void Error(std::string_view fmt, Args&&... args) { ImGui::InsertNotification({ImGuiToastType::Error, 5000, Format(fmt, std::forward(args)...).c_str()}); } template static void Success(std::string_view fmt, Args&&... args) { ImGui::InsertNotification({ImGuiToastType::Success, 2500, Format(fmt, std::forward(args)...).c_str()}); } private: template static std::string Format(std::string_view fmt, Args&&... args) { if constexpr (sizeof...(Args) == 0) { return std::string(fmt); } else { std::string format(fmt); int size = std::snprintf(nullptr, 0, format.c_str(), std::forward(args)...) + 1; if (size <= 0) return std::string(fmt); std::vector buffer(static_cast(size)); std::snprintf(buffer.data(), static_cast(size), format.c_str(), std::forward(args)...); return std::string(buffer.data()); } } };