mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
impr: Switch most usages of modals over to toasts
This commit is contained in:
@@ -7,49 +7,59 @@
|
||||
#include <fonts/codicons_font.h>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
#include <popups/popup_notification.hpp>
|
||||
|
||||
namespace hex::ui {
|
||||
|
||||
namespace impl {
|
||||
|
||||
template<typename T>
|
||||
struct ToastNotification : Toast<T> {
|
||||
ToastNotification(ImColor color, const char *icon, UnlocalizedString title, UnlocalizedString message)
|
||||
: Toast<T>(color), m_icon(icon), m_title(std::move(title)), m_message(std::move(message)) {}
|
||||
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)) {}
|
||||
|
||||
void drawContent() final {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiExt::TextFormattedColored(this->getColor(), "{}", m_icon);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushFont(ImHexApi::Fonts::Bold());
|
||||
{
|
||||
ImGuiExt::TextFormatted("{}", hex::limitStringLength(Lang(m_title).get(), 30));
|
||||
}
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGuiExt::TextFormatted("{}", hex::limitStringLength(Lang(m_unlocalizedTitle).get(), 30));
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGuiExt::TextFormattedWrapped("{}", hex::limitStringLength(Lang(m_message).get(), 60));
|
||||
ImGuiExt::TextFormattedWrapped("{}", hex::limitStringLength(m_message, 60));
|
||||
}
|
||||
|
||||
private:
|
||||
const char *m_icon;
|
||||
UnlocalizedString m_title, m_message;
|
||||
UnlocalizedString m_unlocalizedTitle;
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct ToastInfo : impl::ToastNotification<ToastInfo> {
|
||||
ToastInfo(UnlocalizedString title, UnlocalizedString message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerInfo), ICON_VS_INFO, std::move(title), std::move(message)) {}
|
||||
ToastInfo(std::string message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerInfo), ICON_VS_INFO, "hex.ui.common.info", std::move(message)) {}
|
||||
};
|
||||
|
||||
struct ToastWarn : impl::ToastNotification<ToastWarn> {
|
||||
ToastWarn(UnlocalizedString title, UnlocalizedString message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerWarning), ICON_VS_WARNING, std::move(title), std::move(message)) {}
|
||||
struct ToastWarning : impl::ToastNotification<ToastWarning> {
|
||||
ToastWarning(std::string message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerWarning), ICON_VS_WARNING, "hex.ui.common.warning", std::move(message)) {}
|
||||
};
|
||||
|
||||
struct ToastError : impl::ToastNotification<ToastError> {
|
||||
ToastError(UnlocalizedString title, UnlocalizedString message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError), ICON_VS_ERROR, std::move(title), std::move(message)) {}
|
||||
ToastError(std::string message)
|
||||
: ToastNotification(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError), ICON_VS_ERROR, "hex.ui.common.error", std::move(message)) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user