import 'package:flutter/widgets.dart'; import 'window_entry.dart'; /// One action in a window's title bar, before Minimise and Close (Dock on a /// chat, a kind's own menu). class WindowAction { const WindowAction({ required this.label, required this.icon, required this.onPressed, }); /// The tooltip and semantics label. final String label; final IconData icon; final VoidCallback onPressed; } /// What a kind of window is: how its content is built, titled and saved. /// Kinds register once at app start (see [WindowKinds]); the host and the /// manager know nothing else about a window's content. abstract class WindowKind { const WindowKind(); /// Stable identifier, saved with each window. String get key; /// Whether this kind's windows belong to one server (a chat) rather than /// the device (the terminal). bool get serverScoped; Size get minSize => const Size(320, 240); /// The frame of this kind's first window; later ones cascade from it. Rect get defaultFrame => const Rect.fromLTWH(120, 96, 480, 560); IconData get icon; String title(BuildContext context, WindowEntry entry); /// The window's content, below the title bar. Widget build(BuildContext context, WindowEntry entry); /// Title-bar actions before Minimise and Close. List actions(BuildContext context, WindowEntry entry) => const []; /// Notifies when a title or the actions of this kind's windows change. Listenable? get changes => null; /// The narrowest app this kind's windows show in; below it they hide (and /// come back when the app widens). double get minHostWidth => 0; /// Puts the keyboard where [entry]'s content wants it (a chat's composer) /// as its window takes focus. The default leaves it on the window. void focusContent(WindowEntry entry) {} /// Called after the user closes the window (the X). void closed(WindowEntry entry) {} /// Validates a saved window's [WindowEntry.data]; null drops the window. /// The default keeps no state. Map? decodeData(Object? raw) => const {}; /// What is saved for [entry] besides its identity and frame. Object? encodeData(WindowEntry entry) => null; } /// The registered window kinds, by key. class WindowKinds { final Map _kinds = {}; void register(WindowKind kind) { assert(!_kinds.containsKey(kind.key), 'window kind ${kind.key} twice'); _kinds[kind.key] = kind; } void unregister(String key) => _kinds.remove(key); WindowKind? operator [](String key) => _kinds[key]; Iterable get all => _kinds.values; }