Skip to content

Commit 3772f17

Browse files
committed
Show the moved and resized events in the window example
The example already logged focus and the state changes; moved and resized now fire too (core 26963d86), and they are the two that arrive in a stream while a window is dragged. Log entries carrying the same tag replace the previous one, so a drag leaves a single updating line instead of flooding the list.
1 parent 6fcf5a2 commit 3772f17

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

‎examples/window_example/lib/main.dart‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ class _LogEntry {
3131
final DateTime timestamp = DateTime.now();
3232
final String message;
3333
final Color color;
34+
final String? replaceTag;
3435

35-
_LogEntry(this.message, {this.color = Colors.black87});
36+
_LogEntry(this.message, {this.color = Colors.black87, this.replaceTag});
3637

3738
String get formattedTime {
3839
final m = timestamp.minute.toString().padLeft(2, '0');
@@ -113,9 +114,23 @@ class _WindowManagerPageState extends State<WindowManagerPage>
113114

114115
Color _feedbackColor = Colors.green;
115116

116-
void _addLog(String message, {Color color = Colors.black87}) {
117+
/// [replaceTag] keeps a stream of events (a window being dragged or resized)
118+
/// on one line: an entry replaces the newest one when it carries the same tag.
119+
void _addLog(
120+
String message, {
121+
Color color = Colors.black87,
122+
String? replaceTag,
123+
}) {
117124
setState(() {
118-
_eventLog.insert(0, _LogEntry(message, color: color));
125+
if (replaceTag != null &&
126+
_eventLog.isNotEmpty &&
127+
_eventLog.first.replaceTag == replaceTag) {
128+
_eventLog.removeAt(0);
129+
}
130+
_eventLog.insert(
131+
0,
132+
_LogEntry(message, color: color, replaceTag: replaceTag),
133+
);
119134
if (_eventLog.length > _maxLogEntries) {
120135
_eventLog.removeLast();
121136
}
@@ -152,6 +167,22 @@ class _WindowManagerPageState extends State<WindowManagerPage>
152167
_addLog('Window #${event.windowId} restored');
153168
_updateWindows();
154169
}
170+
if (event is WindowMovedEvent) {
171+
final p = event.newPosition;
172+
_addLog(
173+
'Window #${event.windowId} moved to '
174+
'${p.dx.round()}, ${p.dy.round()}',
175+
replaceTag: 'moved-${event.windowId}',
176+
);
177+
}
178+
if (event is WindowResizedEvent) {
179+
final s = event.newSize;
180+
_addLog(
181+
'Window #${event.windowId} resized to '
182+
'${s.width.round()} x ${s.height.round()}',
183+
replaceTag: 'resized-${event.windowId}',
184+
);
185+
}
155186
}),
156187
);
157188
}

0 commit comments

Comments
 (0)