chore: apply more light lints (#2575)

<!--
Please provide as much information as possible about what your PR aims
to do.
PRs with no description will most likely be closed until more
information is provided.
If you're planing on changing fundamental behaviour or add big new
features, please open a GitHub Issue first before starting to work on
it.
If it's not something big and you still want to contact us about it,
feel free to do so !
-->

### Problem description
<!-- Describe the bug that you fixed/feature request that you
implemented, or link to an existing issue describing it -->

### Implementation description
<!-- Explain what you did to correct the problem -->

### Screenshots
<!-- If your change is visual, take a screenshot showing it. Ideally,
make before/after sceenshots -->

### Additional things
<!-- Anything else you would like to say -->
This commit is contained in:
iTrooz
2025-12-20 15:59:48 +01:00
committed by GitHub
parent a1711ccfa6
commit 17c2dfcbd0
54 changed files with 444 additions and 457 deletions

View File

@@ -555,7 +555,7 @@ namespace hex::ui {
if (!this->isSelectionValid()) return;
if (!Region { byteAddress, 1 }.isWithin(region))
if (!Region { .address=byteAddress, .size=1 }.isWithin(region))
return;
// Draw vertical line at the left of first byte and the start of the line
@@ -581,7 +581,7 @@ namespace hex::ui {
if (!this->isSelectionValid()) return;
if (!Region { byteAddress, 1 }.isWithin(region))
if (!Region { .address=byteAddress, .size=1 }.isWithin(region))
return;
bool cursorVisible = (!ImGui::GetIO().ConfigInputTextCursorBlink) || (m_cursorBlinkTimer <= 0.0F) || std::fmod(m_cursorBlinkTimer, 1.20F) <= 0.80F;
@@ -694,7 +694,7 @@ namespace hex::ui {
if (m_provider != nullptr && m_provider->isReadable()) {
const auto isCurrRegionValid = [this](u64 address) {
auto &[currRegion, currRegionValid] = m_currValidRegion;
if (!Region{ address, 1 }.isWithin(currRegion)) {
if (!Region{ .address=address, .size=1 }.isWithin(currRegion)) {
m_currValidRegion = m_provider->getRegionValidity(address);
}
@@ -802,7 +802,7 @@ namespace hex::ui {
if (isColumnSeparatorColumn(x + 1, columnCount) && cellColors.size() > x + 1) {
auto separatorAddress = x + y * columnCount;
auto [nextForegroundColor, nextBackgroundColor] = cellColors[x + 1];
if ((isSelectionValid() && getSelection().overlaps({ separatorAddress, 1 }) && getSelection().getEndAddress() != separatorAddress) || backgroundColor == nextBackgroundColor)
if ((isSelectionValid() && getSelection().overlaps({ .address=separatorAddress, .size=1 }) && getSelection().getEndAddress() != separatorAddress) || backgroundColor == nextBackgroundColor)
adjustedCellSize.x += SeparatorColumWidth + 1;
}
@@ -846,7 +846,7 @@ namespace hex::ui {
ImGuiExt::TextFormatted("{:?>{}}", "", maxCharsPerCell);
if (cellHovered) {
Region newHoveredCell = { byteAddress, bytesPerCell };
Region newHoveredCell = { .address=byteAddress, .size=bytesPerCell };
if (hoveredCell != newHoveredCell) {
hoveredCell = newHoveredCell;
}
@@ -912,7 +912,7 @@ namespace hex::ui {
this->drawCell(byteAddress, &bytes[x], 1, cellHovered, CellType::ASCII);
if (cellHovered) {
Region newHoveredCell = { byteAddress, bytesPerCell };
Region newHoveredCell = { .address=byteAddress, .size=bytesPerCell };
if (hoveredCell != newHoveredCell) {
hoveredCell = newHoveredCell;
}
@@ -1007,7 +1007,7 @@ namespace hex::ui {
this->handleSelection(address, data.advance, &bytes[address % bytesPerRow], cellHovered);
if (cellHovered) {
Region newHoveredCell = { address, data.advance };
Region newHoveredCell = { .address=address, .size=data.advance };
if (hoveredCell != newHoveredCell) {
hoveredCell = newHoveredCell;
}

View File

@@ -717,8 +717,8 @@ namespace hex::ui {
else
i = 0;
}
if ((i32) (direction * i) >= (i32) ((line.size() - 1) * (1 + direction) / 2)) {
if (lineIndex == (i64) maxLineIndex * (1 + direction) / 2) {
if ((direction * i) >= (i32) ((line.size() - 1) * (1 + direction) / 2)) {
if (lineIndex == (i64) maxLineIndex * (1 + direction) / 2) {
if (m_active) {
m_active = false;
m_changed = true;

View File

@@ -1,7 +1,6 @@
#include <algorithm>
#include <ui/text_editor.hpp>
#include <hex/helpers/logger.hpp>
#include <algorithm>
namespace hex::ui {
using Coordinates = TextEditor::Coordinates;
@@ -324,13 +323,13 @@ namespace hex::ui {
// C++ can't overload functions based on return type, so use any type other
// than u64 to avoid ambiguity.
std::string Line::operator[](i64 index) const {
std::string Line::operator[](i64 column) const {
i64 utf8Length = TextEditor::stringCharacterCount(m_chars);
index = std::clamp(index, (i64) -utf8Length, (i64) utf8Length - 1);
if (index < 0)
index = utf8Length + index;
column = std::clamp(column, (-utf8Length), utf8Length - 1);
if (column < 0)
column = utf8Length + column;
i64 utf8Start = 0;
for (i64 utf8Index = 0; utf8Index < index; ++utf8Index) {
for (i64 utf8Index = 0; utf8Index < column; ++utf8Index) {
utf8Start += TextEditor::utf8CharLength(m_chars[utf8Start]);
}
i64 utf8CharLen = TextEditor::utf8CharLength(m_chars[utf8Start]);
@@ -468,10 +467,8 @@ namespace hex::ui {
bool TextEditor::ActionableBox::trigger() {
auto mousePos = ImGui::GetMousePos();
if (mousePos.x <= m_box.Min.x || mousePos.x >= m_box.Max.x ||
mousePos.y < m_box.Min.y || mousePos.y > m_box.Max.y)
return false;
return true;
return mousePos.x > m_box.Min.x && mousePos.x < m_box.Max.x &&
mousePos.y >= m_box.Min.y && mousePos.y <= m_box.Max.y;
}
void TextEditor::ActionableBox::shiftBoxVertically(float lineCount, float lineHeight) {

View File

@@ -235,11 +235,11 @@ namespace hex::ui {
if (strIndex < 0 || strIndex > (i32) input.size())
return {0, 0};
std::string str = input.substr(0, strIndex);
auto line = std::count(str.begin(), str.end(), '\n');
i32 line = std::count(str.begin(), str.end(), '\n');
auto index = str.find_last_of('\n');
str = str.substr(index + 1);
auto col = TextEditor::stringCharacterCount(str);
i32 col = TextEditor::stringCharacterCount(str);
return TextEditor::Coordinates(line, col);
return {line, col};
}
}

View File

@@ -23,12 +23,12 @@ namespace hex::ui {
switch (*type) {
case RegionType::EntireData:
*region = { provider->getBaseAddress(), provider->getActualSize() };
*region = { .address=provider->getBaseAddress(), .size=provider->getActualSize() };
break;
case RegionType::Selection:
*region = ImHexApi::HexEditor::getSelection().value_or(
ImHexApi::HexEditor::ProviderRegion {
{ 0, 1 },
{ .address=0, .size=1 },
provider }
).getRegion();
break;
@@ -59,7 +59,7 @@ namespace hex::ui {
ImGuiExt::InputHexadecimal("##end", &end);
ImGui::PopItemWidth();
*region = { start, (end - start) + 1 };
*region = { .address=start, .size=(end - start) + 1 };
ImGui::EndPopup();
}