impr: Further optimize ImGui text rendering
This commit is contained in:
parent
7d42742684
commit
e5c782ebe9
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ namespace hex {
|
||||
// Plugin load error popups
|
||||
// These are not translated because they should always be readable, no matter if any localization could be loaded or not
|
||||
{
|
||||
auto drawPluginFolderTable = [] {
|
||||
const static auto drawPluginFolderTable = [] {
|
||||
ImGuiExt::UnderlinedText("Plugin folders");
|
||||
if (ImGui::BeginTable("plugins", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2(0, 100_scaled))) {
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
|
@ -63,11 +63,11 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TextUnformatted(" ");
|
||||
break;
|
||||
case 0xFF:
|
||||
ImGui::TextDisabled("##");
|
||||
ImGuiExt::TextFormattedDisabled("##");
|
||||
break;
|
||||
default:
|
||||
if (c >= ' ' && c <= '~')
|
||||
ImGui::Text(".%c", c);
|
||||
ImGuiExt::TextFormatted(".{:c}", char(c));
|
||||
else
|
||||
ImGui::Text(getFormatString(upperCase), c);
|
||||
break;
|
||||
|
@ -30,9 +30,9 @@ namespace hex::ui {
|
||||
ImGui::TextUnformatted(string.data());
|
||||
}
|
||||
else
|
||||
ImGui::TextDisabled(".");
|
||||
ImGuiExt::TextFormattedDisabled(".");
|
||||
} else {
|
||||
ImGui::TextDisabled(".");
|
||||
ImGuiExt::TextFormattedDisabled(".");
|
||||
}
|
||||
}
|
||||
|
||||
@ -455,12 +455,17 @@ namespace hex::ui {
|
||||
const float SeparatorColumWidth = 6_scaled;
|
||||
const auto CharacterSize = ImGui::CalcTextSize("0");
|
||||
|
||||
if (const auto &visualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); m_currDataVisualizer == nullptr && visualizer != nullptr) {
|
||||
if (m_currDataVisualizer == nullptr) {
|
||||
if (const auto &visualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); visualizer != nullptr) {
|
||||
m_currDataVisualizer = visualizer;
|
||||
return;
|
||||
}
|
||||
if (const auto &visualizers = ContentRegistry::HexEditor::impl::getMiniMapVisualizers(); m_miniMapVisualizer == nullptr && !visualizers.empty())
|
||||
}
|
||||
|
||||
if (m_miniMapVisualizer == nullptr) {
|
||||
if (const auto &visualizers = ContentRegistry::HexEditor::impl::getMiniMapVisualizers(); !visualizers.empty())
|
||||
m_miniMapVisualizer = visualizers.front();
|
||||
}
|
||||
|
||||
const auto bytesPerCell = m_currDataVisualizer->getBytesPerCell();
|
||||
const u16 columnCount = m_bytesPerRow / bytesPerCell;
|
||||
|
Loading…
Reference in New Issue
Block a user