mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 01:32:40 +00:00
Misc cppcheck fixes (#7370)
This commit is contained in:
@@ -1447,7 +1447,7 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
|
||||
int headerY = y;
|
||||
int listTop = headerY + headerFontHeight + headerMargin;
|
||||
|
||||
int visibleRows = (display->getHeight() - listTop - 2) / rowHeight;
|
||||
int _visibleRows = (display->getHeight() - listTop - 2) / rowHeight;
|
||||
int numEmotes = graphics::numEmotes;
|
||||
|
||||
// Clamp highlight index
|
||||
@@ -1457,11 +1457,11 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
|
||||
emotePickerIndex = numEmotes - 1;
|
||||
|
||||
// Determine which emote is at the top
|
||||
int topIndex = emotePickerIndex - visibleRows / 2;
|
||||
int topIndex = emotePickerIndex - _visibleRows / 2;
|
||||
if (topIndex < 0)
|
||||
topIndex = 0;
|
||||
if (topIndex > numEmotes - visibleRows)
|
||||
topIndex = std::max(0, numEmotes - visibleRows);
|
||||
if (topIndex > numEmotes - _visibleRows)
|
||||
topIndex = std::max(0, numEmotes - _visibleRows);
|
||||
|
||||
// Draw header/title
|
||||
display->setFont(FONT_SMALL);
|
||||
@@ -1709,7 +1709,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
} else {
|
||||
// Text: split by words and wrap inside word if needed
|
||||
String text = token.second;
|
||||
uint16_t pos = 0;
|
||||
pos = 0;
|
||||
while (pos < text.length()) {
|
||||
// Find next space (or end)
|
||||
int spacePos = text.indexOf(' ', pos);
|
||||
@@ -1753,7 +1753,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
int yLine = inputY;
|
||||
for (auto &line : lines) {
|
||||
int nextX = x;
|
||||
for (auto &token : line) {
|
||||
for (const auto &token : line) {
|
||||
if (token.first) {
|
||||
const graphics::Emote *emote = nullptr;
|
||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
||||
@@ -1789,19 +1789,20 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
|
||||
int topMsg;
|
||||
std::vector<int> rowHeights;
|
||||
int visibleRows;
|
||||
int _visibleRows;
|
||||
|
||||
// Draw header (To: ...)
|
||||
drawHeader(display, x, y, buffer);
|
||||
|
||||
// Shift message list upward by 3 pixels to reduce spacing between header and first message
|
||||
const int listYOffset = y + FONT_HEIGHT_SMALL - 3;
|
||||
visibleRows = (display->getHeight() - listYOffset) / baseRowSpacing;
|
||||
_visibleRows = (display->getHeight() - listYOffset) / baseRowSpacing;
|
||||
|
||||
// Figure out which messages are visible and their needed heights
|
||||
topMsg =
|
||||
(messagesCount > visibleRows && currentMessageIndex >= visibleRows - 1) ? currentMessageIndex - visibleRows + 2 : 0;
|
||||
int countRows = std::min(messagesCount, visibleRows);
|
||||
topMsg = (messagesCount > _visibleRows && currentMessageIndex >= _visibleRows - 1)
|
||||
? currentMessageIndex - _visibleRows + 2
|
||||
: 0;
|
||||
int countRows = std::min(messagesCount, _visibleRows);
|
||||
|
||||
// --- Build per-row max height based on all emotes in line ---
|
||||
for (int i = 0; i < countRows; i++) {
|
||||
@@ -1828,7 +1829,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
int lineY = yCursor;
|
||||
const char *msg = getMessageByIndex(msgIdx);
|
||||
int rowHeight = rowHeights[vis];
|
||||
bool highlight = (msgIdx == currentMessageIndex);
|
||||
bool _highlight = (msgIdx == currentMessageIndex);
|
||||
|
||||
// --- Multi-emote tokenization ---
|
||||
std::vector<std::pair<bool, String>> tokens; // (isEmote, token)
|
||||
@@ -1881,20 +1882,20 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
int textYOffset = (rowHeight - FONT_HEIGHT_SMALL) / 2;
|
||||
|
||||
#ifdef USE_EINK
|
||||
int nextX = x + (highlight ? 12 : 0);
|
||||
if (highlight)
|
||||
int nextX = x + (_highlight ? 12 : 0);
|
||||
if (_highlight)
|
||||
display->drawString(x + 0, lineY + textYOffset, ">");
|
||||
#else
|
||||
int scrollPadding = 8;
|
||||
if (highlight) {
|
||||
if (_highlight) {
|
||||
display->fillRect(x + 0, lineY, display->getWidth() - scrollPadding, rowHeight);
|
||||
display->setColor(BLACK);
|
||||
}
|
||||
int nextX = x + (highlight ? 2 : 0);
|
||||
int nextX = x + (_highlight ? 2 : 0);
|
||||
#endif
|
||||
|
||||
// Draw all tokens left to right
|
||||
for (auto &token : tokens) {
|
||||
for (const auto &token : tokens) {
|
||||
if (token.first) {
|
||||
// Emote
|
||||
const graphics::Emote *emote = nullptr;
|
||||
@@ -1916,7 +1917,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
}
|
||||
}
|
||||
#ifndef USE_EINK
|
||||
if (highlight)
|
||||
if (_highlight)
|
||||
display->setColor(WHITE);
|
||||
#endif
|
||||
|
||||
@@ -1924,11 +1925,11 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
||||
}
|
||||
|
||||
// Scrollbar
|
||||
if (messagesCount > visibleRows) {
|
||||
if (messagesCount > _visibleRows) {
|
||||
int scrollHeight = display->getHeight() - listYOffset;
|
||||
int scrollTrackX = display->getWidth() - 6;
|
||||
display->drawRect(scrollTrackX, listYOffset, 4, scrollHeight);
|
||||
int barHeight = (scrollHeight * visibleRows) / messagesCount;
|
||||
int barHeight = (scrollHeight * _visibleRows) / messagesCount;
|
||||
int scrollPos = listYOffset + (scrollHeight * topMsg) / messagesCount;
|
||||
display->fillRect(scrollTrackX, scrollPos, 4, barHeight);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user