60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "helpers.h"
|
|
#include "program.h"
|
|
#include "tft_handler.h"
|
|
|
|
void Helpers::recalculate_taskbar(std::vector<TaskBarItem>& task_bar_items) {
|
|
for (short i = 0; i < task_bar_items.size(); ++i) {
|
|
if (i == 0) {
|
|
task_bar_items[i].place_x = 60;
|
|
} else {
|
|
const TaskBarItem& prev = task_bar_items[i - 1];
|
|
task_bar_items[i].place_x = prev.place_x + prev.offset_x;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ScrollableTextBox::reflow_text(TFT_Handler* tft) {
|
|
lines.clear();
|
|
std::string current_line = "";
|
|
short current_y = 0;
|
|
|
|
for (size_t i = 0; i < content.length(); i++) {
|
|
char c = content[i];
|
|
|
|
if (c == '\n') {
|
|
// Explicit newline
|
|
lines.push_back({current_line, current_y});
|
|
current_line = "";
|
|
current_y += line_height;
|
|
continue;
|
|
}
|
|
|
|
// Check if adding this character would exceed width
|
|
short test_width, test_height;
|
|
std::string test_str = current_line + c;
|
|
tft->get_text_bounds(test_str, text_size, test_width, test_height);
|
|
|
|
if (test_width > width - 10) { // -10 for padding
|
|
// Word wrap - try to break at last space
|
|
size_t last_space = current_line.find_last_of(' ');
|
|
if (last_space != std::string::npos) {
|
|
// Break at space
|
|
std::string line_to_add = current_line.substr(0, last_space);
|
|
lines.push_back({line_to_add, current_y});
|
|
current_line = current_line.substr(last_space + 1) + c;
|
|
} else {
|
|
// No space found, hard break
|
|
lines.push_back({current_line, current_y});
|
|
current_line = std::string(1, c);
|
|
}
|
|
current_y += line_height;
|
|
} else {
|
|
current_line += c;
|
|
}
|
|
}
|
|
|
|
// Add remaining text
|
|
if (!current_line.empty()) {
|
|
lines.push_back({current_line, current_y});
|
|
}
|
|
} |