Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/core/window_chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion lib/data/layout_prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
202 changes: 115 additions & 87 deletions lib/ui/home_page.dart

Large diffs are not rendered by default.

78 changes: 3 additions & 75 deletions lib/ui/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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<String>? onDelete;
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1479,17 +1440,14 @@ class _HiddenEntry extends StatelessWidget {
),
),
),
if (!showingHidden && count > 0) ...[
if (!showingHidden && count > 0)
Text(
'$count',
style: TextStyle(
fontSize: AppTypeScale.small,
color: palette.textTertiary,
),
),
if (shortcut != null) const SizedBox(width: 8),
],
if (shortcut != null) _FolderShortcutHint(shortcut: shortcut),
],
),
),
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/sidebar_swipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
92 changes: 72 additions & 20 deletions lib/ui/split_view.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
});
Expand All @@ -24,6 +29,12 @@ class SplitView extends StatefulWidget {
final ValueChanged<double> 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;

Expand All @@ -32,6 +43,13 @@ class SplitView extends StatefulWidget {
}

class _SplitViewState extends State<SplitView> {
/// 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.
Expand All @@ -48,44 +66,47 @@ class _SplitViewState extends State<SplitView> {

@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: [
Positioned.fill(
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,
Expand Down Expand Up @@ -131,6 +152,37 @@ class _SplitViewState extends State<SplitView> {
),
),
),
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<DismissIntent>(
onInvoke: (_) => widget.onHide(),
),
},
child: DecoratedBox(
position: DecorationPosition.foreground,
decoration: BoxDecoration(
border: Border(
right: BorderSide(color: palette.separator, width: 0.5),
),
),
child: widget.sidebar,
),
),
),
],
],
);
},
Expand Down
Loading
Loading