2023-12-19 23:21:20 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex/api/imhex_api.hpp>
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
#include <hex/ui/toast.hpp>
|
|
|
|
|
|
|
|
#include <fonts/codicons_font.h>
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
|
2023-12-26 00:22:47 +01:00
|
|
|
#include <popups/popup_notification.hpp>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
namespace hex::ui {
|
2023-12-19 23:21:20 +01:00
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ToastNotification : Toast<T> {
|
2023-12-26 00:22:47 +01:00
|
|
|
ToastNotification(ImColor color, const char *icon, UnlocalizedString unlocalizedTitle, std::string message)
|
|
|
|
: Toast<T>(color), m_icon(icon), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_message(std::move(message)) {}
|
2023-12-19 23:21:20 +01:00
|
|
|
|
|
|
|
void drawContent() final {
|
2023-12-26 00:22:47 +01:00
|
|
|
if (ImGui::IsWindowHovered()) {
|
|
|
|
if (ImGui::BeginTooltip()) {
|
|
|
|
ImGuiExt::Header(Lang(m_unlocalizedTitle), true);
|
|
|
|
ImGui::PushTextWrapPos(300_scaled);
|
|
|
|
ImGui::TextUnformatted(m_message.c_str());
|
|
|
|
ImGui::PopTextWrapPos();
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-19 23:21:20 +01:00
|
|
|
ImGuiExt::TextFormattedColored(this->getColor(), "{}", m_icon);
|
|
|
|
ImGui::SameLine();
|
2023-12-26 00:22:47 +01:00
|
|
|
|
|
|
|
ImGuiExt::TextFormatted("{}", hex::limitStringLength(Lang(m_unlocalizedTitle).get(), 30));
|
2023-12-19 23:21:20 +01:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-12-26 00:22:47 +01:00
|
|
|
ImGuiExt::TextFormattedWrapped("{}", hex::limitStringLength(m_message, 60));
|
2023-12-19 23:21:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *m_icon;
|
2023-12-26 00:22:47 +01:00
|
|
|
UnlocalizedString m_unlocalizedTitle;
|
|
|
|
std::string m_message;
|
2023-12-19 23:21:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ToastInfo : impl::ToastNotification<ToastInfo> {
|
2023-12-26 00:22:47 +01:00
|
|
|
ToastInfo(std::string message)
|
|
|
|
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerInfo), ICON_VS_INFO, "hex.ui.common.info", std::move(message)) {}
|
2023-12-19 23:21:20 +01:00
|
|
|
};
|
|
|
|
|
2023-12-26 00:22:47 +01:00
|
|
|
struct ToastWarning : impl::ToastNotification<ToastWarning> {
|
|
|
|
ToastWarning(std::string message)
|
|
|
|
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerWarning), ICON_VS_WARNING, "hex.ui.common.warning", std::move(message)) {}
|
2023-12-19 23:21:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ToastError : impl::ToastNotification<ToastError> {
|
2023-12-26 00:22:47 +01:00
|
|
|
ToastError(std::string message)
|
|
|
|
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError), ICON_VS_ERROR, "hex.ui.common.error", std::move(message)) {}
|
2023-12-19 23:21:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|