diff --git a/lib/core/window_chrome.dart b/lib/core/window_chrome.dart index 2a63ab2..b92ef68 100644 --- a/lib/core/window_chrome.dart +++ b/lib/core/window_chrome.dart @@ -20,15 +20,4 @@ class WindowChrome { /// True where the OS draws window controls over the app's own content. static bool get overlaysContent => AppPlatform.isMacOS; - - /// Inset for a pane flush against the window's left edge that wants to keep - /// its content beside the window controls. - static double leadingInset({required bool atWindowLeftEdge}) => - overlaysContent && atWindowLeftEdge ? trafficLightsWidth : 0; - - /// Inset for a pane flush against the window's left edge that would rather - /// keep its content below the window controls. Taller panes prefer this; - /// a single-row toolbar has no room and uses [leadingInset] instead. - static double topInset({required bool atWindowLeftEdge}) => - overlaysContent && atWindowLeftEdge ? trafficLightsHeight : 0; } diff --git a/lib/data/layout_prefs.dart b/lib/data/layout_prefs.dart index 87663d2..bf72f4a 100644 --- a/lib/data/layout_prefs.dart +++ b/lib/data/layout_prefs.dart @@ -81,7 +81,11 @@ DigitGrouping _autoGrouping(Locale locale, String? region) { /// behaves once its window is closed. class LayoutPrefs extends ChangeNotifier { static const Size defaultWindowSize = Size(600, 720); - static const Size minimumWindowSize = Size(520, 360); + + /// The smallest window that still holds the spaces rail and a page: tall + /// enough for the rail with every space, the streak and the account on it, + /// and wide enough for the page's toolbar beside the rail. + static const Size minimumWindowSize = Size(520, 520); static const double minGutterWidth = 72; static const double maxGutterWidth = 480; diff --git a/lib/ui/home_page.dart b/lib/ui/home_page.dart index e0ef4a9..c88f830 100644 --- a/lib/ui/home_page.dart +++ b/lib/ui/home_page.dart @@ -73,8 +73,9 @@ import 'window_drag_area.dart'; import 'draw/drawing_canvas.dart'; import 'draw/note_mode_switch.dart'; -/// Width at which the two-pane desktop layout gives way to the compact editor -/// with a notes drawer. Mobile platforms always use the compact layout. +/// The narrowest window that holds the notes list beside the page. Below it a +/// phone switches to the compact editor with a notes drawer, while a desktop +/// window keeps the rail and the page and opens the list over the page. const double kTwoPaneBreakpoint = 720; class HomePage extends StatefulWidget { @@ -222,6 +223,11 @@ class _HomePageState extends State with WidgetsBindingObserver { bool _openSessionScheduled = false; bool _drawerContentReady = false; bool _drawerOpen = false; + + /// Whether the notes list is open over the page, in a desktop window too + /// narrow to hold it beside the page. See [_setListShown]. + bool _listOverlaid = false; + bool _settingsOpen = false; bool _archiveMode = false; bool _hiddenMode = false; @@ -379,16 +385,22 @@ class _HomePageState extends State with WidgetsBindingObserver { if (mounted && _drawingsOnly && _usesCompactLayout) { setState(() => _drawingsOnly = false); } - // An open compact drawer is disposed when a desktop window crosses into - // the two-pane layout. Scaffold cannot report a closing transition after - // that disposal, so clear the transient flag here. Otherwise returning to - // a compact width builds a closed drawer whose toolbar still hides every - // edge action. + // An open compact drawer is disposed when a phone turns or a tablet's + // window widens into the two-pane layout. Scaffold cannot report a closing + // transition after that disposal, so clear the transient flag here. + // Otherwise returning to a compact width builds a closed drawer whose + // toolbar still hides every edge action. if (mounted && _drawerOpen && !_usesCompactLayout) { setState(() => _drawerOpen = false); } - // A narrow window shows only the focused pane's note. An empty pane has - // none, so focus a pane that does rather than show nothing at all. + // A list opened over the page stays open as the window widens, beside the + // page now that there is room for it. + if (mounted && _listOverlaid && _listFits) { + setState(() => _listOverlaid = false); + if (!widget.prefs.sidebarVisible) widget.prefs.toggleSidebar(); + } + // A phone shows only the focused pane's note. An empty pane has none, so + // focus a pane that does rather than show nothing at all. if (mounted && !_specialMode && _usesCompactLayout && @@ -1007,10 +1019,55 @@ class _HomePageState extends State with WidgetsBindingObserver { if (available.isEmpty && _usesCompactLayout) _scheduleInitialNote(); } - /// Read from the window because selection is also reconciled outside build. - bool get _usesCompactLayout { + /// Only a phone has a compact layout: a desktop window of any width keeps + /// the rail and the page. + bool get _usesCompactLayout => AppPlatform.isMobile && !_listFits; + + /// Whether the window holds the notes list beside the page. Read from the + /// window because selection is also reconciled, and the list shown, outside + /// build. + bool get _listFits { final view = WidgetsBinding.instance.platformDispatcher.views.first; - return view.physicalSize.width / view.devicePixelRatio < kTwoPaneBreakpoint; + return view.physicalSize.width / view.devicePixelRatio >= + kTwoPaneBreakpoint; + } + + /// Whether the notes list is on screen, beside the page or over it. + bool get _listShown => + _listFits ? widget.prefs.sidebarVisible : _listOverlaid; + + /// Shows or hides the notes list in the wide layout. Every control that does + /// either comes through here: the shortcut, the toolbar's button, the list's + /// own hide button and divider, a sideways swipe, an empty pane, and Find + /// notes. + /// + /// Where the window has room, the list stands beside the page and the + /// choice is [LayoutPrefs.sidebarVisible], which the settings switch shows. + /// Where it has not, the list opens over the page and takes the keyboard + /// into its search field, so nothing typed lands in the note it covers, and + /// closing it gives the keyboard back to the note. + void _setListShown(bool shown) { + if (_listFits) { + if (widget.prefs.sidebarVisible != shown) widget.prefs.toggleSidebar(); + return; + } + if (shown == _listOverlaid) return; + setState(() => _listOverlaid = shown); + if (!shown) { + _focusSelectedEditorHere(); + return; + } + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) _searchFocus.requestFocus(); + }); + } + + void _toggleList() => _setListShown(!_listShown); + + /// Puts away a list open over the page once a note is chosen from it. A + /// list beside the page stays where it is. + void _dismissListOverlay() { + if (_listOverlaid) _setListShown(false); } void _setSelectedId(String? id, {bool selectionPreview = false}) { @@ -1209,7 +1266,17 @@ class _HomePageState extends State with WidgetsBindingObserver { }); } - void _selectFromSidebar(String id) => _select(id, focusEditor: false); + /// A press on a row. Beside the page the keyboard stays in the list, for + /// the arrows to walk on from there; over the page the note opens and the + /// list goes. + void _selectFromSidebar(String id) { + if (!_listOverlaid) { + _select(id, focusEditor: false); + return; + } + _dismissListOverlay(); + _select(id); + } void _previewFromSidebar(String id) => _select(id, focusEditor: false, selectionPreview: true); @@ -1264,6 +1331,7 @@ class _HomePageState extends State with WidgetsBindingObserver { void _openNoteToSide(String id) { if (_usesCompactLayout || _specialMode) return; + _dismissListOverlay(); _afterRecordingLeaves( _workspace.displacedByOpenToSide(id), () => _openNoteToSideNow(id), @@ -1484,6 +1552,8 @@ class _HomePageState extends State with WidgetsBindingObserver { // it being written. _sidebarTab = SidebarTab.mine; _drawingsOnly = false; + // And it is written on the page, so a list open over the page goes. + _listOverlaid = false; _setSelectedId(note.id); }); widget.prefs.lastOpenedNoteId = note.id; @@ -2236,6 +2306,7 @@ class _HomePageState extends State with WidgetsBindingObserver { /// already mounted and can take the caret immediately. Unlike the deferred /// helper above, this does not depend on another frame being scheduled. void _enterSelectedEditorFromSidebar() { + _dismissListOverlay(); if (_editorFocusSuppressed || (_selectedId != null && _selectedId == _untouchedWelcomeId)) { return; @@ -2266,7 +2337,7 @@ class _HomePageState extends State with WidgetsBindingObserver { void _focusGlobalSearch() { _recordKapyActivity(); if (!_usesCompactLayout) { - if (!widget.prefs.sidebarVisible) widget.prefs.toggleSidebar(); + _setListShown(true); WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) _searchFocus.requestFocus(); }); @@ -2396,16 +2467,13 @@ class _HomePageState extends State with WidgetsBindingObserver { // golden harness captures this boundary directly. return LayoutBuilder( builder: (context, constraints) { - final compact = constraints.maxWidth < kTwoPaneBreakpoint; + final compact = + AppPlatform.isMobile && constraints.maxWidth < kTwoPaneBreakpoint; final page = compact ? _buildCompact(context) : _buildWide(context); final gesturePage = AppPlatform.isDesktop ? SidebarSwipe( - sidebarVisible: compact - ? _drawerOpen - : widget.prefs.sidebarVisible, - onToggle: compact - ? _toggleCompactSidebarFromTrackpad - : widget.prefs.toggleSidebar, + sidebarVisible: _listShown, + onToggle: _toggleList, child: page, ) : page; @@ -2425,17 +2493,17 @@ class _HomePageState extends State with WidgetsBindingObserver { onFindNotes: _focusGlobalSearch, onNextNote: () => _cycleNote(1), onPreviousNote: () => _cycleNote(-1), - onSplitEditor: compact || _specialMode || !_workspace.canSplit + onSplitEditor: _specialMode || !_workspace.canSplit ? null : _splitEditor, // Unbound with a single pane, so the chord closes nothing at all // rather than something the reader did not mean it to. - onClosePane: compact || _specialMode || !_workspace.isSplit + onClosePane: _specialMode || !_workspace.isSplit ? null : () => _closePane(_workspace.activePane), onFocusPane: [ for (var index = 0; index < EditorWorkspace.maxPanes; index++) - compact || _specialMode || index >= _workspace.paneCount + _specialMode || index >= _workspace.paneCount ? null : () => _focusPane(index), ], @@ -2447,9 +2515,7 @@ class _HomePageState extends State with WidgetsBindingObserver { _selectedEditor?.pickAndInsertImages() ?? Future.value(), ), onRecordVoice: () => unawaited(_startVoiceRecording()), - onToggleSidebar: compact - ? _toggleCompactSidebarFromTrackpad - : widget.prefs.toggleSidebar, + onToggleSidebar: _toggleList, onToggleHiddenFolder: _toggleHiddenFolderVisibility, onToggleResults: widget.prefs.toggleResults, onToggleAlwaysOnTop: AppPlatform.isDesktop @@ -2464,17 +2530,6 @@ class _HomePageState extends State with WidgetsBindingObserver { ); } - void _toggleCompactSidebarFromTrackpad() { - final scaffold = _scaffoldKey.currentState; - if (scaffold == null) return; - if (scaffold.isDrawerOpen) { - scaffold.closeDrawer(); - return; - } - FocusManager.instance.primaryFocus?.unfocus(); - scaffold.openDrawer(); - } - Widget _buildWide(BuildContext context) { final selected = widget.notes.byId(_selectedId); // A tablet reaches this layout too, and it has no Scaffold to resize @@ -2500,7 +2555,8 @@ class _HomePageState extends State with WidgetsBindingObserver { listenable: _toolbarSources, builder: (context, _) { final space = _space; - final sidebarVisible = widget.prefs.sidebarVisible; + final listFits = _listFits; + final listShown = _listShown; return Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -2529,13 +2585,14 @@ class _HomePageState extends State with WidgetsBindingObserver { ), Expanded( child: SplitView( - sidebarVisible: sidebarVisible, + sidebarVisible: listShown, + overlay: !listFits, sidebarWidth: widget.prefs.sidebarWidth, minSidebarWidth: LayoutPrefs.minSidebarWidth, maxSidebarWidth: LayoutPrefs.maxSidebarWidth, onWidthChanged: (value) => widget.prefs.sidebarWidth = value, - onHide: widget.prefs.toggleSidebar, + onHide: () => _setListShown(false), sidebar: Sidebar( notes: _visibleNotes, pinnedNoteIds: widget.notes.pinnedNoteIds, @@ -2610,7 +2667,7 @@ class _HomePageState extends State with WidgetsBindingObserver { newNoteShortcut: widget.shortcuts.bindingFor( ShortcutAction.newNote, ), - onHide: widget.prefs.toggleSidebar, + onHide: () => _setListShown(false), hideShortcut: widget.shortcuts.bindingFor( ShortcutAction.toggleSidebar, ), @@ -2636,7 +2693,7 @@ class _HomePageState extends State with WidgetsBindingObserver { duration: const Duration(milliseconds: 160), curve: Curves.easeOutCubic, padding: EdgeInsets.fromLTRB( - sidebarVisible ? 0 : pageInset, + listFits && listShown ? 0 : pageInset, pageInset, pageInset, pageInset, @@ -2646,9 +2703,9 @@ class _HomePageState extends State with WidgetsBindingObserver { children: [ NoteToolbar( mascotController: _kapyHeader, - sidebarVisible: sidebarVisible, + sidebarVisible: listShown, sidebarShortcut: _sidebarShortcut, - onToggleSidebar: widget.prefs.toggleSidebar, + onToggleSidebar: _toggleList, onCreate: _createNote, onShare: _shareSelected, members: _selectedMembers, @@ -2664,7 +2721,6 @@ class _HomePageState extends State with WidgetsBindingObserver { : _splitEditor, splitTooltip: _splitTooltip, updates: widget.updates, - atWindowLeftEdge: false, ), Expanded(child: _buildWideWorkspace()), ], @@ -2736,9 +2792,7 @@ class _HomePageState extends State with WidgetsBindingObserver { body = EmptyPane( active: active, onCreate: _createNote, - onShowNotes: widget.prefs.sidebarVisible - ? null - : widget.prefs.toggleSidebar, + onShowNotes: _listShown ? null : () => _setListShown(true), ); } else { body = EmptyState(onCreate: _createNote); @@ -2773,10 +2827,6 @@ class _HomePageState extends State with WidgetsBindingObserver { 0.0, 360.0, ); - // Narrow desktop windows retain Flutter's draggable edge. Phones use the - // full-page observer below, which can begin anywhere without taking the - // editor's vertical-scroll or text-selection gestures away from it. - final drawerEdgeDragWidth = MediaQuery.sizeOf(context).width / 3; final overlayStyle = Theme.of(context).brightness == Brightness.dark ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark; @@ -2790,10 +2840,10 @@ class _HomePageState extends State with WidgetsBindingObserver { backgroundColor: palette.isGlass ? Colors.transparent : palette.editorBackground, - // Not over a drawing, where a stroke from the left edge is a stroke. - drawerEnableOpenDragGesture: - !AppPlatform.isMobile && !(selected?.isDrawing ?? false), - drawerEdgeDragWidth: drawerEdgeDragWidth, + // The full-page observer below opens it instead, from anywhere and + // without taking the editor's vertical-scroll or text-selection + // gestures away from it. + drawerEnableOpenDragGesture: false, onDrawerChanged: (isOpen) { setState(() { _drawerOpen = isOpen; @@ -2856,7 +2906,6 @@ class _HomePageState extends State with WidgetsBindingObserver { onRestoreChecked: _restoreChecked, archivedCount: widget.notes.archivedNotes.length, hiddenCount: widget.notes.hiddenNotes.length, - showHiddenFolder: widget.prefs.hiddenFolderVisible, streak: widget.notes.streak, onShare: widget.account == null ? null : _shareNote, sharing: widget.account?.sharing, @@ -2877,9 +2926,6 @@ class _HomePageState extends State with WidgetsBindingObserver { archiveShortcut: widget.shortcuts.bindingFor( ShortcutAction.deleteNote, ), - hiddenShortcut: widget.shortcuts.bindingFor( - ShortcutAction.toggleHiddenFolder, - ), updates: widget.updates, ), ), @@ -2942,7 +2988,6 @@ class _HomePageState extends State with WidgetsBindingObserver { ), ); - if (!AppPlatform.isMobile) return compactPage; return MobilePageSwipe( enabled: !_drawerOpen, onOpenNotes: () { @@ -2955,15 +3000,6 @@ class _HomePageState extends State with WidgetsBindingObserver { } Widget _buildCompactEditor(Note note) { - // Narrow desktop windows still have a precise pointer and enough room for - // the results column to be resized. On Windows, the native minimum is an - // outer window size, so the Flutter client can be a few pixels narrower - // than that minimum. Platform capability is therefore the durable rule. - // Phones preserve the fixed mobile gutter, and wide phones get enough - // room for a grouped currency plus its three-letter code. - final compactWidth = MediaQuery.sizeOf(context).width; - final desktopResultsDivider = AppPlatform.isDesktop; - final mobileGutterWidth = compactWidth >= 400 ? 152.0 : 132.0; if (note.isDrawing) return _buildDrawing(note); final editor = ListenableBuilder( listenable: widget.engines, @@ -2990,13 +3026,11 @@ class _HomePageState extends State with WidgetsBindingObserver { initialFormats: note.formats, engine: widget.engines.engine, highlighter: widget.engines.highlighter, - gutterWidth: desktopResultsDivider - ? widget.prefs.gutterWidth - : mobileGutterWidth, - resultsVisible: desktopResultsDivider - ? widget.prefs.resultsVisible - : true, - showDivider: desktopResultsDivider, + // A phone keeps a fixed results column, and a wide phone gets + // enough of one for a grouped currency and its three-letter code. + gutterWidth: MediaQuery.sizeOf(context).width >= 400 ? 152 : 132, + resultsVisible: true, + showDivider: false, autofocus: _readyToTypeIn(note), startAtEnd: _readyToTypeIn(note), initialCaret: _resumeCaretIn(note), @@ -3035,15 +3069,9 @@ class _HomePageState extends State with WidgetsBindingObserver { onDocumentChanged: (body, formats, attachments) => _updateDocument(note.id, body, formats, attachments), storedDocument: () => _storedDocument(note.id), - onGutterWidthChanged: desktopResultsDivider - ? (value) => widget.prefs.gutterWidth = value - : (_) {}, - onResultsVisibilityChanged: desktopResultsDivider - ? (value) => widget.prefs.resultsVisible = value - : (_) {}, - onGutterWidthReset: desktopResultsDivider - ? widget.prefs.resetGutterWidth - : () {}, + onGutterWidthChanged: (_) {}, + onResultsVisibilityChanged: (_) {}, + onGutterWidthReset: () {}, onSettingsPressed: _showSettings, ), ), diff --git a/lib/ui/sidebar.dart b/lib/ui/sidebar.dart index 48a2597..8ae727c 100644 --- a/lib/ui/sidebar.dart +++ b/lib/ui/sidebar.dart @@ -119,14 +119,12 @@ class Sidebar extends StatelessWidget { this.searchShortcut, this.settingsShortcut, this.archiveShortcut, - this.hiddenShortcut, this.updates, this.searchFocusNode, this.archiveMode = false, this.hiddenMode = false, this.archivedCount = 0, this.hiddenCount = 0, - this.showHiddenFolder = false, this.onDelete, this.onDeleteAll, this.selecting = false, @@ -214,7 +212,6 @@ class Sidebar extends StatelessWidget { /// shortcut nobody can find is a shortcut nobody uses. Read from the /// binding rather than written out, so a rebound key is not misnamed here. final ShortcutBinding? archiveShortcut; - final ShortcutBinding? hiddenShortcut; /// Drives the Update badge beside the installed version. Null where the app /// store owns updates; the version still comes from the installed package. @@ -224,7 +221,6 @@ class Sidebar extends StatelessWidget { final bool hiddenMode; final int archivedCount; final int hiddenCount; - final bool showHiddenFolder; /// Throws one note away for good. Only ever supplied in the archive. final ValueChanged? onDelete; @@ -389,20 +385,12 @@ class Sidebar extends StatelessWidget { ), ), ), - if (onSettingsPressed != null || - onArchiveToggle != null || - _showDesktopHiddenEntry) + if (onSettingsPressed != null || onArchiveToggle != null) _SidebarFooter( onSettingsPressed: onSettingsPressed, onArchivePressed: onArchiveToggle, - onHiddenPressed: _showDesktopHiddenEntry - ? onHiddenToggle - : null, showingArchive: archiveMode, - showingHidden: hiddenMode, archivedCount: archivedCount, - hiddenCount: hiddenCount, - hiddenShortcut: hiddenShortcut, settingsShortcut: settingsShortcut, updates: updates, ), @@ -433,11 +421,6 @@ extension on Sidebar { bool get _showMobileHiddenEntry => AppPlatform.isMobile && onHiddenToggle != null && !_onSharedTab; - bool get _showDesktopHiddenEntry => - AppPlatform.isDesktop && - onHiddenToggle != null && - (hiddenMode || (showHiddenFolder && hiddenCount > 0)); - bool get _hasPinned => !_specialMode && notes.any((note) => pinnedNoteIds.contains(note.id)); @@ -1356,35 +1339,25 @@ class _SidebarFooter extends StatelessWidget { const _SidebarFooter({ this.onSettingsPressed, this.onArchivePressed, - this.onHiddenPressed, required this.showingArchive, - required this.showingHidden, required this.archivedCount, - required this.hiddenCount, - this.hiddenShortcut, this.settingsShortcut, this.updates, }); final VoidCallback? onSettingsPressed; final VoidCallback? onArchivePressed; - final VoidCallback? onHiddenPressed; final bool showingArchive; - final bool showingHidden; final int archivedCount; - final int hiddenCount; - final ShortcutBinding? hiddenShortcut; final ShortcutBinding? settingsShortcut; final UpdateChecker? updates; @override Widget build(BuildContext context) { final palette = context.palette; - final onHiddenPressed = this.onHiddenPressed; final onArchivePressed = this.onArchivePressed; final onSettingsPressed = this.onSettingsPressed; final rows = - (onHiddenPressed == null ? 0 : 1) + (onArchivePressed == null ? 0 : 1) + (onSettingsPressed == null ? 0 : 1); return Container( @@ -1394,15 +1367,6 @@ class _SidebarFooter extends StatelessWidget { ), child: Column( children: [ - if (onHiddenPressed != null) - Expanded( - child: _HiddenEntry( - showingHidden: showingHidden, - count: hiddenCount, - onPressed: onHiddenPressed, - shortcut: hiddenShortcut, - ), - ), if (onArchivePressed != null) Expanded( child: _ArchiveEntry( @@ -1435,21 +1399,18 @@ class _HiddenEntry extends StatelessWidget { required this.showingHidden, required this.count, required this.onPressed, - this.shortcut, }); final bool showingHidden; final int count; final VoidCallback onPressed; - final ShortcutBinding? shortcut; @override Widget build(BuildContext context) { final palette = context.palette; final label = showingHidden ? 'All notes' : 'Hidden Notes'; - final shortcut = this.shortcut; return Tooltip( - message: shortcut == null ? label : '$label · ${shortcut.displayLabel}', + message: label, child: Semantics( button: true, label: label, @@ -1479,7 +1440,7 @@ class _HiddenEntry extends StatelessWidget { ), ), ), - if (!showingHidden && count > 0) ...[ + if (!showingHidden && count > 0) Text( '$count', style: TextStyle( @@ -1487,9 +1448,6 @@ class _HiddenEntry extends StatelessWidget { color: palette.textTertiary, ), ), - if (shortcut != null) const SizedBox(width: 8), - ], - if (shortcut != null) _FolderShortcutHint(shortcut: shortcut), ], ), ), @@ -1499,36 +1457,6 @@ class _HiddenEntry extends StatelessWidget { } } -class _FolderShortcutHint extends StatelessWidget { - const _FolderShortcutHint({required this.shortcut}); - - final ShortcutBinding shortcut; - - @override - Widget build(BuildContext context) { - final palette = context.palette; - final label = shortcut.displayLabel; - return ExcludeSemantics( - child: Container( - padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2), - decoration: BoxDecoration( - color: palette.surfaceBackground.withMultipliedAlpha(0.42), - border: Border.all(color: palette.controlBorder, width: 0.5), - borderRadius: BorderRadius.circular(4), - ), - child: Text( - label, - style: TextStyle( - fontSize: AppPlatform.isWindows ? AppTypeScale.micro : 9.5, - height: AppPlatform.isWindows ? 1.1 : 1, - color: palette.textTertiary, - ), - ), - ), - ); - } -} - /// The strip above the archive: pick some notes, or empty the whole thing. /// /// Only ever in the archive. The main list has no delete at all — a note diff --git a/lib/ui/sidebar_swipe.dart b/lib/ui/sidebar_swipe.dart index 609fbf4..3460498 100644 --- a/lib/ui/sidebar_swipe.dart +++ b/lib/ui/sidebar_swipe.dart @@ -11,9 +11,9 @@ import 'package:material_ui/material_ui.dart'; /// field is how you select text, and taking it would cost more than the /// gesture is worth. A two-finger swipe conflicts with nothing. /// -/// Desktop keeps this observer above both responsive layouts, so the same -/// two-finger gesture works in wide and narrow windows. Touchscreen compact -/// layouts use their separate full-page swipe handling. +/// The desktop keeps this observer above the whole window, so the same +/// two-finger gesture opens the list beside the page in a wide window and over +/// it in a narrow one. A phone's compact layout has its own full-page swipe. class SidebarSwipe extends StatefulWidget { const SidebarSwipe({ super.key, diff --git a/lib/ui/split_view.dart b/lib/ui/split_view.dart index 54308b7..4cdc6e2 100644 --- a/lib/ui/split_view.dart +++ b/lib/ui/split_view.dart @@ -1,6 +1,10 @@ import 'package:material_ui/material_ui.dart'; -/// A two-pane layout whose divider the user can drag. +import '../core/theme.dart'; + +/// The notes list and the page: side by side, with a divider the user can +/// drag, where the window has room for both, and the list over the page where +/// it has not. /// /// The width is owned by the caller so it can be persisted. A drag moves the /// divider here and reports where it ended, so each frame of it lays the @@ -14,6 +18,7 @@ class SplitView extends StatefulWidget { required this.onWidthChanged, required this.onHide, required this.sidebarVisible, + this.overlay = false, this.minSidebarWidth = 150, this.maxSidebarWidth = 420, }); @@ -24,6 +29,12 @@ class SplitView extends StatefulWidget { final ValueChanged onWidthChanged; final VoidCallback onHide; final bool sidebarVisible; + + /// Whether the sidebar opens over the body rather than beside it, for a + /// window with no room for both. The body keeps its whole width, dimmed + /// behind the sidebar, and a click on it or Escape hides the sidebar again + /// through [onHide]. Nothing of the sidebar is built while it is hidden. + final bool overlay; final double minSidebarWidth; final double maxSidebarWidth; @@ -32,6 +43,13 @@ class SplitView extends StatefulWidget { } class _SplitViewState extends State { + /// The least of the body the sidebar leaves beside it. + static const double _minBodyWidth = 320; + + /// The least of the body an open overlay leaves in view, for the click that + /// closes it to land on. + static const double _minBodyInView = 48; + bool _hovering = false; /// Where the divider is while it is being dragged. @@ -48,19 +66,19 @@ class _SplitViewState extends State { @override Widget build(BuildContext context) { + final palette = context.palette; + final overlay = widget.overlay; + return LayoutBuilder( builder: (context, constraints) { + final room = + constraints.maxWidth - (overlay ? _minBodyInView : _minBodyWidth); double clamped(double value) => value.clamp( widget.minSidebarWidth, - widget.maxSidebarWidth.clamp( - widget.minSidebarWidth, - (constraints.maxWidth - 320).clamp( - widget.minSidebarWidth, - widget.maxSidebarWidth, - ), - ), + room.clamp(widget.minSidebarWidth, widget.maxSidebarWidth), ); final width = clamped(_dragWidth ?? widget.sidebarWidth); + final beside = widget.sidebarVisible && !overlay; return Stack( children: [ @@ -68,24 +86,27 @@ class _SplitViewState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - AnimatedContainer( - duration: const Duration(milliseconds: 160), - curve: Curves.easeOutCubic, - width: widget.sidebarVisible ? width : 0, - child: ClipRect( - child: OverflowBox( - alignment: Alignment.centerLeft, - minWidth: width, - maxWidth: width, - child: widget.sidebar, + // Slides open and shut, but comes and goes at once with the + // room for it, rather than squeezing the body as it goes. + if (!overlay) + AnimatedContainer( + duration: const Duration(milliseconds: 160), + curve: Curves.easeOutCubic, + width: beside ? width : 0, + child: ClipRect( + child: OverflowBox( + alignment: Alignment.centerLeft, + minWidth: width, + maxWidth: width, + child: widget.sidebar, + ), ), ), - ), Expanded(child: widget.body), ], ), ), - if (widget.sidebarVisible) + if (beside) Positioned( left: width - 7.5, top: 0, @@ -131,6 +152,37 @@ class _SplitViewState extends State { ), ), ), + if (overlay && widget.sidebarVisible) ...[ + Positioned.fill( + child: ModalBarrier( + key: const ValueKey('sidebar-overlay-barrier'), + color: palette.scrim, + onDismiss: widget.onHide, + ), + ), + Positioned( + left: 0, + top: 0, + bottom: 0, + width: width, + child: Actions( + actions: { + DismissIntent: CallbackAction( + onInvoke: (_) => widget.onHide(), + ), + }, + child: DecoratedBox( + position: DecorationPosition.foreground, + decoration: BoxDecoration( + border: Border( + right: BorderSide(color: palette.separator, width: 0.5), + ), + ), + child: widget.sidebar, + ), + ), + ), + ], ], ); }, diff --git a/lib/ui/toolbar.dart b/lib/ui/toolbar.dart index 093f95b..a439371 100644 --- a/lib/ui/toolbar.dart +++ b/lib/ui/toolbar.dart @@ -6,7 +6,6 @@ import 'package:material_ui/material_ui.dart'; import '../core/platform.dart'; import '../core/theme.dart'; import '../core/toast.dart'; -import '../core/window_chrome.dart'; import '../data/update_checker.dart'; import '../sync/presence.dart'; import '../sync/spaces.dart'; @@ -44,7 +43,6 @@ class NoteToolbar extends StatelessWidget { this.currentUserId = '', this.noteShared = false, this.updates, - this.atWindowLeftEdge = true, }); final VoidCallback onToggleSidebar; @@ -84,8 +82,8 @@ class NoteToolbar extends StatelessWidget { final VoidCallback? onSplit; /// What the split button says, which is also why it is grey when it is. - /// Null leaves the button out altogether, where there is only ever one note - /// on screen: a phone, or a window too narrow for the notes list beside it. + /// Null leaves the button out altogether where there is only ever one note + /// on screen, which is a phone. final String? splitTooltip; /// Drives the optional animated mark without changing toolbar geometry. @@ -110,11 +108,6 @@ class NoteToolbar extends StatelessWidget { /// the app does not update itself. final UpdateChecker? updates; - /// Whether the bar starts at the window's left edge, where macOS draws the - /// traffic lights over it. In the wide window it starts beside the spaces - /// rail, which keeps them clear itself. - final bool atWindowLeftEdge; - /// Wide enough for the update button to say what it does in full. Below /// this it would run into the centred lockup, so it shortens to "Update". static const double _updateLabelWidth = 680; @@ -124,7 +117,7 @@ class NoteToolbar extends StatelessWidget { /// Between the lockup and the pin, and mirrored on the other side. static const double _pinGap = 5; - /// Between an edge action and the window's edge. + /// Between an edge action and the bar's edge. static const double _edgeGap = 9; @override @@ -155,7 +148,7 @@ class NoteToolbar extends StatelessWidget { 0.0, math.min( desiredLeadingRight, - constraints.maxWidth - _leadingInset - fixedLeadingWidth, + constraints.maxWidth - _edgeGap - fixedLeadingWidth, ), ); @@ -231,7 +224,7 @@ class NoteToolbar extends StatelessWidget { if (showActions) ...[ Positioned( top: topInset, - left: _leadingInset, + left: _edgeGap, // Stops short of the lockup when there is room. On the // narrowest phones, reserve the two fixed actions first; // avatars still give up circles, then names, to fit. @@ -259,12 +252,6 @@ class NoteToolbar extends StatelessWidget { ); } - /// Where the leading cluster starts: clear of the traffic lights on macOS, - /// and a matching beat from the window edge everywhere else. - double get _leadingInset => WindowChrome.overlaysContent && atWindowLeftEdge - ? WindowChrome.trafficLightsWidth - : _edgeGap; - /// Half the lockup, plus air. /// /// Estimated from the type size rather than measured: its only job is to @@ -276,10 +263,8 @@ class NoteToolbar extends StatelessWidget { /// The drawer's button, and whoever the open note is shared with. /// - /// The menu leads on every platform, so the drawer opens from the same - /// corner everywhere. macOS paints its traffic lights over that corner, so - /// the button starts after them rather than under them — see - /// [_leadingInset], which is the whole of the difference there. + /// The menu leads on every platform, so the notes list opens from the same + /// corner everywhere. Widget _leading() { return Row( mainAxisSize: MainAxisSize.min, diff --git a/test/app_test.dart b/test/app_test.dart index 2b6a2f3..45f832e 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -46,6 +46,7 @@ import 'package:kapy_notes/ui/toolbar.dart'; import 'package:kapy_notes/ui/window_drag_area.dart'; import 'kapy_icon_finder.dart'; +import 'quick_capture_test.dart' show stubLaunchIntent; import 'sync/fake_server.dart'; import 'test_fonts.dart'; @@ -600,7 +601,7 @@ void main() { }); testWidgets( - 'keeps Windows header actions after returning to a compact width', + 'a list open over a narrow page stands beside it once the window widens', (tester) async { AppPlatform.debugTargetPlatformOverride = TargetPlatform.windows; addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); @@ -609,26 +610,38 @@ void main() { of: find.byType(NoteToolbar), matching: findKapyIcon(icon), ); + final barrier = find.byKey(const ValueKey('sidebar-overlay-barrier')); await pumpApp(tester, size: const Size(620, 620), sidebarVisible: false); - // Open the compact drawer, then let the window cross into the wide - // layout while it is open. The new compact Scaffold starts closed when - // the window is narrowed again, so its header actions must come back. await tester.tap(notesToggleWithLabel('Show notes')); await tester.pumpAndSettle(); - expect(toolbarIcon(KapyIcons.menuRounded), findsNothing); + expect(find.byType(Sidebar), findsOneWidget); + expect(barrier, findsOneWidget); + // Still on screen with room to stand beside the page, so it does. tester.view.physicalSize = const Size(760, 620); await tester.pumpAndSettle(); - expect(toolbarIcon(KapyIcons.menuRounded), findsOneWidget); + expect(barrier, findsNothing); + expect(prefs.sidebarVisible, isTrue); + expect( + tester.getRect(find.byType(Sidebar)).right, + lessThanOrEqualTo(tester.getRect(find.byType(NoteToolbar)).left), + ); + // Narrowed again, the window folds it away and keeps every action. tester.view.physicalSize = const Size(622, 620); await tester.pumpAndSettle(); - + expect(find.byType(Sidebar), findsNothing); + expect(barrier, findsNothing); expect(toolbarIcon(KapyIcons.menuRounded), findsOneWidget); expect(toolbarIcon(KapyIcons.addRounded), findsOneWidget); expect(toolbarIcon(KapyIcons.peopleOutlined), findsOneWidget); + + tester.view.physicalSize = const Size(760, 620); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsOneWidget); + expect(barrier, findsNothing); }, ); @@ -651,15 +664,15 @@ void main() { ); } - // The drawer hides the note actions while it covers them. The pin is - // about the window, not the note, so it stays. + // The list opened over a narrow window's page leaves the toolbar, and + // the pin on it, where they were. await pumpApp(tester, size: const Size(700, 620)); await tester.tap(notesToggleWithLabel('Show notes')); await tester.pumpAndSettle(); expect( findKapyIcon(KapyIcons.pinOutlined), findsOneWidget, - reason: 'the pin went with the drawer', + reason: 'the pin went under the list', ); // A phone has no window to float, so the control is absent rather than @@ -2346,22 +2359,26 @@ void main() { expect(prefs.sidebarVisible, isFalse); }); - testWidgets('the notes shortcut opens and closes the compact drawer', ( + testWidgets('the notes shortcut opens and closes the list over a narrow page', ( tester, ) async { await pumpApp(tester, size: const Size(600, 700)); - notes.create(body: 'Compact note'); + notes.create(body: 'Narrow note'); await tester.pumpAndSettle(); - final scaffold = tester.state(find.byType(Scaffold).first); final binding = shortcuts.bindingFor(ShortcutAction.toggleSidebar)!; - expect(scaffold.isDrawerOpen, isFalse); + final search = find.byKey(const ValueKey('sidebar-search-field')); + expect(find.byType(Sidebar), findsNothing); await pressShortcut(tester, binding); - expect(scaffold.isDrawerOpen, isTrue); + expect(find.byType(Sidebar), findsOneWidget); + // The list takes the keyboard, so nothing typed lands in the note under it. + expect(tester.widget(search).focusNode?.hasFocus, isTrue); await pressShortcut(tester, binding); - expect(scaffold.isDrawerOpen, isFalse); + expect(find.byType(Sidebar), findsNothing); + // A wide window's list is a choice of its own, and stays as it was. + expect(prefs.sidebarVisible, isTrue); }); testWidgets('the hamburger tooltip includes its current shortcut', ( @@ -2384,8 +2401,10 @@ void main() { testWidgets( 'toolbar settings sits beside notes, teaches its shortcut, and opens', (tester) async { - // A narrow window's toolbar. Beside the rail, settings is its gear. - await pumpApp(tester, size: const Size(600, 760)); + // A phone's toolbar. Beside the rail, settings is the rail's gear. + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); + await pumpApp(tester, size: const Size(390, 844)); final toolbar = find.byType(NoteToolbar); final menu = find.descendant( @@ -2503,29 +2522,36 @@ void main() { ); }); - testWidgets('global search opens and focuses the compact notes drawer', ( - tester, - ) async { - await pumpApp(tester, size: const Size(600, 760)); - notes.create(body: 'Compact search result'); - await tester.pumpAndSettle(); + testWidgets( + 'global search opens the list over a narrow page and focuses it', + (tester) async { + await pumpApp(tester, size: const Size(600, 760)); + notes.create(body: 'Narrow search result'); + await tester.pumpAndSettle(); - await pressShortcut( - tester, - shortcuts.bindingFor(ShortcutAction.findNotes)!, - ); + await pressShortcut( + tester, + shortcuts.bindingFor(ShortcutAction.findNotes)!, + ); - final search = find.byKey(const ValueKey('sidebar-search-field')); - expect(search, findsOneWidget); - expect(tester.widget(search).focusNode?.hasFocus, isTrue); - }); + final search = find.byKey(const ValueKey('sidebar-search-field')); + expect(search, findsOneWidget); + expect(tester.widget(search).focusNode?.hasFocus, isTrue); + expect( + find.byKey(const ValueKey('sidebar-overlay-barrier')), + findsOneWidget, + ); + }, + ); testWidgets('creates a note from the plus beside search', (tester) async { - // A narrow window's notes list. Beside the rail, New note sits in the bar - // over the list instead; see the spaces rail group. + // A phone's notes drawer. Beside the rail, New note sits in the bar over + // the list instead; see the spaces rail group. + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); await notes.load(); notes.create(body: 'Something written'); - await pumpApp(tester, size: const Size(600, 760)); + await pumpApp(tester, size: const Size(390, 844)); await showNotesList(tester); final before = notes.notes.length; final search = find.byKey(const ValueKey('sidebar-search-field')); @@ -2539,7 +2565,7 @@ void main() { expect(notes.notes, hasLength(before + 1)); }); - testWidgets('leaves breathing room around the sidebar search row', ( + testWidgets('the list over a narrow page is the list beside a wide one', ( tester, ) async { await notes.load(); @@ -2547,16 +2573,27 @@ void main() { await pumpApp(tester, size: const Size(600, 760)); await showNotesList(tester); + final rail = tester.getRect(find.byType(SpacesRail)); final sidebar = tester.getRect(find.byType(Sidebar)); + final bar = tester.getRect(find.byType(SidebarWindowBar)); final search = tester.getRect( find.byKey(const ValueKey('sidebar-search-field')), ); - final add = tester.getRect(find.byKey(const ValueKey('sidebar-new-note'))); - expect(search.top - sidebar.top, greaterThanOrEqualTo(12)); + expect(sidebar.left, rail.right); + expect(sidebar.width, LayoutPrefs.defaultSidebarWidth); + expect(bar.top, sidebar.top); + expect(search.top, greaterThanOrEqualTo(bar.bottom)); expect(search.left - sidebar.left, greaterThanOrEqualTo(12)); - expect(sidebar.right - add.right, greaterThanOrEqualTo(12)); - expect(add.center.dy, closeTo(search.center.dy, 0.5)); + expect(sidebar.right - search.right, greaterThanOrEqualTo(12)); + // New note sits in the bar, as it does beside the page. + expect( + find.descendant( + of: find.byType(SidebarWindowBar), + matching: find.byKey(const ValueKey('sidebar-new-note')), + ), + findsOneWidget, + ); }); testWidgets( @@ -4039,7 +4076,7 @@ void main() { }); group('compact editor', () { - testWidgets('keeps the results divider in compact desktop windows', ( + testWidgets('keeps the results divider in a narrow desktop window', ( tester, ) async { store.data['notes.v1'] = [ @@ -4363,6 +4400,8 @@ void main() { ]; // Last opened is the default startup behavior. store.data['selectedNote.v1'] = 'created-last'; + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); await pumpApp(tester, size: const Size(420, 800)); @@ -4426,6 +4465,8 @@ void main() { 'updatedAt': 2000, }, ]; + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); await pumpApp(tester, size: const Size(420, 800)); expect(find.widgetWithText(ResultChip, '42'), findsOneWidget); @@ -4667,6 +4708,8 @@ void main() { testWidgets('creates a ready-to-type note when the store is empty', ( tester, ) async { + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); await pumpApp(tester, size: const Size(420, 800)); expect(notes.notes, hasLength(1)); @@ -4680,6 +4723,12 @@ void main() { testWidgets('restores editor focus and the keyboard on app resume', ( tester, ) async { + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); + // A phone asks on every resume whether a widget was tapped meanwhile. + // Nothing was. + stubLaunchIntent(null); + addTearDown(() => stubLaunchIntent(null, respond: false)); await pumpApp(tester, size: const Size(420, 800)); tester.testTextInput.hide(); @@ -5042,19 +5091,109 @@ void main() { }); }); + group('narrow window', () { + final barrier = find.byKey(const ValueKey('sidebar-overlay-barrier')); + + testWidgets('keeps the rail and the page, and folds the list away', ( + tester, + ) async { + await notes.load(); + notes.create(body: 'Narrow note'); + // The size every new window opens at. + await pumpApp(tester, size: LayoutPrefs.defaultWindowSize); + + expect(find.byType(SpacesRail), findsOneWidget); + expect(find.byType(Scaffold), findsNothing); + // Shown, as far as a window with room for it is concerned. + expect(prefs.sidebarVisible, isTrue); + expect(find.byType(Sidebar), findsNothing); + expect(notesToggleWithLabel('Show notes'), findsOneWidget); + // The page stands a margin in from the rail, as in Paper's window with + // the list hidden. + expect( + tester.getRect(find.byType(NoteToolbar)).left, + tester.getRect(find.byType(SpacesRail)).right + 12, + ); + }); + + testWidgets('opens the list over the page, and puts it away again', ( + tester, + ) async { + await notes.load(); + notes.create(body: 'First note'); + notes.create(body: 'Second note'); + await pumpApp(tester, size: const Size(600, 720)); + final page = tester.getRect(find.byType(NoteToolbar)); + + Future open() async { + await tester.tap(notesToggleWithLabel('Show notes')); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsOneWidget); + expect(barrier, findsOneWidget); + } + + // Over the page, which keeps its place and its width. + await open(); + expect(tester.getRect(find.byType(NoteToolbar)), page); + + // A click on the page beside it. + await tester.tapAt(Offset(page.right - 8, page.center.dy)); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsNothing); + + await open(); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsNothing); + + await open(); + await tester.tap(find.byKey(const ValueKey('sidebar-hide'))); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsNothing); + + // A note chosen from it opens ready to type. + await open(); + await tester.tap(find.widgetWithText(NoteRow, 'First note')); + await tester.pumpAndSettle(); + expect(find.byType(Sidebar), findsNothing); + expect(barrier, findsNothing); + final field = tester.widget( + find.descendant( + of: find.byType(NoteEditor), + matching: find.byType(TextField), + ), + ); + expect(field.controller!.text, startsWith('First note')); + expect(field.focusNode!.hasFocus, isTrue); + + // So does a new one. + await open(); + final before = notes.notes.length; + await tester.tap(find.byKey(const ValueKey('sidebar-new-note'))); + await tester.pumpAndSettle(); + expect(notes.notes, hasLength(before + 1)); + expect(find.byType(Sidebar), findsNothing); + + // None of it touched the list a wide window shows. + expect(prefs.sidebarVisible, isTrue); + }); + }); + group('window chrome', () { testWidgets( - 'keeps the compact desktop toolbar clear of macOS window controls', + 'keeps a narrow window\'s toolbar clear of macOS window controls', (tester) async { await pumpApp(tester, size: const Size(600, 630)); notes.create(); await tester.pumpAndSettle(); - expect(find.byType(NoteToolbar), findsOneWidget); + // The rail still runs down the window's left edge and takes the + // traffic lights, as it does in a wide window. + expect(tester.getRect(find.byType(SpacesRail)).topLeft, Offset.zero); expect( tester.getTopLeft(notesToggleWithLabel('Show notes')).dx, greaterThanOrEqualTo(WindowChrome.trafficLightsWidth), - reason: 'the compact toolbar overlapped the macOS traffic lights', + reason: 'the toolbar overlapped the macOS traffic lights', ); }, skip: !WindowChrome.overlaysContent, diff --git a/test/golden_test.dart b/test/golden_test.dart index 3af0f8f..4666c87 100644 --- a/test/golden_test.dart +++ b/test/golden_test.dart @@ -577,7 +577,7 @@ void main() { ); }); - testWidgets('desktop dark compact results divider hover', (tester) async { + testWidgets('desktop dark narrow results divider hover', (tester) async { await pumpForGolden( tester, size: const Size(600, 630), @@ -594,11 +594,33 @@ void main() { await expectLater( find.byType(KapyNotesApp), matchesGoldenFile( - 'goldens/desktop_dark_compact_results_divider_hover.png', + 'goldens/desktop_dark_narrow_results_divider_hover.png', ), ); }); + testWidgets('desktop dark narrow, notes list over the page', (tester) async { + // The window a new install opens at, too narrow for the list beside the + // page: the rail and the page stay, and the list opens over the page. + await pumpForGolden( + tester, + size: LayoutPrefs.defaultWindowSize, + brightness: Brightness.dark, + ); + await tester.tap( + find.byWidgetPredicate( + (widget) => + widget is Tooltip && + (widget.message ?? '').startsWith('Show notes'), + ), + ); + await tester.pumpAndSettle(); + await expectLater( + find.byType(KapyNotesApp), + matchesGoldenFile('goldens/desktop_dark_narrow_list.png'), + ); + }); + testWidgets('desktop dark results restore hover', (tester) async { await pumpForGolden( tester, @@ -828,8 +850,8 @@ void main() { }); testWidgets('desktop dark, sidebar collapsed', (tester) async { - // The toolbar owns the window's left edge here, where macOS draws the - // traffic lights over it. + // The page starts a margin in from the rail, as in Paper's window with + // the list hidden. await pumpForGolden( tester, size: const Size(760, 520), diff --git a/test/goldens/desktop_dark_compact_results_divider_hover.png b/test/goldens/desktop_dark_compact_results_divider_hover.png deleted file mode 100644 index b203923..0000000 Binary files a/test/goldens/desktop_dark_compact_results_divider_hover.png and /dev/null differ diff --git a/test/goldens/desktop_dark_narrow_list.png b/test/goldens/desktop_dark_narrow_list.png new file mode 100644 index 0000000..f506a00 Binary files /dev/null and b/test/goldens/desktop_dark_narrow_list.png differ diff --git a/test/goldens/desktop_dark_narrow_results_divider_hover.png b/test/goldens/desktop_dark_narrow_results_divider_hover.png new file mode 100644 index 0000000..299342c Binary files /dev/null and b/test/goldens/desktop_dark_narrow_results_divider_hover.png differ diff --git a/test/goldens/toolbar_shared_note_dark.png b/test/goldens/toolbar_shared_note_dark.png index c39c3c0..8815a8f 100644 Binary files a/test/goldens/toolbar_shared_note_dark.png and b/test/goldens/toolbar_shared_note_dark.png differ diff --git a/test/goldens/toolbar_shared_note_light.png b/test/goldens/toolbar_shared_note_light.png index 28f6106..d1b8a2d 100644 Binary files a/test/goldens/toolbar_shared_note_light.png and b/test/goldens/toolbar_shared_note_light.png differ diff --git a/test/spaces_rail_test.dart b/test/spaces_rail_test.dart index 9a35b14..c534867 100644 --- a/test/spaces_rail_test.dart +++ b/test/spaces_rail_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:kapy_notes/core/platform.dart'; import 'package:kapy_notes/core/theme.dart'; +import 'package:kapy_notes/data/layout_prefs.dart'; import 'package:kapy_notes/data/writing_streak.dart'; import 'package:kapy_notes/sync/auth_api.dart'; import 'package:kapy_notes/sync/sync_service.dart'; @@ -190,4 +191,42 @@ void main() { expect(dot(tester), scheme.error); }); }); + + for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) { + testWidgets('fits the smallest ${platform.name} window with every space', ( + tester, + ) async { + AppPlatform.debugTargetPlatformOverride = platform; + // A Windows minimum is the outer window, and its caption and frame take + // some forty points of that. macOS draws its title bar over the rail. + final height = + LayoutPrefs.minimumWindowSize.height - + (platform == TargetPlatform.windows ? 40 : 0); + await tester.pumpWidget( + MaterialApp( + theme: KapyTheme.dark(), + home: Material( + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: height, + child: rail( + invitations: 2, + showHidden: true, + streak: const WritingStreak(days: 3, wroteToday: true), + onAccountPressed: () {}, + ), + ), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + expect( + tester.getRect(find.byKey(const ValueKey('rail-account'))).bottom, + lessThanOrEqualTo(height), + ); + }); + } } diff --git a/test/toolbar_test.dart b/test/toolbar_test.dart index 78fb7fa..74f193f 100644 --- a/test/toolbar_test.dart +++ b/test/toolbar_test.dart @@ -1,7 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:kapy_notes/core/platform.dart'; import 'package:kapy_notes/core/theme.dart'; -import 'package:kapy_notes/core/window_chrome.dart'; import 'package:kapy_notes/sync/presence.dart'; import 'package:kapy_notes/sync/spaces.dart'; import 'package:kapy_notes/ui/app_logo.dart'; @@ -58,25 +57,6 @@ void main() { tearDown(() => AppPlatform.debugTargetPlatformOverride = null); group('placement', () { - testWidgets('macOS starts the menu after its traffic lights', ( - tester, - ) async { - AppPlatform.debugTargetPlatformOverride = TargetPlatform.macOS; - await tester.pumpWidget( - harness( - NoteToolbar(onToggleSidebar: () {}, onCreate: () {}, onShare: () {}), - ), - ); - - // The drawer's button leads here as it does everywhere else; the only - // difference is that the corner it leads from belongs to the window - // controls, so it begins where they end rather than underneath them. - expect( - tester.getTopLeft(findKapyIcon(KapyIcons.menuRounded)).dx, - greaterThanOrEqualTo(WindowChrome.trafficLightsWidth), - ); - }); - for (final platform in [ TargetPlatform.macOS, TargetPlatform.windows, @@ -240,13 +220,13 @@ void main() { // Own initial, not the "Y" of the word standing in for the name. expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); - // Left of the wordmark, beside the window controls rather than over them. + // Between the menu and the wordmark. final avatars = tester.getRect( find.byKey(const ValueKey('toolbar-members')), ); expect( avatars.left, - greaterThanOrEqualTo(WindowChrome.trafficLightsWidth), + greaterThan(tester.getRect(findKapyIcon(KapyIcons.menuRounded)).right), ); expect( avatars.right, diff --git a/test/welcome_note_test.dart b/test/welcome_note_test.dart index 08294a8..d328864 100644 --- a/test/welcome_note_test.dart +++ b/test/welcome_note_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:kapy_notes/app.dart'; import 'package:kapy_notes/calc/engine.dart'; +import 'package:kapy_notes/core/platform.dart'; import 'package:kapy_notes/core/theme.dart'; import 'package:kapy_notes/data/layout_prefs.dart'; import 'package:kapy_notes/data/notes_store.dart'; @@ -268,6 +269,8 @@ void main() { }); testWidgets('does not offer the welcome note on a phone', (tester) async { + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); await pumpLaunch(tester, MemoryStore(), size: const Size(390, 760)); await tester.tap(find.byKey(const ValueKey('toolbar-notes-toggle'))); await tester.pumpAndSettle();