Files
roro9stack/src/apps/setup_app.cpp
T
twislaandClaude Opus 5.5 34e6714785
CI / build (pull_request) Successful in 7m14s
Site / build (pull_request) Successful in 8s
Keys: one table file for the device's help panel and the website's key tables (#72)
Every screen's keys are constant tables in lib/core/src/app_keys.h (52 of
them, each under an `// id: Title` comment). An App's help() picks the table
of the state it is in. site/tools/gen_dev_docs.py reads the same file and
writes site/data/keys.toml; the `keys` shortcode shows a screen's tables on
its guide page, and /guide/keys/ shows all of them.

The Site job fails when the data file is out of date or a page asks for a
table that doesn't exist, and now also runs when app_keys.h changes. A key
added to an App shows up on the website without anyone editing a page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-07 01:42:48 +02:00

116 lines
4.9 KiB
C++

#include "app_keys.h"
#include "setup_app.h"
#include "platform/identity.h"
#include "ui/fonts.h"
#include "ui/widgets.h"
namespace roro {
using Step = SetupWizard::Step;
SetupApp::SetupApp(Settings& settings, AppManager& apps)
: apps_(apps), wizard_(settings, identity::defaultLongName(), identity::defaultShortName()) {}
bool SetupApp::onKey(const KeyEvent& e) {
requestRedraw();
bool choosing = wizard_.choiceCount() > 0;
bool typing = wizard_.step() == Step::LongName || wizard_.step() == Step::ShortName;
switch (e.key) {
case Key::Select:
if (choosing) wizard_.selectChoice(choices_.selected());
if (wizard_.next()) {
if (wizard_.finished()) {
apps_.endModal();
return true;
}
choices_.setCount(wizard_.choiceCount());
if (wizard_.choiceCount()) choices_.select(wizard_.selectedChoice());
}
break;
case Key::Back:
case Key::Home:
wizard_.back();
choices_.setCount(wizard_.choiceCount());
if (wizard_.choiceCount()) choices_.select(wizard_.selectedChoice());
break;
case Key::Up: if (choosing) choices_.up(); break;
case Key::Down: if (choosing) choices_.down(); break;
case Key::Left: if (typing) wizard_.editor().left(); break;
case Key::Right: if (typing) wizard_.editor().right(); break;
case Key::Delete: if (typing) wizard_.editor().backspace(); break;
case Key::Char: if (typing) wizard_.editor().insert(e.ch); break;
default: break;
}
return true;
}
void SetupApp::help(std::vector<KeyHelp>& out) const {
switch (wizard_.step()) {
case Step::LongName:
case Step::ShortName: keys::add(out, keys::kSetupText); break;
case Step::Region:
case Step::Timezone: keys::add(out, keys::kSetupChoice); break;
default: keys::add(out, keys::kSetup); break;
}
}
// The one place that names keys on the screen (Q200): someone in their first minute doesn't know
// the help key yet, and this is where they learn it.
void SetupApp::draw(Canvas& c) {
const auto& area = theme::kContent;
auto heading = [&](const char* text) {
c.setFont(&fonts::bold);
c.setTextColor(theme::kAccent);
c.drawString(text, 4, area.y + 3);
c.setFont(&fonts::body);
};
auto note = [&](const std::string& text, int y, uint16_t color = theme::kMuted) {
auto lines = wrapText(text, area.w - 8, widgets::bodyMeasure(c));
c.setTextColor(color);
for (size_t i = 0; i < lines.size(); i++) c.drawString(lines[i].c_str(), 4, y + i * theme::kLineHeight);
};
switch (wizard_.step()) {
case Step::Welcome:
heading("Welcome to roro9stack");
note("Let's set up this device: your names on the mesh, your radio region and your timezone.",
area.y + 22, theme::kText);
note("One key to know: Fn + h lists the keys of the screen you're on.", area.y + 22 + 4 * theme::kLineHeight, theme::kAccent);
note("Enter: continue", area.y + area.h - 14);
break;
case Step::LongName:
heading("Long name (1/4)");
note("Shown to other mesh users. Up to 39 bytes.", area.y + 20);
widgets::lineEditor(c, wizard_.editor(), {4, area.y + 50, area.w - 8, 0});
break;
case Step::ShortName:
heading("Short name (2/4)");
note("Up to 4 characters, shown where space is tight.", area.y + 20);
widgets::lineEditor(c, wizard_.editor(), {4, area.y + 50, area.w - 8, 0});
break;
case Step::Region:
heading("Radio region (3/4)");
note("The radio only transmits once you confirm your region.", area.y + 18);
widgets::list(c, choices_, {0, area.y + 48, area.w, 4 * theme::kLineHeight},
[this](int i) { return wizard_.choiceLabel(i); });
note("Enter: I confirm I'm in this region", area.y + area.h - 14);
break;
case Step::Timezone:
heading("Timezone (4/4)");
widgets::list(c, choices_, {0, area.y + 20, area.w, 4 * theme::kLineHeight},
[this](int i) { return wizard_.choiceLabel(i); });
break;
case Step::Done:
heading("All set. One key to remember:");
note("Fn + h, on any screen, lists the keys that work there. No screen names its keys: that key does. Try it now.",
area.y + 22, theme::kAccent);
note("The rest can be changed later in Settings.", area.y + 22 + 4 * theme::kLineHeight, theme::kText);
note("Enter: start `: go back", area.y + area.h - 14);
break;
}
if (!wizard_.error().empty()) note(wizard_.error(), area.y + area.h - 14, theme::kWarning);
}
} // namespace roro