Files
roro9stack/lib/ui/src/dialog_model.h
T
twislaandClaude Opus 5.5 879cb0d0b6 Add widget kit, input layer with Compose Key, Launcher and demo apps
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
2026-10-02 10:35:48 +02:00

45 lines
1.3 KiB
C++

#pragma once
#include <string>
#include <vector>
#include "key_event.h"
namespace roro {
// A modal choice between buttons. The first button should be the safe one (e.g. "Cancel"):
// it's highlighted initially, and Back always cancels.
class DialogModel {
public:
static constexpr int kPending = -1;
static constexpr int kCancelled = -2;
explicit DialogModel(std::vector<std::string> buttons) : buttons_(std::move(buttons)) {}
// Consumes every key while open.
bool onKey(const KeyEvent& e) {
if (result_ != kPending) return true;
int last = static_cast<int>(buttons_.size()) - 1;
switch (e.key) {
case Key::Left: if (selected_ > 0) selected_--; break;
case Key::Right: if (selected_ < last) selected_++; break;
case Key::Tab: selected_ = selected_ == last ? 0 : selected_ + 1; break;
case Key::Select: result_ = selected_; break;
case Key::Back: result_ = kCancelled; break;
default: break;
}
return true;
}
const std::vector<std::string>& buttons() const { return buttons_; }
int selected() const { return selected_; }
int result() const { return result_; }
private:
std::vector<std::string> buttons_;
int selected_ = 0;
int result_ = kPending;
};
} // namespace roro