Public Access
Steps 5 and 6 of M0. - lib/ui (host-tested): ListModel, LineEditor (UTF-8, byte-limited), wrapText, ToastQueue, DialogModel - lib/input (host-tested): KeyMapper turns keyboard state into logical keys (Fn arrows, ` Back, Fn+` Home) and composes accents with opt - src/ui: off-screen 16-bit frame pushed in one transfer (fixes the flicker), Status Bar, list, text, line editor, dialog, Toast widgets, Notifier (Toast + beep + LED), vendored public-domain Latin-1 fonts - Apps: minimal Launcher, Widget demo, Diagnostics (SD erase now behind a confirmation dialog) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#include "list_model.h"
|
|
|
|
namespace roro {
|
|
|
|
void ListModel::setCount(int count) {
|
|
count_ = count < 0 ? 0 : count;
|
|
if (count_ == 0) {
|
|
selected_ = -1;
|
|
first_ = 0;
|
|
return;
|
|
}
|
|
select(selected_ < 0 ? 0 : selected_);
|
|
}
|
|
|
|
void ListModel::select(int index) {
|
|
if (count_ == 0) return;
|
|
selected_ = index < 0 ? 0 : index >= count_ ? count_ - 1 : index;
|
|
scrollToSelection();
|
|
}
|
|
|
|
void ListModel::up() {
|
|
if (count_ == 0) return;
|
|
select(selected_ == 0 ? count_ - 1 : selected_ - 1);
|
|
}
|
|
|
|
void ListModel::down() {
|
|
if (count_ == 0) return;
|
|
select(selected_ == count_ - 1 ? 0 : selected_ + 1);
|
|
}
|
|
|
|
void ListModel::pageUp() { select(selected_ - rows_); }
|
|
void ListModel::pageDown() { select(selected_ + rows_); }
|
|
|
|
void ListModel::scrollToSelection() {
|
|
if (selected_ < first_) first_ = selected_;
|
|
if (selected_ >= first_ + rows_) first_ = selected_ - rows_ + 1;
|
|
int maxFirst = count_ > rows_ ? count_ - rows_ : 0;
|
|
if (first_ > maxFirst) first_ = maxFirst;
|
|
}
|
|
|
|
} // namespace roro
|