mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
impr: Further optimize ImGui text rendering
This commit is contained in:
@@ -123,6 +123,8 @@ namespace ImGuiExt {
|
||||
int m_width = 0, m_height = 0;
|
||||
};
|
||||
|
||||
float GetTextWrapPos();
|
||||
|
||||
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data);
|
||||
|
||||
bool IconHyperlink(const char *icon, const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
||||
@@ -186,7 +188,12 @@ namespace ImGuiExt {
|
||||
void SmallProgressBar(float fraction, float yOffset = 0.0F);
|
||||
|
||||
inline void TextFormatted(std::string_view fmt, auto &&...args) {
|
||||
ImGui::TextUnformatted(hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
if constexpr (sizeof...(args) == 0) {
|
||||
ImGui::TextUnformatted(fmt.data(), fmt.data() + fmt.size());
|
||||
} else {
|
||||
const auto string = hex::format(fmt, std::forward<decltype(args)>(args)...);
|
||||
ImGui::TextUnformatted(string.c_str(), string.c_str() + string.size());
|
||||
}
|
||||
}
|
||||
|
||||
inline void TextFormattedSelectable(std::string_view fmt, auto &&...args) {
|
||||
@@ -208,15 +215,24 @@ namespace ImGuiExt {
|
||||
}
|
||||
|
||||
inline void TextFormattedColored(ImColor color, std::string_view fmt, auto &&...args) {
|
||||
ImGui::TextColored(color, "%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, color.Value);
|
||||
ImGuiExt::TextFormatted(fmt, std::forward<decltype(args)>(args)...);
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
inline void TextFormattedDisabled(std::string_view fmt, auto &&...args) {
|
||||
ImGui::TextDisabled("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
|
||||
ImGuiExt::TextFormatted(fmt, std::forward<decltype(args)>(args)...);
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
inline void TextFormattedWrapped(std::string_view fmt, auto &&...args) {
|
||||
ImGui::TextWrapped("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
const bool need_backup = ImGuiExt::GetTextWrapPos() < 0.0F; // Keep existing wrap position if one is already set
|
||||
if (need_backup)
|
||||
ImGui::PushTextWrapPos(0.0F);
|
||||
ImGuiExt::TextFormatted(fmt, std::forward<decltype(args)>(args)...);
|
||||
if (need_backup)
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
inline void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) {
|
||||
|
||||
@@ -285,6 +285,10 @@ namespace ImGuiExt {
|
||||
glDeleteTextures(1, reinterpret_cast<GLuint*>(&m_textureId));
|
||||
}
|
||||
|
||||
float GetTextWrapPos() {
|
||||
return GImGui->CurrentWindow->DC.TextWrapPos;
|
||||
}
|
||||
|
||||
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data) {
|
||||
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
|
||||
auto &string = *static_cast<std::string *>(data->UserData);
|
||||
@@ -1194,7 +1198,7 @@ namespace ImGuiExt {
|
||||
|
||||
if (collapsed != nullptr && *collapsed) {
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - (ImGui::GetStyle().FramePadding.y * 2));
|
||||
ImGui::TextDisabled("...");
|
||||
ImGuiExt::TextFormattedDisabled("...");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user