e4f3ebdcab
Remove the separate minimise control and make the title-bar X hide windows while preserving their state and reachability. Update window behavior documentation and focused tests for chat, terminal, and window layering.
86 lines
2.6 KiB
Dart
86 lines
2.6 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'window_entry.dart';
|
|
|
|
/// One action in a window's title bar, before Maximise and the X (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 Maximise and the X.
|
|
List<WindowAction> 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 window is closed (Dock, Close all, a chat's /close).
|
|
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;
|
|
}
|