Skip to content

ui task

rogovogor edited this page May 15, 2026 · 2 revisions

UITask.cpp — Adaptive UI and MsgPreview / Адаптивный UI и MsgPreview

[English] · [Русский]


English

File: examples/companion_radio/ui-new/UITask.cpp

Summary

Two independent directions: (1) adaptive HomeScreen layout for displays of different widths, (2) redesign of the unread message preview screen.


1. Adaptive HomeScreen Layout

All HomeScreen pages (MSGS, RECENT, RADIO, BLUETOOTH, ADVERT, GPS, SENSORS, SHUTDOWN) have been migrated from hardcoded coordinates to computed metrics:

int hdr_size   = (display.width() >= 200) ? 2 : 1;  // header font size
int hdr_line_h = 8 * hdr_size;                        // header line height
int dot_y      = hdr_line_h + 5;                      // Y of page indicator
int content_y  = hdr_line_h + 14;                     // Y of content start
int line_h     = 8 * hdr_size + 3;                    // line spacing
  • Narrow displays (< 200 px): hdr_size=1, behavior as before.
  • Wide displays (≥ 200 px): hdr_size=2, larger font in header and content.
  • RADIO page: for hdr_size=2, shortened string formats are used (FQ:%.3f SF:%d instead of FQ: %06.3f SF: %d).
  • All elements are positioned relative to content_y and display.height() instead of absolute values like y=18, y=64-11, etc.

Removal of showAlert

When navigating to the RECENT page, the call to _task->showAlert("Recent adverts", 800) has been removed — it was redundant.


2. MsgPreview — Structural and Render Redesign

MsgEntry Structure

Before:

char origin[62];   // formatted string "(D) name:" or "(N) name:"
char msg[78];

After:

uint8_t  path_len;        // 0xFF = direct, otherwise hop count
char     from_name[32];   // sender / channel name
char     msg[MAX_TEXT_LEN];

Data is stored unformatted; formatting has been moved to render().

addPreview()

Removed sprintf for origin; replaced with direct copying of path_len and from_name via strncpy with NUL guarantee.

render() — New Algorithm

  1. Metrics: hdr_size based on display width, msg_start_y = hdr_line_h + 3.
  2. Body font size selection: word-wrap is simulated at size=2; if the message fits — body_size=2 is used, otherwise body_size=1.
  3. Header: #N (D)name (direct) or #N [hops]name (group) on the left + time Xs/Xm/Xh on the right, both in hdr_size.
  4. Divider: horizontal line at hdr_line_h + 2.
  5. Body: printWordWrap() in body_size.
  6. Removed rendering of "Unread: N" and the old layout with origin.

Русский

Файл: examples/companion_radio/ui-new/UITask.cpp

Вектор изменений

Два независимых направления: (1) адаптивная раскладка HomeScreen под дисплеи разной ширины, (2) переработка экрана предпросмотра непрочитанных сообщений.


1. Адаптивная раскладка HomeScreen

Все страницы HomeScreen (MSGS, RECENT, RADIO, BLUETOOTH, ADVERT, GPS, SENSORS, SHUTDOWN) переведены с хардкод-координат на вычисляемые метрики:

int hdr_size   = (display.width() >= 200) ? 2 : 1;  // размер шрифта заголовка
int hdr_line_h = 8 * hdr_size;                        // высота строки заголовка
int dot_y      = hdr_line_h + 5;                      // Y индикатора страницы
int content_y  = hdr_line_h + 14;                     // Y начала контента
int line_h     = 8 * hdr_size + 3;                    // межстрочный интервал
  • Узкие дисплеи (< 200 px): hdr_size=1, поведение как прежде.
  • Широкие дисплеи (≥ 200 px): hdr_size=2, крупный шрифт в заголовке и контенте.
  • Страница RADIO: для hdr_size=2 используются укороченные форматы строк (FQ:%.3f SF:%d вместо FQ: %06.3f SF: %d).
  • Все элементы позиционируются относительно content_y и display.height() вместо абсолютных y=18, y=64-11 и т.д.

Удаление showAlert

При навигации на страницу RECENT убран вызов _task->showAlert("Recent adverts", 800) — был лишним.


2. MsgPreview — переработка структуры и рендера

Структура MsgEntry

До:

char origin[62];   // форматированная строка "(D) name:" или "(N) name:"
char msg[78];

После:

uint8_t  path_len;        // 0xFF = direct, иначе hop count
char     from_name[32];   // имя отправителя / канала
char     msg[MAX_TEXT_LEN];

Данные хранятся неформатированными, форматирование перенесено в render().

addPreview()

Убрано sprintf для origin; вместо него — прямое копирование path_len и from_name через strncpy с NUL-гарантией.

render() — новый алгоритм

  1. Метрики: hdr_size по ширине дисплея, msg_start_y = hdr_line_h + 3.
  2. Выбор размера шрифта тела: симулируется перенос по словам при size=2; если сообщение умещается — используется body_size=2, иначе body_size=1.
  3. Заголовок: #N (D)name (direct) или #N [hops]name (group) слева + время Xs/Xm/Xh справа, оба в hdr_size.
  4. Разделитель: горизонтальная линия на hdr_line_h + 2.
  5. Тело: printWordWrap() в body_size.
  6. Убрана отрисовка "Unread: N" и старый layout с origin.

Clone this wiki locally