50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
#pragma once
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace evo::client {
|
|
enum class UiError : std::uint8_t { invalid, stale_time, busy, exhausted };
|
|
enum class NoticeLevel : std::uint8_t { info, warning, error };
|
|
struct Notice {
|
|
std::uint64_t id{}, expires_at_ms{};
|
|
NoticeLevel level{};
|
|
std::string text;
|
|
};
|
|
struct Dialog {
|
|
std::uint64_t id{};
|
|
std::string title, body;
|
|
};
|
|
// Main-thread, bounded presentation state. Never store credentials or authority here.
|
|
class UiState {
|
|
public:
|
|
static constexpr std::size_t max_notices = 8, max_text = 240, max_title = 96;
|
|
[[nodiscard]] std::expected<void, UiError> advance(std::uint64_t now_ms);
|
|
[[nodiscard]] std::expected<std::uint64_t, UiError>
|
|
notify(std::string_view text, NoticeLevel level, std::uint64_t lifetime_ms = 5000);
|
|
[[nodiscard]] bool dismiss(std::uint64_t id);
|
|
[[nodiscard]] std::expected<std::uint64_t, UiError> open_dialog(std::string_view title,
|
|
std::string_view body);
|
|
[[nodiscard]] bool close_dialog(std::uint64_t id);
|
|
[[nodiscard]] std::span<const Notice> notices() const noexcept {
|
|
return notices_;
|
|
}
|
|
[[nodiscard]] const std::optional<Dialog>& dialog() const noexcept {
|
|
return dialog_;
|
|
}
|
|
[[nodiscard]] std::uint64_t evicted_notices() const noexcept {
|
|
return evicted_;
|
|
}
|
|
|
|
private:
|
|
std::uint64_t now_{}, next_id_{1}, evicted_{};
|
|
std::vector<Notice> notices_;
|
|
std::optional<Dialog> dialog_;
|
|
};
|
|
} // namespace evo::client
|