Files
alan 98cdf63079 Prevent floating window content rebuilds
Keep window content scope independent from frame changes, and retain the page theme and root page across layer rebuilds. Add repaint boundaries and regression coverage so dragging and resizing avoid unrelated content work while content changes still propagate.
2026-11-11 02:05:30 +00:00

55 lines
1.8 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'window_entry.dart';
import 'window_manager.dart';
/// The floating window some content is in: its entry and the manager. Absent
/// outside a window, so shared content can tell the tiled app from a window.
///
/// Content depends on what it can read of the entry, not on where the window
/// is drawn: moving, resizing, minimising or maximising a window keeps its
/// content as it is.
class WindowScope extends InheritedWidget {
const WindowScope({
super.key,
required this.manager,
required this.entry,
required super.child,
});
final WindowManager manager;
final WindowEntry entry;
static WindowScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<WindowScope>();
static WindowScope of(BuildContext context) => maybeOf(context)!;
@override
bool updateShouldNotify(WindowScope oldWidget) =>
oldWidget.manager != manager ||
oldWidget.entry.id != entry.id ||
oldWidget.entry.kind != entry.kind ||
oldWidget.entry.contentId != entry.contentId ||
oldWidget.entry.serverKey != entry.serverKey ||
!mapEquals(oldWidget.entry.data, entry.data);
}
/// Where a window's content area is drawn in the window host. Kept apart from
/// [WindowScope] so a move or a resize repositions the page without rebuilding
/// what the page shows.
class WindowBodyScope extends InheritedWidget {
const WindowBodyScope({super.key, required this.body, required super.child});
/// The content area (the window less its title bar), in the host's
/// coordinates.
final Rect body;
static Rect? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<WindowBodyScope>()?.body;
@override
bool updateShouldNotify(WindowBodyScope oldWidget) => oldWidget.body != body;
}