mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
feat: Added banners, replace some modals with them
This commit is contained in:
51
plugins/ui/include/banners/banner_button.hpp
Normal file
51
plugins/ui/include/banners/banner_button.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/ui/banner.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
namespace hex::ui {
|
||||
|
||||
class BannerButton : public Banner<BannerButton> {
|
||||
public:
|
||||
BannerButton(const char *icon, UnlocalizedString message, ImColor color, UnlocalizedString buttonText, std::function<void()> buttonCallback)
|
||||
: Banner(color), m_icon(icon), m_message(std::move(message)), m_buttonText(std::move(buttonText)), m_buttonCallback(std::move(buttonCallback)) { }
|
||||
|
||||
void drawContent() override {
|
||||
const std::string buttonText = Lang(m_buttonText);
|
||||
const auto buttonSize = ImGui::CalcTextSize(buttonText.c_str());
|
||||
|
||||
ImGui::TextUnformatted(m_icon);
|
||||
ImGui::SameLine(0, 10_scaled);
|
||||
|
||||
const std::string message = Lang(m_message);
|
||||
const auto messageSize = ImGui::CalcTextSize(message.c_str());
|
||||
ImGuiExt::TextFormatted("{}", limitStringLength(message, message.size() * ((ImGui::GetContentRegionAvail().x - buttonSize.x - 40_scaled) / messageSize.x)));
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetNextWindowSize(ImVec2(400_scaled, 0));
|
||||
if (ImGui::BeginTooltip()) {
|
||||
ImGuiExt::TextFormattedWrapped("{}", message);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - buttonSize.x - 20_scaled);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 2_scaled);
|
||||
if (ImGui::SmallButton(buttonText.c_str())) {
|
||||
m_buttonCallback();
|
||||
this->close();
|
||||
}
|
||||
ImGui::PopStyleVar(1);
|
||||
}
|
||||
|
||||
private:
|
||||
const char *m_icon;
|
||||
UnlocalizedString m_message;
|
||||
UnlocalizedString m_buttonText;
|
||||
std::function<void()> m_buttonCallback;
|
||||
};
|
||||
|
||||
}
|
||||
24
plugins/ui/include/banners/banner_icon.hpp
Normal file
24
plugins/ui/include/banners/banner_icon.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/ui/banner.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace hex::ui {
|
||||
|
||||
class BannerIcon : public Banner<BannerIcon> {
|
||||
public:
|
||||
BannerIcon(const char *icon, UnlocalizedString message, ImColor color)
|
||||
: Banner(color), m_icon(icon), m_message(std::move(message)) { }
|
||||
|
||||
void drawContent() override {
|
||||
ImGui::TextUnformatted(m_icon);
|
||||
ImGui::SameLine(0, 10_scaled);
|
||||
ImGui::TextUnformatted(Lang(m_message));
|
||||
}
|
||||
|
||||
private:
|
||||
const char *m_icon;
|
||||
UnlocalizedString m_message;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user