715efab778
Phase 1.2 of docs/plans/floating-windows.md: an app-lifetime WindowManager with ordered WindowEntry values, a WindowKind registry and a device-local versioned WindowStore whose server-scoped entries carry their server key. Nothing uses it yet.
75 lines
2.1 KiB
Dart
75 lines
2.1 KiB
Dart
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<WindowAction> actions(BuildContext context, WindowEntry entry) =>
|
|
const [];
|
|
|
|
/// 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<String, Object?>? 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<String, WindowKind> _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<WindowKind> get all => _kinds.values;
|
|
}
|