1
0
mirror of synced 2025-01-31 03:53:44 +01:00

impr: Further cleanup hex editor footer

This commit is contained in:
WerWolv 2024-06-25 21:19:59 +02:00
parent c56667b0dd
commit 95166ccfb8
4 changed files with 60 additions and 64 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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",

View File

@ -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());
}