diff --git a/lib/ui/compact_icon_button.dart b/lib/ui/compact_icon_button.dart index d09499b..048351f 100644 --- a/lib/ui/compact_icon_button.dart +++ b/lib/ui/compact_icon_button.dart @@ -17,6 +17,7 @@ class CompactIconButton extends StatelessWidget { this.extent, this.radius = 6, this.tapTargetSize, + this.selectedBackground, }); final Widget icon; @@ -33,6 +34,10 @@ class CompactIconButton extends StatelessWidget { /// buttons edge to edge and cannot afford padding around each one. final MaterialTapTargetSize? tapTargetSize; + /// The surface while [selected], in place of the palette's selection: the + /// drawing dock marks its tool in the tonal sage. + final Color? selectedBackground; + @override Widget build(BuildContext context) { final palette = context.palette; @@ -63,7 +68,9 @@ class CompactIconButton extends StatelessWidget { if (states.contains(WidgetState.pressed)) { return scheme.primary.withValues(alpha: 0.10); } - if (selected) return palette.selectedBackground; + if (selected) { + return selectedBackground ?? palette.selectedBackground; + } if (states.contains(WidgetState.hovered) || states.contains(WidgetState.focused)) { return palette.hover; diff --git a/lib/ui/draw/drawing_canvas.dart b/lib/ui/draw/drawing_canvas.dart index ec5182d..106e69a 100644 --- a/lib/ui/draw/drawing_canvas.dart +++ b/lib/ui/draw/drawing_canvas.dart @@ -4,12 +4,12 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:material_ui/material_ui.dart'; +import '../../core/editor_font.dart'; import '../../core/platform.dart'; import '../../core/theme.dart'; import '../../data/note_drawing.dart'; import '../../data/notes_store.dart'; import '../compact_icon_button.dart'; -import '../floating_surface.dart'; import '../mobile_page_swipe.dart'; import '../sidebar_swipe.dart'; import 'drawing_geometry.dart'; @@ -44,18 +44,23 @@ enum DrawTool { }; } -/// Colours that read on the light paper and the dark one alike. Null is the -/// theme's ink, which is the one that has to flip. -const List drawColors = [ - null, - 0xFFE03131, - 0xFFF08C00, - 0xFF2F9E44, - 0xFF1971C2, - 0xFF7048E8, +/// Riverbank's muted colours, which read on the light paper and the dark one +/// alike. Null is the theme's ink, which is the one that has to flip. A stroke +/// keeps the colour it was drawn in, whatever this list later becomes. +const List<(String, int?)> drawColors = [ + ('Ink', null), + ('Clay', 0xFFD0663B), + ('Ochre', 0xFFC49A3A), + ('Sage', 0xFF6F8F52), + ('River', 0xFF3F8796), + ('Plum', 0xFF8E5E8A), ]; -const List drawWidths = [2, 4, 8]; +const List<(String, double)> drawWidths = [ + ('Thin', 2), + ('Medium', 4), + ('Bold', 8), +]; /// A minimal whiteboard: a title, an endless canvas, and a handful of tools. /// @@ -72,6 +77,7 @@ class DrawingCanvas extends StatefulWidget { required this.title, required this.onChanged, required this.onTitleChanged, + this.edited, this.readOnly = false, this.onSwitchToWrite, this.onFocus, @@ -81,6 +87,10 @@ class DrawingCanvas extends StatefulWidget { final String title; final ValueChanged onChanged; final ValueChanged onTitleChanged; + + /// When the drawing last changed, said under its title beside how many + /// shapes it holds. + final String? edited; final bool readOnly; /// Offered only while the canvas and its title are both blank. @@ -146,7 +156,7 @@ class DrawingCanvasState extends State { DrawTool _tool = DrawTool.pen; int? _color; - double _width = drawWidths[1]; + double _width = drawWidths[1].$2; bool _styleOpen = false; Offset _pan = Offset.zero; @@ -854,7 +864,7 @@ class DrawingCanvasState extends State { pan: _pan, zoom: _zoom, ink: ink, - grid: palette.separator.withValues(alpha: 0.5), + grid: palette.controlBorder, accent: Theme.of(context).colorScheme.primary, textStyle: _textStyle(context), ), @@ -910,44 +920,79 @@ class DrawingCanvasState extends State { Widget _buildHeader(BuildContext context) { final palette = context.palette; final touch = !AppPlatform.hasPointer; + const handwritten = WritingFont.handwritten; + final edited = widget.edited; + final shapes = _drawing.elements.length; + final title = Row( + children: [ + Expanded( + child: TextField( + key: const ValueKey('drawing-title'), + controller: _titleController, + focusNode: _titleFocus, + readOnly: widget.readOnly, + maxLines: 1, + textInputAction: TextInputAction.done, + style: touch + ? Theme.of(context).textTheme.titleMedium?.copyWith( + color: palette.textPrimary, + fontWeight: FontWeight.w600, + ) + : TextStyle( + fontFamily: handwritten.fontFamily, + fontFamilyFallback: handwritten.fontFamilyFallback, + fontVariations: handwritten.fontVariations, + fontSize: 28, + height: 36 / 28, + fontWeight: FontWeight.w600, + color: palette.textPrimary, + ), + decoration: InputDecoration( + hintText: 'Untitled drawing', + hintStyle: TextStyle(color: palette.textTertiary), + border: InputBorder.none, + enabledBorder: InputBorder.none, + focusedBorder: InputBorder.none, + filled: false, + isDense: true, + contentPadding: const EdgeInsets.symmetric(vertical: 8), + ), + onChanged: widget.onTitleChanged, + onSubmitted: (_) => _canvasFocus.requestFocus(), + ), + ), + if (widget.onSwitchToWrite != null && + _drawing.isEmpty && + _titleController.text.trim().isEmpty) + NoteModeSwitch( + drawing: true, + onChanged: (drawing) { + if (!drawing) widget.onSwitchToWrite!(); + }, + ), + ], + ); + if (touch) { + return Padding( + padding: const EdgeInsets.fromLTRB(16, 10, 12, 0), + child: title, + ); + } return Padding( - padding: EdgeInsets.fromLTRB(touch ? 16 : 24, 10, 12, 0), - child: Row( + padding: const EdgeInsets.fromLTRB(40, 12, 12, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - child: TextField( - key: const ValueKey('drawing-title'), - controller: _titleController, - focusNode: _titleFocus, - readOnly: widget.readOnly, - maxLines: 1, - textInputAction: TextInputAction.done, - style: Theme.of(context).textTheme.titleMedium?.copyWith( - color: palette.textPrimary, - fontWeight: FontWeight.w600, - ), - decoration: InputDecoration( - hintText: 'Untitled drawing', - hintStyle: TextStyle(color: palette.textTertiary), - border: InputBorder.none, - enabledBorder: InputBorder.none, - focusedBorder: InputBorder.none, - filled: false, - isDense: true, - contentPadding: const EdgeInsets.symmetric(vertical: 8), + title, + if (edited != null && shapes > 0) + Text( + '$edited · $shapes ${shapes == 1 ? 'shape' : 'shapes'}', + style: TextStyle( + fontSize: AppTypeScale.small, + height: 16 / 13, + fontWeight: FontWeight.w500, + color: palette.textTertiary, ), - onChanged: widget.onTitleChanged, - onSubmitted: (_) => _canvasFocus.requestFocus(), - ), - ), - if (widget.onSwitchToWrite != null && - _drawing.isEmpty && - _titleController.text.trim().isEmpty) - NoteModeSwitch( - drawing: true, - onChanged: (drawing) { - if (!drawing) widget.onSwitchToWrite!(); - }, ), ], ), @@ -1006,57 +1051,110 @@ class DrawingCanvasState extends State { : DrawTool.values) if (!(touch && tool == DrawTool.pan && !widget.readOnly)) tool, ]; + final extent = _DockSurface.buttonExtent; final divider = Container( width: 1, height: 20, margin: const EdgeInsets.symmetric(horizontal: 4), color: palette.separator, ); + Widget button( + String key, + KapyIconData icon, + String tooltip, + VoidCallback? onPressed, { + bool selected = false, + }) => CompactIconButton( + key: ValueKey(key), + icon: KapyIcon(icon, size: touch ? null : 17), + tooltip: tooltip, + selected: selected, + onPressed: onPressed, + extent: extent, + radius: 9, + foregroundColor: selected ? palette.tonalForeground : null, + selectedBackground: palette.tonalBackground, + // Each button is already a 44pt target on touch; the padding around + // it is what pushed the last tool off a phone. + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + ); final toolButtons = [ for (final tool in tools) - CompactIconButton( - key: ValueKey('draw-tool-${tool.name}'), - icon: KapyIcon(tool.icon), - tooltip: touch ? tool.label : '${tool.label} · ${tool.key}', + button( + 'draw-tool-${tool.name}', + tool.icon, + touch ? tool.label : '${tool.label} · ${tool.key}', + () => selectTool(tool), selected: _tool == tool, - onPressed: () => selectTool(tool), - // Each button is already a 44pt target on touch; the padding - // around it is what pushed the last tool off a phone. - tapTargetSize: MaterialTapTargetSize.shrinkWrap, ), ]; final actions = [ if (!widget.readOnly) ...[ - CompactIconButton( - key: const ValueKey('draw-style'), - tooltip: 'Colour and size', - selected: _styleOpen, - onPressed: () => setState(() => _styleOpen = !_styleOpen), - icon: _Swatch( - color: _color == null ? palette.textPrimary : Color(_color!), - size: 6 + _width * 1.2, + Tooltip( + message: 'Colour and size', + child: InkWell( + key: const ValueKey('draw-style'), + onTap: () => setState(() => _styleOpen = !_styleOpen), + borderRadius: BorderRadius.circular(9), + child: Container( + height: extent, + padding: const EdgeInsets.symmetric(horizontal: 8), + decoration: _styleOpen + ? BoxDecoration( + color: palette.selectedBackground, + borderRadius: BorderRadius.circular(9), + ) + : null, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + width: 14, + height: 14, + decoration: BoxDecoration( + color: _color == null + ? palette.textPrimary + : Color(_color!), + shape: BoxShape.circle, + border: Border.all( + color: palette.separator, + width: 1.5, + strokeAlign: BorderSide.strokeAlignOutside, + ), + ), + ), + const SizedBox(width: 6), + KapyIcon( + KapyIcons.chevronDownRounded, + size: 12, + strokeWidth: 2, + color: palette.textSecondary, + ), + ], + ), + ), ), ), divider, - CompactIconButton( - key: const ValueKey('draw-undo'), - icon: const KapyIcon(KapyIcons.undoRounded), - tooltip: 'Undo', - onPressed: _undo.isEmpty ? null : undo, + button( + 'draw-undo', + KapyIcons.undoRounded, + 'Undo', + _undo.isEmpty ? null : undo, ), - CompactIconButton( - key: const ValueKey('draw-redo'), - icon: const KapyIcon(KapyIcons.redoRounded), - tooltip: 'Redo', - onPressed: _redo.isEmpty ? null : redo, + button( + 'draw-redo', + KapyIcons.redoRounded, + 'Redo', + _redo.isEmpty ? null : redo, ), if (_selected.isNotEmpty) - CompactIconButton( - key: const ValueKey('draw-delete'), - icon: const KapyIcon(KapyIcons.deleteOutlined), - tooltip: 'Delete', - onPressed: deleteSelection, + button( + 'draw-delete', + KapyIcons.deleteOutlined, + 'Delete', + deleteSelection, ), divider, ], @@ -1066,10 +1164,14 @@ class DrawingCanvasState extends State { key: const ValueKey('draw-zoom'), onPressed: fitToContent, style: TextButton.styleFrom( - minimumSize: Size(52, AppControlMetrics.iconButtonExtent), - padding: const EdgeInsets.symmetric(horizontal: 6), - foregroundColor: palette.textSecondary, - textStyle: Theme.of(context).textTheme.labelMedium?.copyWith( + minimumSize: Size(52, extent), + padding: const EdgeInsets.symmetric(horizontal: 10), + foregroundColor: palette.textPrimary, + textStyle: TextStyle( + fontFamily: AppFonts.mono, + fontFamilyFallback: AppFonts.monoFallback, + fontSize: 12.5, + fontWeight: FontWeight.w600, fontFeatures: const [FontFeature.tabularFigures()], ), ), @@ -1078,11 +1180,14 @@ class DrawingCanvasState extends State { ), ]; - Widget bar(List children) => FloatingSurface( - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4), + Widget bar(List children) => _DockSurface( child: SingleChildScrollView( scrollDirection: Axis.horizontal, - child: Row(mainAxisSize: MainAxisSize.min, children: children), + child: Row( + mainAxisSize: MainAxisSize.min, + spacing: 2, + children: children, + ), ), ); @@ -1091,8 +1196,7 @@ class DrawingCanvasState extends State { return LayoutBuilder( builder: (context, constraints) { final oneRow = - constraints.maxWidth >= - (tools.length + 6) * AppControlMetrics.iconButtonExtent + 120; + constraints.maxWidth >= (tools.length + 6) * extent + 120; return Column( mainAxisSize: MainAxisSize.min, children: [ @@ -1119,6 +1223,43 @@ class DrawingCanvasState extends State { } } +/// What the dock and its colour and size panel stand on: the insert bar's +/// raised strip of control colour. +class _DockSurface extends StatelessWidget { + const _DockSurface({required this.child, this.width}); + + final Widget child; + final double? width; + + /// The dock's buttons: roomier than the toolbars' on a pointer, the + /// platform's target on touch. + static double get buttonExtent => + AppPlatform.hasPointer ? 34 : AppControlMetrics.iconButtonExtent; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + return Container( + width: width, + padding: const EdgeInsets.all(5), + decoration: BoxDecoration( + color: palette.controlBackground, + border: Border.all(color: palette.controlBorder, width: 1.5), + borderRadius: BorderRadius.circular(14), + boxShadow: [ + BoxShadow( + color: palette.shadowAt(0x80), + offset: const Offset(0, 12), + blurRadius: 28, + spreadRadius: -14, + ), + ], + ), + child: child, + ); + } +} + class _StylePanel extends StatelessWidget { const _StylePanel({ required this.color, @@ -1135,73 +1276,136 @@ class _StylePanel extends StatelessWidget { @override Widget build(BuildContext context) { final palette = context.palette; - return FloatingSurface( - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4), - // Wraps rather than overflowing: six colours and three sizes are wider - // than a phone. - child: Wrap( - alignment: WrapAlignment.center, - crossAxisAlignment: WrapCrossAlignment.center, - runSpacing: 4, - children: [ - for (final option in drawColors) - CompactIconButton( - key: ValueKey('draw-color-${option ?? 'ink'}'), - tooltip: option == null ? 'Ink' : 'Colour', - selected: option == color, - onPressed: () => onColor(option), - tapTargetSize: MaterialTapTargetSize.shrinkWrap, - icon: _Swatch( - color: option == null ? palette.textPrimary : Color(option), - size: 14, + final label = TextStyle( + fontSize: 12, + height: 16 / 12, + fontWeight: FontWeight.w600, + color: palette.textTertiary, + ); + return _DockSurface( + width: 262, + child: Padding( + padding: const EdgeInsets.all(7), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text('Colour', style: label), + const SizedBox(height: 8), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + for (final (name, option) in drawColors) + Tooltip( + message: name, + child: InkWell( + key: ValueKey('draw-color-${option ?? 'ink'}'), + customBorder: const CircleBorder(), + onTap: () => onColor(option), + child: Container( + width: 30, + height: 30, + alignment: Alignment.center, + decoration: option == color + ? BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: palette.selectedBorder, + width: 2, + ), + ) + : null, + child: Container( + width: 20, + height: 20, + decoration: BoxDecoration( + color: option == null + ? palette.textPrimary + : Color(option), + shape: BoxShape.circle, + ), + ), + ), + ), + ), + ], + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 12), + child: SizedBox( + height: 1, + child: ColoredBox(color: palette.separator), ), ), - Container( - width: 1, - height: 20, - margin: const EdgeInsets.symmetric(horizontal: 4), - color: palette.separator, - ), - for (final option in drawWidths) - CompactIconButton( - key: ValueKey('draw-width-${option.round()}'), - tooltip: switch (option) { - <= 2 => 'Thin', - <= 4 => 'Medium', - _ => 'Bold', - }, - selected: option == width, - onPressed: () => onWidth(option), - tapTargetSize: MaterialTapTargetSize.shrinkWrap, - icon: Container( - width: 16, - height: option, - decoration: BoxDecoration( - color: palette.textPrimary, - borderRadius: BorderRadius.circular(option), - ), + Text('Size', style: label), + const SizedBox(height: 8), + Container( + padding: const EdgeInsets.all(2), + decoration: BoxDecoration( + color: palette.editorBackground, + border: Border.all(color: palette.controlBorder), + borderRadius: BorderRadius.circular(9), + ), + child: Row( + spacing: 4, + children: [ + for (final (name, option) in drawWidths) + Expanded( + child: InkWell( + key: ValueKey('draw-width-${option.round()}'), + onTap: () => onWidth(option), + borderRadius: BorderRadius.circular(7), + child: Container( + height: 30, + decoration: option == width + ? BoxDecoration( + color: palette.tonalBackground, + borderRadius: BorderRadius.circular(7), + ) + : null, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: option + 3, + height: option + 3, + decoration: BoxDecoration( + color: option == width + ? palette.tonalForeground + : palette.textSecondary, + shape: BoxShape.circle, + ), + ), + const SizedBox(width: 7), + Flexible( + child: Text( + name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.5, + fontWeight: FontWeight.w600, + color: option == width + ? palette.tonalForeground + : palette.textPrimary, + ), + ), + ), + ], + ), + ), + ), + ), + ], ), ), - ], + ], + ), ), ); } } -class _Swatch extends StatelessWidget { - const _Swatch({required this.color, required this.size}); - - final Color color; - final double size; - - @override - Widget build(BuildContext context) => Container( - width: size, - height: size, - decoration: BoxDecoration(color: color, shape: BoxShape.circle), - ); -} - class _EmptyHint extends StatelessWidget { const _EmptyHint(); diff --git a/lib/ui/empty_state.dart b/lib/ui/empty_state.dart index dad471b..44a592d 100644 --- a/lib/ui/empty_state.dart +++ b/lib/ui/empty_state.dart @@ -1,17 +1,80 @@ import 'package:material_ui/material_ui.dart'; +import '../core/editor_font.dart'; import '../core/theme.dart'; import 'app_logo.dart'; +import 'keycap.dart'; /// Shown in the main pane when there is no note to edit. class EmptyState extends StatelessWidget { - const EmptyState({super.key, required this.onCreate}); + const EmptyState({super.key, required VoidCallback this.onCreate}) + : drawings = false, + shortcut = null; - final VoidCallback onCreate; + /// The page in Drawings with nothing open: a quiet hint at New drawing, + /// which is already in the window bar over the list. + const EmptyState.drawings({super.key, this.shortcut}) + : drawings = true, + onCreate = null; + + final VoidCallback? onCreate; + final bool drawings; + + /// The keys for New drawing, named in the hint. + final String? shortcut; @override Widget build(BuildContext context) { final palette = context.palette; + if (drawings) { + const handwritten = WritingFont.handwritten; + return Container( + color: palette.paperColor, + alignment: Alignment.center, + padding: const EdgeInsets.all(32), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + KapyIcon( + KapyIcons.penRounded, + size: 30, + strokeWidth: 1.4, + color: palette.textTertiary, + ), + const SizedBox(height: 10), + Text( + 'No drawing open', + style: TextStyle( + fontFamily: handwritten.fontFamily, + fontFamilyFallback: handwritten.fontFamilyFallback, + fontVariations: handwritten.fontVariations, + fontSize: 16, + fontWeight: FontWeight.w500, + color: palette.textPrimary, + ), + ), + const SizedBox(height: 6), + Row( + mainAxisSize: MainAxisSize.min, + spacing: 5, + children: [ + Text( + shortcut == null + ? 'Start one with New drawing' + : 'Start one with New drawing or', + style: TextStyle( + fontSize: AppTypeScale.small, + fontWeight: FontWeight.w500, + color: palette.textTertiary, + ), + ), + if (shortcut case final shortcut?) Keycap(shortcut), + ], + ), + ], + ), + ); + } // The paper runs to the window's edges; the words in it stay clear of the // home indicator, the same bargain the notes list makes. diff --git a/lib/ui/home_page.dart b/lib/ui/home_page.dart index b6ff666..1cfe29e 100644 --- a/lib/ui/home_page.dart +++ b/lib/ui/home_page.dart @@ -67,6 +67,7 @@ import 'notes_list.dart'; import 'page_card.dart'; import 'page_toolbar.dart'; import 'sidebar.dart'; +import 'sidebar_timestamp.dart'; import 'settings_dialog.dart'; import 'sidebar_swipe.dart'; import 'spaces_rail.dart'; @@ -1522,30 +1523,35 @@ class _HomePageState extends State with WidgetsBindingObserver { /// /// Returns whether anything was actually created, which is what the swipe /// cue needs in order not to announce a note that does not exist. - bool _createNote() { + bool _createNote({bool drawing = false}) { final recording = widget.recording; if (recording != null && recording.isRecording) { unawaited( recording.finishRecordingAndFlush().then((_) { - if (mounted) _createNoteNow(); + if (mounted) _createNoteNow(drawing: drawing); }), ); // The recording is about to land in the note that is open, so that note // will not be blank by the time this runs and a new one will follow. return true; } - return _createNoteNow(); + return _createNoteNow(drawing: drawing); } - bool _createNoteNow() { + /// What New makes in the space on screen: a drawing in Drawings, a note + /// everywhere else. + bool _createInSpace() => _createNote(drawing: _drawingsOnly); + + bool _createNoteNow({bool drawing = false}) { _recordKapyActivity(); final creatingHidden = _hiddenMode; - final blank = _blankNoteAlreadyOpen(); + final blank = drawing ? null : _blankNoteAlreadyOpen(); if (blank == null && !(_noteLimit?.canCreate ?? true)) { unawaited(_explainNoteLimit(creating: true)); return false; } final note = blank ?? widget.notes.create(hidden: creatingHidden); + if (drawing) widget.notes.setDrawingMode(note.id, drawing: true); if (blank == null) _freshNoteIds.add(note.id); setState(() { _query = ''; @@ -1554,13 +1560,13 @@ class _HomePageState extends State with WidgetsBindingObserver { // A new note is the person's own, so it is listed where they can see // it being written. _sidebarTab = SidebarTab.mine; - _drawingsOnly = false; + _drawingsOnly = drawing; // 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; - _focusSelectedEditorAtEnd(); + if (!drawing) _focusSelectedEditorAtEnd(); return blank == null; } @@ -2437,11 +2443,14 @@ class _HomePageState extends State with WidgetsBindingObserver { : widget.notes.search(_query), ); final pinnedOnly = _showingPinnedOnly; - if (pinnedOnly || _mediaFilter.length < NoteMedia.values.length) { + // Drawings has no media filter: every item in it is a drawing. + final filtered = + !_drawingsOnly && _mediaFilter.length < NoteMedia.values.length; + if (pinnedOnly || filtered) { final pinned = widget.notes.pinnedNoteIds; notes = [ for (final note in notes) - if (NoteMedia.shows(note, _mediaFilter) && + if ((!filtered || NoteMedia.shows(note, _mediaFilter)) && (!pinnedOnly || pinned.contains(note.id))) note, ]; @@ -2492,7 +2501,7 @@ class _HomePageState extends State with WidgetsBindingObserver { builder: (context, _) => _DesktopShortcuts( focusNode: _desktopShortcutFocus, shortcuts: widget.shortcuts, - onNewNote: _createNote, + onNewNote: _createInSpace, onFindNotes: _focusGlobalSearch, onNextNote: () => _cycleNote(1), onPreviousNote: () => _cycleNote(-1), @@ -2653,9 +2662,8 @@ class _HomePageState extends State with WidgetsBindingObserver { archiveShortcut: widget.shortcuts.bindingFor( ShortcutAction.deleteNote, ), - emptyMessage: space == LibrarySpace.drawings - ? 'No drawings yet' - : null, + drawings: space == LibrarySpace.drawings, + onNewDrawing: () => _createNote(drawing: true), engine: widget.engines.engine, now: widget.notes.now, cards: widget.prefs.noteCards, @@ -2669,7 +2677,10 @@ class _HomePageState extends State with WidgetsBindingObserver { windowBar: SidebarWindowBar( title: space.title, count: _spaceCount, - onCreate: _createNote, + noun: space == LibrarySpace.drawings + ? 'drawing' + : 'note', + onCreate: _createInSpace, newNoteShortcut: widget.shortcuts.bindingFor( ShortcutAction.newNote, ), @@ -2714,7 +2725,10 @@ class _HomePageState extends State with WidgetsBindingObserver { listVisible: listFits && listShown, onShowList: _toggleList, showListShortcut: _sidebarShortcut, - onCreate: _createNote, + noun: space == LibrarySpace.drawings + ? 'drawing' + : 'note', + onCreate: _createInSpace, newNoteShortcut: widget.shortcuts .bindingFor(ShortcutAction.newNote) ?.displayLabel, @@ -2849,7 +2863,7 @@ class _HomePageState extends State with WidgetsBindingObserver { : _buildEditor(selected, key: _archiveEditorKey, active: true); } final panes = _workspace.panes; - if (panes.isEmpty) return EmptyState(onCreate: _createNote); + if (panes.isEmpty) return _emptyPage(); return PaneSplitView( weights: _workspace.weights, @@ -2879,11 +2893,11 @@ class _HomePageState extends State with WidgetsBindingObserver { } else if (split) { body = EmptyPane( active: active, - onCreate: _createNote, + onCreate: _createInSpace, onShowNotes: _listShown ? null : () => _setListShown(true), ); } else { - body = EmptyState(onCreate: _createNote); + body = _emptyPage(); } return EditorPaneFrame( @@ -3299,12 +3313,28 @@ class _HomePageState extends State with WidgetsBindingObserver { widget.notes.setDrawingMode(id, drawing: drawing); } + /// The page with nothing open on it, which in Drawings points at New + /// drawing rather than offering a note. + Widget _emptyPage() => _drawingsOnly + ? EmptyState.drawings( + shortcut: widget.shortcuts + .bindingFor(ShortcutAction.newNote) + ?.keycapLabel, + ) + : EmptyState(onCreate: _createNote); + Widget _buildDrawing(Note note, {VoidCallback? onFocus}) { final canWrite = _canWriteNote(note); return DrawingCanvas( key: ValueKey('drawing-${note.id}'), drawing: note.drawing ?? NoteDrawing.empty, title: note.body, + edited: SidebarTimestamp.glance( + note.updatedAt, + now: widget.notes.now(), + displayTime: widget.prefs.displayTime, + today: true, + ), readOnly: !canWrite, onFocus: onFocus, onSwitchToWrite: _canChooseMode(note) diff --git a/lib/ui/notes_list.dart b/lib/ui/notes_list.dart index 8c5980a..9049ec6 100644 --- a/lib/ui/notes_list.dart +++ b/lib/ui/notes_list.dart @@ -8,6 +8,9 @@ import '../core/editor_font.dart'; import '../core/theme.dart'; import '../data/note.dart'; import '../data/note_attachment.dart'; +import '../data/note_drawing.dart'; +import 'draw/drawing_geometry.dart'; +import 'draw/drawing_painter.dart'; /// What a note can hold besides words, in the order the media filter lists /// them. @@ -186,16 +189,32 @@ TextStyle _figtree(double size, double line, FontWeight weight, Color color) => /// The small icons a card or row carries before its date: the media in the /// note, then whether it is read-only or shared. List _marksOf( - NoteGlance glance, { + Set media, { required bool locked, required bool shared, }) => [ - for (final media in NoteMedia.values.reversed) - if (glance.media.contains(media)) media.icon, + for (final kind in NoteMedia.values.reversed) + if (media.contains(kind)) kind.icon, if (locked) KapyIcons.lockRounded, if (shared) KapyIcons.peopleOutlined, ]; +Border? _cardBorder( + CalcPalette palette, { + required bool selected, + required bool ringed, + Color? resting, +}) => selected + ? Border.all(color: palette.selectedBorder, width: 1.5) + : ringed + ? Border.all( + color: palette.selectedBorder.withValues(alpha: 0.5), + width: 1.5, + ) + : resting == null + ? null + : Border.all(color: resting); + /// A tick box: the media menu's, and a note's while the archive is picking /// notes. class _PickBox extends StatelessWidget { @@ -276,7 +295,7 @@ class NoteCardFace extends StatelessWidget { final preview = snippet ?? (blank ? 'Empty' : glance.line ?? (note.isDrawing ? 'Sketch' : null)); - final marks = _marksOf(glance, locked: locked, shared: shared); + final marks = _marksOf(glance.media, locked: locked, shared: shared); final tint = blank ? palette.surfaceBackground : stickyTint(palette, note); final picking = this.picking; @@ -292,16 +311,12 @@ class NoteCardFace extends StatelessWidget { ) : tint, borderRadius: _cardRadius, - border: selected || picking == true - ? Border.all(color: palette.selectedBorder, width: 1.5) - : ringed - ? Border.all( - color: palette.selectedBorder.withValues(alpha: 0.5), - width: 1.5, - ) - : blank - ? Border.all(color: palette.separator) - : null, + border: _cardBorder( + palette, + selected: selected || picking == true, + ringed: ringed, + resting: blank ? palette.separator : null, + ), boxShadow: _cardShadow(palette), ), child: Stack( @@ -491,7 +506,7 @@ class NoteListRowFace extends StatelessWidget { @override Widget build(BuildContext context) { final palette = context.palette; - final marks = _marksOf(glance, locked: locked, shared: shared); + final marks = _marksOf(glance.media, locked: locked, shared: shared); final summary = snippet ?? (note.isEmpty ? 'Empty' : glance.summary); final picking = this.picking; final marked = selected || picking == true; @@ -592,6 +607,306 @@ class NoteListRowFace extends StatelessWidget { } } +/// A drawing shrunk to fit a card or a row, centred, in the theme's ink. +class DrawingThumbnail extends StatelessWidget { + const DrawingThumbnail({super.key, required this.drawing}); + + final NoteDrawing? drawing; + + @override + Widget build(BuildContext context) => CustomPaint( + painter: _ThumbnailPainter( + elements: drawing?.elements ?? const [], + ink: context.palette.textPrimary, + textStyle: Theme.of(context).textTheme.bodyLarge ?? const TextStyle(), + ), + child: const SizedBox.expand(), + ); +} + +class _ThumbnailPainter extends CustomPainter { + _ThumbnailPainter({ + required this.elements, + required this.ink, + required this.textStyle, + }); + + final List elements; + final Color ink; + final TextStyle textStyle; + + static const double _margin = 8; + + @override + void paint(Canvas canvas, Size size) { + final bounds = drawingBounds(elements); + if (bounds == null) return; + final zoom = math.min( + 1.0, + math.min( + (size.width - _margin * 2) / math.max(bounds.width, 1), + (size.height - _margin * 2) / math.max(bounds.height, 1), + ), + ); + canvas.clipRect(Offset.zero & size); + DrawingPainter( + elements: elements, + hidden: const {}, + extra: const [], + selection: const [], + marquee: null, + pan: size.center(Offset.zero) - bounds.center * zoom, + zoom: zoom, + ink: ink, + grid: const Color(0x00000000), + accent: ink, + textStyle: textStyle, + ).paint(canvas, size); + } + + @override + bool shouldRepaint(_ThumbnailPainter old) => + !identical(old.elements, elements) || + old.ink != ink || + old.textStyle != textStyle; +} + +/// A drawing as a card in the Drawings space: a thumbnail of it on the +/// paper, its title in the handwriting face, and when it was last changed. +class DrawingCardFace extends StatelessWidget { + const DrawingCardFace({ + super.key, + required this.note, + required this.date, + required this.selected, + required this.hovering, + this.ringed = false, + this.locked = false, + this.shared = false, + this.picking, + }); + + static const double height = 148; + + final Note note; + final String date; + final bool selected; + final bool hovering; + final bool ringed; + final bool locked; + final bool shared; + final bool? picking; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final picking = this.picking; + final marks = _marksOf(const {}, locked: locked, shared: shared); + return Transform.rotate( + angle: _stickyTilt(note), + child: Container( + padding: const EdgeInsets.fromLTRB(6, 6, 6, 10), + decoration: BoxDecoration( + color: hovering + ? Color.alphaBlend( + palette.textPrimary.withValues(alpha: 0.04), + palette.editorBackground, + ) + : palette.editorBackground, + borderRadius: _cardRadius, + border: _cardBorder( + palette, + selected: selected || picking == true, + ringed: ringed, + resting: palette.separator, + ), + boxShadow: _cardShadow(palette), + ), + child: Stack( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Expanded( + child: ClipRRect( + borderRadius: BorderRadius.circular(4), + child: ColoredBox( + color: palette.sidebarBackground, + child: DrawingThumbnail(drawing: note.drawing), + ), + ), + ), + const SizedBox(height: 7), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 6), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + note.title, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: _handwritten( + 14, + 18, + FontWeight.w500, + palette.cardTitle, + ), + ), + const SizedBox(height: 2), + Row( + children: [ + for (final mark in marks) ...[ + KapyIcon( + mark, + size: 13, + strokeWidth: 1.8, + color: palette.textMuted, + ), + const SizedBox(width: 5), + ], + Flexible( + child: Text( + date, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: _figtree( + AppTypeScale.caption, + 14, + FontWeight.w600, + palette.textMuted, + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + if (picking != null) + Positioned(top: 4, right: 4, child: _PickBox(checked: picking)), + ], + ), + ), + ); + } +} + +/// A drawing as a row in the Drawings space: a small thumbnail of it, then +/// its title over when it was last changed. +class DrawingListRowFace extends StatelessWidget { + const DrawingListRowFace({ + super.key, + required this.note, + required this.date, + required this.selected, + required this.hovering, + this.ringed = false, + this.locked = false, + this.shared = false, + this.picking, + }); + + final Note note; + final String date; + final bool selected; + final bool hovering; + final bool ringed; + final bool locked; + final bool shared; + final bool? picking; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final picking = this.picking; + final marked = selected || picking == true; + final marks = _marksOf(const {}, locked: locked, shared: shared); + return Container( + padding: const EdgeInsets.all(6.5), + decoration: BoxDecoration( + color: marked + ? palette.editorBackground + : hovering + ? palette.hover + : null, + borderRadius: BorderRadius.circular(12), + border: Border.all( + color: marked + ? palette.selectedBorder + : ringed + ? palette.selectedBorder.withValues(alpha: 0.5) + : Colors.transparent, + width: 1.5, + ), + ), + child: Row( + children: [ + if (picking != null) ...[ + _PickBox(checked: picking), + const SizedBox(width: 10), + ], + Container( + width: 56, + height: 40, + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + color: palette.editorBackground, + border: Border.all(color: palette.separator), + borderRadius: BorderRadius.circular(6), + ), + child: DrawingThumbnail(drawing: note.drawing), + ), + const SizedBox(width: 10), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + note.title, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: _figtree(14, 18, FontWeight.w600, palette.cardTitle), + ), + const SizedBox(height: 3), + Row( + children: [ + for (final mark in marks) ...[ + KapyIcon( + mark, + size: 13, + strokeWidth: 1.8, + color: palette.textMuted, + ), + const SizedBox(width: 5), + ], + Flexible( + child: Text( + date, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: _figtree( + AppTypeScale.small, + 16, + FontWeight.w500, + palette.textTertiary, + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + ); + } +} + /// The heading over a group of notes: Pinned or Notes, with how many there /// are, and whatever the group offers at its far end. class NotesListHeading extends StatelessWidget { @@ -599,6 +914,7 @@ class NotesListHeading extends StatelessWidget { super.key, required this.label, required this.count, + this.noun = 'note', this.height = 24, this.leading, this.trailing, @@ -606,6 +922,9 @@ class NotesListHeading extends StatelessWidget { final String label; final int count; + + /// What the list holds, for the count's spoken form: "3 drawings". + final String noun; final double height; final Widget? leading; final Widget? trailing; @@ -639,7 +958,7 @@ class NotesListHeading extends StatelessWidget { ), const SizedBox(width: 7), Tooltip( - message: count == 1 ? '1 note' : '$count notes', + message: count == 1 ? '1 $noun' : '$count ${noun}s', child: Text( '$count', style: _figtree( @@ -707,14 +1026,16 @@ class SeeAllLink extends StatelessWidget { class NotesListControls extends StatelessWidget { const NotesListControls({ super.key, - required this.media, - required this.onMediaChanged, + this.media, + this.onMediaChanged, required this.cards, required this.onCardsChanged, }); - final Set media; - final ValueChanged> onMediaChanged; + /// Null leaves the filter out, as in Drawings, where every item is a + /// drawing. + final Set? media; + final ValueChanged>? onMediaChanged; final bool cards; final ValueChanged onCardsChanged; @@ -769,12 +1090,16 @@ class NotesListControls extends StatelessWidget { ); } + final media = this.media; + final onMediaChanged = this.onMediaChanged; return Row( children: [ - Flexible( - child: _MediaFilter(ticked: media, onChanged: onMediaChanged), - ), - const SizedBox(width: 4), + if (media != null && onMediaChanged != null) ...[ + Flexible( + child: _MediaFilter(ticked: media, onChanged: onMediaChanged), + ), + const SizedBox(width: 4), + ], const Spacer(), Container( padding: const EdgeInsets.all(2), diff --git a/lib/ui/page_toolbar.dart b/lib/ui/page_toolbar.dart index 0356d13..33616a1 100644 --- a/lib/ui/page_toolbar.dart +++ b/lib/ui/page_toolbar.dart @@ -31,6 +31,7 @@ class PageToolbar extends StatelessWidget { required this.onMore, this.section, this.showListShortcut, + this.noun = 'note', this.newNoteShortcut, this.noteOpen = false, this.syncStatus, @@ -56,6 +57,9 @@ class PageToolbar extends StatelessWidget { final VoidCallback onCreate; final String? newNoteShortcut; + /// What New makes here: a note, or a drawing in Drawings. + final String noun; + /// Whether there is a note on the page for Saved to speak for. final bool noteOpen; @@ -131,7 +135,7 @@ class PageToolbar extends StatelessWidget { TonalButton( key: const ValueKey('page-new-note'), icon: KapyIcons.addRounded, - tooltip: ['New note', ?newNoteShortcut].join(' '), + tooltip: ['New $noun', ?newNoteShortcut].join(' '), onPressed: onCreate, ), const SizedBox(width: 10), diff --git a/lib/ui/sidebar.dart b/lib/ui/sidebar.dart index 3d540ca..2de393f 100644 --- a/lib/ui/sidebar.dart +++ b/lib/ui/sidebar.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:math' as math; import 'package:flutter/services.dart'; import 'package:material_ui/material_ui.dart'; @@ -141,7 +142,8 @@ class Sidebar extends StatelessWidget { this.tab = SidebarTab.mine, this.onTabChanged, this.windowBar, - this.emptyMessage, + this.drawings = false, + this.onNewDrawing, this.engine, this.now = DateTime.now, this.cards = false, @@ -267,10 +269,12 @@ class Sidebar extends StatelessWidget { /// one, the list is the compact layout's drawer, under the wordmark. final Widget? windowBar; - /// What the list says when there is nothing in it to show, in place of the - /// name of the folder it would otherwise give. A search that finds nothing - /// still says so. - final String? emptyMessage; + /// Whether the list is the Drawings space: every item a drawing, shown by + /// a thumbnail of it, with no media filter to narrow it by. + final bool drawings; + + /// Starts a drawing from the empty Drawings space. + final VoidCallback? onNewDrawing; /// Works out the sums a card or row shows under a note's title. final CalcEngine? engine; @@ -329,6 +333,7 @@ class Sidebar extends StatelessWidget { belowTabs: _showsTabs, besideRail: _besideRail, pinnedOnly: pinnedOnly, + drawings: drawings, ), if (_besideRail && mediaFilter != null && @@ -337,7 +342,7 @@ class Sidebar extends StatelessWidget { Padding( padding: const EdgeInsets.fromLTRB(18, 0, 18, 12), child: NotesListControls( - media: mediaFilter, + media: drawings ? null : mediaFilter, onMediaChanged: onMediaFilterChanged, cards: cards, onCardsChanged: onCardsChanged, @@ -443,16 +448,20 @@ extension on Sidebar { !_specialMode && !_onSharedTab && query.trim().isEmpty; Widget _buildEmpty(BuildContext context) { + if (drawings && query.trim().isEmpty) { + return _DrawingsEmpty(onNewDrawing: onNewDrawing); + } final empty = _SidebarEmpty( message: query.trim().isEmpty - ? emptyMessage ?? - (archiveMode - ? 'Archived Notes is empty' - : hiddenMode - ? 'Hidden Notes is empty' - : _onSharedTab - ? 'Nothing shared with you yet' - : 'No notes yet') + ? archiveMode + ? 'Archived Notes is empty' + : hiddenMode + ? 'Hidden Notes is empty' + : _onSharedTab + ? 'Nothing shared with you yet' + : 'No notes yet' + : drawings + ? 'No matching drawings' : 'No matching notes', detail: query.trim().isEmpty && _onSharedTab ? 'Notes other people share with you appear here' @@ -685,7 +694,13 @@ extension on Sidebar { final groups = _noteGroups; final pinned = _shownPinned(groups); final rows = []; - final style = cards ? NoteRowStyle.card : NoteRowStyle.row; + final style = switch ((cards, drawings)) { + (true, true) => NoteRowStyle.drawingCard, + (true, false) => NoteRowStyle.card, + (false, true) => NoteRowStyle.drawingRow, + (false, false) => NoteRowStyle.row, + }; + final noun = drawings ? 'drawing' : 'note'; final onPinnedOnlyChanged = this.onPinnedOnlyChanged; void gap(double height) => rows.add((_) => SizedBox(height: height)); @@ -728,7 +743,10 @@ extension on Sidebar { (context) => Padding( padding: const EdgeInsets.symmetric(horizontal: 18), child: SizedBox( - height: AppControlMetrics.scaleBar(context, NoteCardFace.height), + height: AppControlMetrics.scaleBar( + context, + drawings ? DrawingCardFace.height : NoteCardFace.height, + ), child: Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -758,6 +776,7 @@ extension on Sidebar { NotesListHeading( label: 'Pinned', count: groups.pinned.length, + noun: noun, height: 22, leading: Row( mainAxisSize: MainAxisSize.min, @@ -790,6 +809,7 @@ extension on Sidebar { key: const ValueKey('sidebar-pinned-heading'), label: 'Pinned', count: groups.pinned.length, + noun: noun, height: 22, leading: pin, trailing: @@ -829,8 +849,13 @@ extension on Sidebar { heading( NotesListHeading( key: const ValueKey('sidebar-notes-heading'), - label: groups.hasSharedSections && !_tabbed ? 'My notes' : 'Notes', + label: drawings + ? 'Drawings' + : groups.hasSharedSections && !_tabbed + ? 'My notes' + : 'Notes', count: groups.mine.length, + noun: noun, ), ); section(groups.mine); @@ -1756,12 +1781,16 @@ class SidebarWindowBar extends StatelessWidget { required this.count, required this.onCreate, required this.onHide, + this.noun = 'note', this.newNoteShortcut, this.hideShortcut, }); final String title; + /// What the space holds and New makes: a note, or a drawing in Drawings. + final String noun; + /// How many notes the space holds, whatever a search has narrowed the list /// to. final int count; @@ -1842,8 +1871,8 @@ class SidebarWindowBar extends StatelessWidget { // read as just a number. Tooltip( message: count == 1 - ? '1 note' - : '$count notes', + ? '1 $noun' + : '$count ${noun}s', child: Text( '$count', key: const ValueKey('sidebar-space-count'), @@ -1867,14 +1896,14 @@ class SidebarWindowBar extends StatelessWidget { TonalButton( key: const ValueKey('sidebar-new-note'), icon: KapyIcons.addRounded, - label: label ? 'New note' : null, + label: label ? 'New $noun' : null, shortcut: keycap ? newNoteShortcut?.keycapLabel : null, // Without its keycap the button still teaches the // chord, on hover. tooltip: keycap ? null : [ - 'New note', + 'New $noun', ?newNoteShortcut?.displayLabel, ].join(' '), onPressed: onCreate, @@ -2391,8 +2420,12 @@ class _SearchField extends StatefulWidget { this.belowTabs = false, this.besideRail = false, this.pinnedOnly = false, + this.drawings = false, }); + /// Searching the Drawings space. + final bool drawings; + /// Sits under the tabs rather than the title bar, and needs less room /// above it to read as part of the same header. final bool belowTabs; @@ -2455,6 +2488,8 @@ class _SearchFieldState extends State<_SearchField> { ? 'Find in Hidden…' : widget.pinnedOnly ? 'Find in pinned…' + : widget.drawings + ? 'Find a drawing…' : 'Find a note…'; return Padding( padding: const EdgeInsets.fromLTRB(18, 0, 18, 12), @@ -2645,7 +2680,7 @@ class _SearchShortcutHint extends StatelessWidget { /// How a [NoteRow] draws its note: the compact list's row, or the desktop /// list's row or sticky card beside the spaces rail. -enum NoteRowStyle { compact, row, card } +enum NoteRowStyle { compact, row, card, drawingRow, drawingCard } /// One row in the note list. class NoteRow extends StatefulWidget { @@ -2968,7 +3003,9 @@ class _NoteRowState extends State { note.updatedAt, now: widget.now(), displayTime: widget.displayTime, - today: widget.style == NoteRowStyle.card, + today: + widget.style == NoteRowStyle.card || + widget.style == NoteRowStyle.drawingCard, ) : typingStatusText([ for (final person in people) @@ -2978,31 +3015,52 @@ class _NoteRowState extends State { final glance = NoteGlance.of(note, widget.engine); final picking = widget.selecting ? widget.checked : null; final ringed = widget.openElsewhere && !widget.selected; - final face = widget.style == NoteRowStyle.card - ? NoteCardFace( - note: note, - glance: glance, - date: date, - snippet: snippet, - selected: widget.selected, - hovering: _hovering, - ringed: ringed, - locked: widget.locked, - shared: widget.shared, - picking: picking, - ) - : NoteListRowFace( - note: note, - glance: glance, - date: date, - snippet: snippet, - selected: widget.selected, - hovering: _hovering, - ringed: ringed, - locked: widget.locked, - shared: widget.shared, - picking: picking, - ); + final face = switch (widget.style) { + NoteRowStyle.card => NoteCardFace( + note: note, + glance: glance, + date: date, + snippet: snippet, + selected: widget.selected, + hovering: _hovering, + ringed: ringed, + locked: widget.locked, + shared: widget.shared, + picking: picking, + ), + NoteRowStyle.drawingCard => DrawingCardFace( + note: note, + date: date, + selected: widget.selected, + hovering: _hovering, + ringed: ringed, + locked: widget.locked, + shared: widget.shared, + picking: picking, + ), + NoteRowStyle.drawingRow => DrawingListRowFace( + note: note, + date: date, + selected: widget.selected, + hovering: _hovering, + ringed: ringed, + locked: widget.locked, + shared: widget.shared, + picking: picking, + ), + NoteRowStyle.row || NoteRowStyle.compact => NoteListRowFace( + note: note, + glance: glance, + date: date, + snippet: snippet, + selected: widget.selected, + hovering: _hovering, + ringed: ringed, + locked: widget.locked, + shared: widget.shared, + picking: picking, + ), + }; if (!hasMenu || !_hovering) return face; return Stack( children: [ @@ -3542,6 +3600,85 @@ class _SpaceHeader extends StatelessWidget { } } +/// The Drawings space with nothing in it: what will go here, and the way to +/// start. +class _DrawingsEmpty extends StatelessWidget { + const _DrawingsEmpty({required this.onNewDrawing}); + + final VoidCallback? onNewDrawing; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + const handwritten = WritingFont.handwritten; + final onNewDrawing = this.onNewDrawing; + return SingleChildScrollView( + padding: const EdgeInsets.fromLTRB(24, 96, 24, 24), + child: Column( + children: [ + Transform.rotate( + angle: -3 * math.pi / 180, + child: Container( + width: 72, + height: 72, + decoration: BoxDecoration( + color: palette.editorBackground, + border: Border.all(color: palette.separator), + borderRadius: BorderRadius.circular(20), + ), + alignment: Alignment.center, + child: KapyIcon( + KapyIcons.penRounded, + size: 30, + strokeWidth: 1.5, + color: palette.textTertiary, + ), + ), + ), + const SizedBox(height: 16), + Text( + 'No drawings yet', + textAlign: TextAlign.center, + style: TextStyle( + fontFamily: handwritten.fontFamily, + fontFamilyFallback: handwritten.fontFamilyFallback, + fontVariations: handwritten.fontVariations, + fontSize: 16, + height: 22 / 16, + fontWeight: FontWeight.w600, + color: palette.textSubheading, + ), + ), + const SizedBox(height: 10), + SizedBox( + width: 220, + child: Text( + 'Sketches, diagrams and wireframes live here, apart from your ' + 'notes.', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: AppTypeScale.small, + height: 18 / 13, + fontWeight: FontWeight.w500, + color: palette.textTertiary, + ), + ), + ), + if (onNewDrawing != null) ...[ + const SizedBox(height: 16), + TonalButton( + key: const ValueKey('sidebar-empty-new-drawing'), + icon: KapyIcons.addRounded, + label: 'New drawing', + onPressed: onNewDrawing, + ), + ], + ], + ), + ); + } +} + class _SidebarEmpty extends StatelessWidget { const _SidebarEmpty({required this.message, this.detail}); diff --git a/test/app_test.dart b/test/app_test.dart index e9cfc28..a9d9fa8 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -4866,7 +4866,7 @@ void main() { ); }); - testWidgets('Drawings lists only drawings, until a new note is made', ( + testWidgets('Drawings lists only drawings, and New there makes one', ( tester, ) async { store.data['notes.v1'] = [ @@ -4891,12 +4891,79 @@ void main() { expect(rowTitles(tester), unorderedEquals(['Words', 'Sketch'])); expect(spaceTitle(tester), 'My notes'); - // A new note is not a drawing yet, so the list goes back to show it. + // New in Drawings makes a drawing, so the list stays where it is. await openSpace(tester, 'drawings'); await tester.tap(find.byKey(const ValueKey('sidebar-new-note'))); await tester.pumpAndSettle(); - expect(spaceTitle(tester), 'My notes'); + expect(spaceTitle(tester), 'Drawings'); + expect(spaceCount(tester), '2'); expect(notes.notes, hasLength(3)); + expect(notes.notes.where((note) => note.isDrawing), hasLength(2)); + expect(find.byType(DrawingCanvas), findsOneWidget); + }); + + testWidgets('every New in Drawings makes a drawing', (tester) async { + await notes.load(); + notes.create(body: 'Words'); + await pumpApp(tester); + await openSpace(tester, 'drawings'); + + // Each New opens a fresh drawing; the blank one before it is swept the + // way a blank note is, so what counts is the drawing that is open. + final opened = []; + void expectNewDrawing() { + final canvas = tester.widget(find.byType(DrawingCanvas)); + final id = (canvas.key! as ValueKey).value.substring( + 'drawing-'.length, + ); + expect(opened, isNot(contains(id))); + expect(notes.byId(id)!.isDrawing, isTrue); + opened.add(id); + } + + await tester.tap(find.byKey(const ValueKey('sidebar-empty-new-drawing'))); + await tester.pumpAndSettle(); + expectNewDrawing(); + + await tester.tap(find.byKey(const ValueKey('sidebar-new-note'))); + await tester.pumpAndSettle(); + expectNewDrawing(); + + await pressShortcut( + tester, + shortcuts.bindingFor(ShortcutAction.newNote)!, + ); + expectNewDrawing(); + + await tester.tap(notesToggleWithLabel('Hide notes')); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const ValueKey('page-new-note'))); + await tester.pumpAndSettle(); + expectNewDrawing(); + + await tester.tap(notesToggleWithLabel('Show notes')); + await tester.pumpAndSettle(); + expect(spaceTitle(tester), 'Drawings'); + expect(notes.byId(opened.last), isNotNull); + }); + + testWidgets('Drawings has no media filter', (tester) async { + await notes.load(); + notes.create(body: 'Words'); + await pumpApp(tester); + expect( + find.byKey(const ValueKey('sidebar-media-filter')), + findsOneWidget, + ); + + await openSpace(tester, 'drawings'); + expect(find.byKey(const ValueKey('sidebar-media-filter')), findsNothing); + + await openSpace(tester, 'notes'); + expect( + find.byKey(const ValueKey('sidebar-media-filter')), + findsOneWidget, + ); }); testWidgets('Drawings says so while there are none', (tester) async { diff --git a/test/golden_test.dart b/test/golden_test.dart index 6f0af7a..cef3839 100644 --- a/test/golden_test.dart +++ b/test/golden_test.dart @@ -11,6 +11,7 @@ import 'package:http/testing.dart'; import 'package:kapy_notes/app.dart'; import 'package:kapy_notes/core/platform.dart'; import 'package:kapy_notes/data/layout_prefs.dart'; +import 'package:kapy_notes/data/note_drawing.dart'; import 'package:kapy_notes/data/notes_store.dart'; import 'package:kapy_notes/data/onboarding.dart'; import 'package:kapy_notes/data/rates.dart'; @@ -76,6 +77,10 @@ Future pumpForGolden( bool sidebarVisible = true, bool withPinnedNote = false, + /// Drawings in the store, the newest pinned, for the Drawings space. + bool withDrawings = false, + bool cards = true, + /// Which build the image is of. /// /// Sizes in this app resolve from [AppPlatform.hasPointer], not from the @@ -197,6 +202,8 @@ Future pumpForGolden( // opened at least once. A new install starts with it closed, which is what // the first-launch images ask for. if (prefs.sidebarVisible != sidebarVisible) prefs.toggleSidebar(); + prefs.noteCards = cards; + if (withDrawings) _seedDrawings(notes); if (withNote) { final note = notes.create(); if (withImages) { @@ -238,6 +245,71 @@ Future pumpForGolden( await tester.pumpAndSettle(); } +/// Five drawings, the first pinned: boxes, an arrow, a scribble and a word, +/// in the swatches the colour popover offers. +void _seedDrawings(NotesStore notes) { + const titles = [ + 'Q4 goals map', + 'App wireframe', + 'Onboarding flow', + 'Living room', + 'Garden plan', + ]; + for (final (seed, title) in titles.indexed) { + var z = 0; + DrawElement element( + DrawKind kind, + List points, { + int? color, + double width = 3, + String text = '', + }) => DrawElement( + id: '$seed-$z', + kind: kind, + points: points, + z: z++, + color: color, + width: width, + text: text, + ); + final note = notes.create(); + notes.setDrawingMode(note.id, drawing: true); + notes.updateDrawing( + note.id, + NoteDrawing([ + element(DrawKind.rect, [40, 40, 260, 160]), + element(DrawKind.ellipse, [320, 60, 460, 170], color: 0xFF6F8F52), + element(DrawKind.arrow, [260, 100, 320, 110]), + element(DrawKind.text, [60, 80], text: seed.isEven ? 'Idea' : 'Herbs'), + element( + DrawKind.pen, + [ + for (var i = 0; i < 30; i++) ...[ + 60.0 + i * 12, + 240 + (i % 5) * 8.0, + ], + ], + color: 0xFF3F8796, + width: 4, + ), + if (seed.isOdd) + element(DrawKind.ellipse, [120, 260, 220, 330], color: 0xFFD0663B), + ]), + title: title, + ); + if (seed == titles.length - 1) notes.togglePinned(note.id); + } +} + +/// Opens Drawings from the rail, and [open] from its list when given. +Future _openDrawings(WidgetTester tester, {String? open}) async { + await tester.tap(find.byKey(const ValueKey('rail-drawings'))); + await tester.pumpAndSettle(); + if (open == null) return; + await tester.tap(find.text(open).first); + await tester.pumpAndSettle(); +} + /// Resolves the exact size-aware keys the first frame requested. File I/O only /// advances under `runAsync` in a widget test; the real app has no fake clock. Future _warmVisibleNoteImages(WidgetTester tester) async { @@ -683,6 +755,68 @@ void main() { ); }); + testWidgets('desktop dark drawings', (tester) async { + await pumpForGolden( + tester, + size: const Size(1100, 720), + brightness: Brightness.dark, + withNote: false, + withDrawings: true, + ); + await _openDrawings(tester, open: 'Garden plan'); + await expectLater( + find.byType(KapyNotesApp), + matchesGoldenFile('goldens/desktop_dark_drawings.png'), + ); + }); + + testWidgets('desktop light drawings with the colour popover', (tester) async { + await pumpForGolden( + tester, + size: const Size(1100, 720), + brightness: Brightness.light, + withNote: false, + withDrawings: true, + ); + await _openDrawings(tester, open: 'Garden plan'); + await tester.tap(find.byKey(const ValueKey('draw-style'))); + await tester.pumpAndSettle(); + await expectLater( + find.byType(KapyNotesApp), + matchesGoldenFile('goldens/desktop_light_drawings_style.png'), + ); + }); + + testWidgets('desktop dark drawings list', (tester) async { + await pumpForGolden( + tester, + size: const Size(1100, 720), + brightness: Brightness.dark, + withNote: false, + withDrawings: true, + cards: false, + ); + await _openDrawings(tester, open: 'Garden plan'); + await expectLater( + find.byType(KapyNotesApp), + matchesGoldenFile('goldens/desktop_dark_drawings_list.png'), + ); + }); + + testWidgets('desktop dark drawings, none yet and none open', (tester) async { + await pumpForGolden( + tester, + size: const Size(1100, 720), + brightness: Brightness.dark, + withNote: false, + ); + await _openDrawings(tester); + await expectLater( + find.byType(KapyNotesApp), + matchesGoldenFile('goldens/desktop_dark_drawings_empty.png'), + ); + }); + testWidgets('desktop dark note with images', (tester) async { await pumpForGolden( tester, diff --git a/test/goldens/desktop_dark_drawings.png b/test/goldens/desktop_dark_drawings.png new file mode 100644 index 0000000..2753afc Binary files /dev/null and b/test/goldens/desktop_dark_drawings.png differ diff --git a/test/goldens/desktop_dark_drawings_empty.png b/test/goldens/desktop_dark_drawings_empty.png new file mode 100644 index 0000000..672d546 Binary files /dev/null and b/test/goldens/desktop_dark_drawings_empty.png differ diff --git a/test/goldens/desktop_dark_drawings_list.png b/test/goldens/desktop_dark_drawings_list.png new file mode 100644 index 0000000..2bd355e Binary files /dev/null and b/test/goldens/desktop_dark_drawings_list.png differ diff --git a/test/goldens/desktop_light_drawings_style.png b/test/goldens/desktop_light_drawings_style.png new file mode 100644 index 0000000..ed2e8b9 Binary files /dev/null and b/test/goldens/desktop_light_drawings_style.png differ