#pragma once // Spec: SPEC.md UX-HOST-01. Modal presentations: alerts, confirmation dialogs, sheets, full screen covers, // popup menus and toasts. One global stack, drawn above the app tree. #include #include #include #include #include "ui/Navigation.hpp" #include "ui/TextInput.hpp" namespace dp::ui { struct AlertButton { enum class Role { Normal, Cancel, Destructive }; std::string title; Role role = Role::Normal; std::function action; }; struct AlertField { std::string placeholder; bool secure = false; std::shared_ptr text = std::make_shared(); }; struct AlertSpec { std::string title; std::string message; std::vector buttons; std::vector fields; }; struct MenuItem { std::string title; std::string icon; // optional symbol bool destructive = false; bool checked = false; std::function action; }; enum class SheetStyle { Sheet, FullScreen }; class Overlays { public: static Overlays& instance(); void alert(AlertSpec spec); // Bottom action sheet (SwiftUI confirmationDialog). void confirmationDialog(std::string title, std::string message, std::vector buttons); void sheet(ScreenPtr root, SheetStyle style = SheetStyle::Sheet, std::function onDismiss = nullptr); void menu(Rect anchor, std::vector items); // Popover card anchored to a rect; the builder runs every frame. void popover(Rect anchor, Size size, std::function builder); void toast(std::string text); // Close the topmost presentation (Escape, Done). Returns false when nothing was open. bool dismissTop(); // Close the sheet that hosts `screen` (screens call this from their own buttons). void dismissSheetContaining(const Screen* screen); bool any() const { return !entries_.empty(); } bool busy() const; void clear(); ViewPtr view(Size window); private: struct Entry { enum class Kind { Alert, Dialog, Sheet, Menu, Popover } kind = Kind::Alert; std::function builder; Size popSize; AlertSpec alert; std::vector items; Rect anchor; std::shared_ptr nav; SheetStyle style = SheetStyle::Sheet; std::function onDismiss; double start = 0; double closeStart = -1; bool fieldsFocused = false; std::vector> handles; }; struct Toast { std::string text; double start = 0; }; ViewPtr alertView(Entry& e); ViewPtr dialogView(Entry& e); ViewPtr sheetView(Entry& e, Size window); ViewPtr menuView(Entry& e, Size window); ViewPtr popoverView(Entry& e, Size window); void close(std::size_t index); std::vector> entries_; std::vector toasts_; }; } // namespace dp::ui