Notifications (#3002)

This commit is contained in:
Totoo
2026-02-19 14:33:01 +01:00
committed by GitHub
parent 77f747aab2
commit 6498f5a1b2
27 changed files with 424 additions and 70 deletions
+30 -11
View File
@@ -386,7 +386,9 @@ void Text::set(std::string_view value) {
text = std::string{value};
set_dirty();
}
std::string Text::get() {
return text;
}
void Text::getAccessibilityText(std::string& result) {
result = text;
}
@@ -396,18 +398,35 @@ void Text::getWidgetName(std::string& result) {
void Text::paint(Painter& painter) {
const auto rect = screen_rect();
auto s = has_focus() ? style().invert() : style();
auto max_len = (unsigned)rect.width() / s.font.char_width();
auto text_view = std::string_view{text};
painter.fill_rectangle(rect, s.background);
const int char_width = s.font.char_width();
const int line_height = s.font.line_height();
if (char_width == 0 || line_height == 0) return;
const size_t chars_per_line = rect.width() / char_width;
if (chars_per_line == 0) return;
size_t lines_capacity = rect.height() / line_height;
if (lines_capacity == 0) lines_capacity = 1; // at least one line, even if it overflows vertically
auto text_view = std::string_view{text};
size_t current_offset = 0;
for (size_t line_idx = 0; line_idx < lines_capacity; ++line_idx) {
if (current_offset >= text_view.length()) break;
size_t chunk_len = std::min(chars_per_line, text_view.length() - current_offset);
painter.draw_string(
rect.location() + Point(0, line_idx * line_height),
s,
text_view.substr(current_offset, chunk_len));
current_offset += chunk_len;
}
}
if (text_view.length() > max_len)
text_view = text_view.substr(0, max_len);
painter.draw_string(
rect.location(),
s,
text_view);
bool Text::on_touch(const TouchEvent event) {
if (event.type == TouchEvent::Type::Start) {
if (on_select) {
on_select(*this);
return true;
}
}
return false;
}
/* Labels ****************************************************************/