diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 06d57e6dd..988135fd1 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -573,8 +573,13 @@ namespace ImGuiExt { bool result = false; if (IsItemHovered() && (currTime - lastMoveTime) >= 0.5 && hoveredID == lastHoveredID) { if (!std::string_view(text).empty()) { - const auto width = 300 * hex::ImHexApi::System::getGlobalScale(); - ImGui::SetNextWindowSizeConstraints(ImVec2(width / 2, 0), ImVec2(width, FLT_MAX)); + const auto textWidth = CalcTextSize(text).x; + + auto width = 150 * hex::ImHexApi::System::getGlobalScale(); + if (textWidth < width) + width = textWidth; + + ImGui::SetNextWindowSizeConstraints(ImVec2(width, 0), ImVec2(width * 2, FLT_MAX)); if (BeginTooltip()) { if (isSeparator) SeparatorText(text); diff --git a/plugins/ui/include/ui/hex_editor.hpp b/plugins/ui/include/ui/hex_editor.hpp index 1e2ab0443..6c90ea12b 100644 --- a/plugins/ui/include/ui/hex_editor.hpp +++ b/plugins/ui/include/ui/hex_editor.hpp @@ -232,10 +232,6 @@ namespace hex::ui { m_showAscii = showAscii; } - void enableShowHumanReadableUnits(bool showHumanReadableUnits) { - m_showHumanReadableUnits = showHumanReadableUnits; - } - void enableSyncScrolling(bool syncScrolling) { m_scrollPosition.setSynced(syncScrolling); } @@ -365,7 +361,6 @@ namespace hex::ui { bool m_showCustomEncoding = true; bool m_showMiniMap = false; int m_miniMapWidth = 5; - bool m_showHumanReadableUnits = true; u32 m_byteCellPadding = 0, m_characterCellPadding = 0; bool m_footerCollapsed = true; diff --git a/plugins/ui/romfs/lang/en_US.json b/plugins/ui/romfs/lang/en_US.json index 336d07065..e5c71ad56 100644 --- a/plugins/ui/romfs/lang/en_US.json +++ b/plugins/ui/romfs/lang/en_US.json @@ -88,8 +88,9 @@ "hex.ui.hex_editor.columns": "Columns", "hex.ui.hex_editor.human_readable_units_footer": "Convert sizes to human-readable units", "hex.ui.hex_editor.data_size": "Data Size", + "hex.ui.hex_editor.data_cell_options": "Data Cell Options", "hex.ui.hex_editor.gray_out_zero": "Grey out zeros", - "hex.ui.hex_editor.minimap": "Mini Map", + "hex.ui.hex_editor.minimap": "Mini Map\n(Right click for settings)", "hex.ui.hex_editor.minimap.width": "Width", "hex.ui.hex_editor.no_bytes": "No bytes available", "hex.ui.hex_editor.page": "Page", diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index d7fe8a677..3136e3199 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -957,15 +957,52 @@ namespace hex::ui { ImGui::EndPopup(); } - ImGui::SameLine(); + ImGui::SameLine(0, 1_scaled); - // Human-readable units - ImGuiExt::DimmedIconToggle(ICON_VS_SYMBOL_NUMERIC, &m_showHumanReadableUnits); - ImGuiExt::InfoTooltip("hex.ui.hex_editor.human_readable_units_footer"_lang); + // Data Cell configuration + if (ImGuiExt::DimmedIconButton(ICON_VS_TABLE, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { + ImGui::OpenPopup("DataCellOptions"); + } + ImGuiExt::InfoTooltip("hex.ui.hex_editor.data_cell_options"_lang); - ImGui::SameLine(0, 10_scaled); - if (m_mode == Mode::Insert) { - ImGui::TextUnformatted("[ INSERT ]"); + if (ImGui::BeginPopup("DataCellOptions")) { + + if (ImGui::BeginCombo("##visualizer", Lang(m_currDataVisualizer->getUnlocalizedName()))) { + for (const auto &visualizer : ContentRegistry::HexEditor::impl::getVisualizers()) { + if (ImGui::Selectable(Lang(visualizer->getUnlocalizedName()))) { + m_currDataVisualizer = visualizer; + m_encodingLineStartAddresses.clear(); + + m_bytesPerRow = std::max(m_bytesPerRow, visualizer->getBytesPerCell()); + } + } + + ImGui::EndCombo(); + } + + { + bool hasEndianness = m_currDataVisualizer->getBytesPerCell() > 1; + + if (!hasEndianness) + m_dataVisualizerEndianness = std::endian::native; + + ImGui::BeginDisabled(!hasEndianness); + { + int sliderPos = m_dataVisualizerEndianness == std::endian::little ? 0 : 1; + ImGui::SliderInt("##visualizer_endianness", &sliderPos, 0, 1, sliderPos == 0 ? "hex.ui.common.little"_lang : "hex.ui.common.big"_lang); + m_dataVisualizerEndianness = sliderPos == 0 ? std::endian::little : std::endian::big; + } + ImGui::EndDisabled(); + } + + ImGui::NewLine(); + + int bytesPerRow = m_bytesPerRow / this->getBytesPerCell(); + if (ImGui::SliderInt("##row_size", &bytesPerRow, 1, 128 / this->getBytesPerCell(), hex::format("{} {}", bytesPerRow * this->getBytesPerCell(), "hex.ui.hex_editor.columns"_lang).c_str())) { + m_bytesPerRow = bytesPerRow * this->getBytesPerCell(); + m_encodingLineStartAddresses.clear(); + } + ImGui::EndPopup(); } } @@ -978,53 +1015,11 @@ namespace hex::ui { ImGui::TableNextColumn(); - // Visualizer - { - auto &visualizers = ContentRegistry::HexEditor::impl::getVisualizers(); - - { - bool hasEndianness = m_currDataVisualizer->getBytesPerCell() > 1; - - if (!hasEndianness) - m_dataVisualizerEndianness = std::endian::native; - - ImGui::BeginDisabled(!hasEndianness); - { - int sliderPos = m_dataVisualizerEndianness == std::endian::little ? 0 : 1; - ImGui::PushItemWidth(60_scaled); - ImGui::SliderInt("##visualizer_endianness", &sliderPos, 0, 1, sliderPos == 0 ? "hex.ui.common.little"_lang : "hex.ui.common.big"_lang); - ImGui::PopItemWidth(); - m_dataVisualizerEndianness = sliderPos == 0 ? std::endian::little : std::endian::big; - } - ImGui::EndDisabled(); - } - - ImGui::SameLine(0, 2_scaled); - ImGui::PushItemWidth((ImGui::GetContentRegionAvail().x / 3) * 2); - if (ImGui::BeginCombo("##visualizer", Lang(m_currDataVisualizer->getUnlocalizedName()))) { - - for (const auto &visualizer : visualizers) { - if (ImGui::Selectable(Lang(visualizer->getUnlocalizedName()))) { - m_currDataVisualizer = visualizer; - m_encodingLineStartAddresses.clear(); - - m_bytesPerRow = std::max(m_bytesPerRow, visualizer->getBytesPerCell()); - } - } - - ImGui::EndCombo(); - } - ImGui::PopItemWidth(); - - ImGui::SameLine(0, 2_scaled); - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); - int bytesPerRow = m_bytesPerRow / this->getBytesPerCell(); - if (ImGui::SliderInt("##row_size", &bytesPerRow, 1, 128 / this->getBytesPerCell(), hex::format("{} {}", bytesPerRow * this->getBytesPerCell(), "hex.ui.hex_editor.columns"_lang).c_str())) { - m_bytesPerRow = bytesPerRow * this->getBytesPerCell(); - m_encodingLineStartAddresses.clear(); - } - ImGui::PopItemWidth(); + ImGui::SameLine(0, 20_scaled); + if (m_mode == Mode::Insert) { + ImGui::TextUnformatted("[ INSERT ]"); } + if (!m_footerCollapsed) { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 3_scaled); ImGui::Dummy({}); @@ -1057,9 +1052,9 @@ namespace hex::ui { ImGuiExt::TextFormattedSelectable("0x{0:08X} (0x{1:X} | {2})", m_provider->getBaseAddress(), m_provider->getBaseAddress() + m_provider->getActualSize(), - m_showHumanReadableUnits - ? hex::toByteString(m_provider->getActualSize()) - : hex::format("{}", m_provider->getActualSize()) + ImGui::GetIO().KeyCtrl + ? hex::format("{}", m_provider->getActualSize()) + : hex::toByteString(m_provider->getActualSize()) ); ImGui::SetItemTooltip("%s", "hex.ui.hex_editor.data_size"_lang.get().c_str()); }