diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0181a..e68dc9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - feat: `NesWindow` uses `NesContainerTheme` instead of Material's card. - feat: update mini sprite to improve icons. - feat: add `NesIcons.center`. + - feat: add ability to customize mouse cursors used by the package. # 0.12.1 - fix: theme lerp causing error on null access. diff --git a/lib/src/theme.dart b/lib/src/theme.dart index e612b6e..2f1c792 100644 --- a/lib/src/theme.dart +++ b/lib/src/theme.dart @@ -10,16 +10,102 @@ class NesTheme extends ThemeExtension { /// {@macro nes_theme} const NesTheme({ required this.pixelSize, + this.clickCursor = SystemMouseCursors.click, + this.resizeLeftRightCursor = SystemMouseCursors.resizeLeftRight, + this.resizeUpDownCursor = SystemMouseCursors.resizeUpDown, + this.moveCursor = SystemMouseCursors.move, + this.resizeUpLeftDownRightCursor = SystemMouseCursors.resizeUpLeftDownRight, + this.resizeUpRightDownLeftCursor = SystemMouseCursors.resizeUpRightDownLeft, + this.resizeUpCursor = SystemMouseCursors.resizeUp, + this.resizeDownCursor = SystemMouseCursors.resizeDown, + this.resizeLeftCursor = SystemMouseCursors.resizeLeft, + this.resizeRightCursor = SystemMouseCursors.resizeRight, }); /// The size of a pixel unit used in Flutter nes, like the width /// of a border of a button. final int pixelSize; + /// When provided, the cursor used when hovering over a button + /// or anything that is clickable. + /// + /// Defaults to [SystemMouseCursors.click]. + final MouseCursor clickCursor; + + /// When provided, the cursor used when hovering over a resize corner + /// + /// Defaults to [SystemMouseCursors.resizeLeftRight]. + final MouseCursor resizeLeftRightCursor; + + /// When provided, the cursor used when hovering over a resize corner + /// + /// Defaults to [SystemMouseCursors.resizeUpDown]. + final MouseCursor resizeUpDownCursor; + + /// When provided, the cursor used when hovering over a resize corner + /// + /// Defaults to [SystemMouseCursors.resizeUpLeftDownRight]. + final MouseCursor resizeUpLeftDownRightCursor; + + /// When provided, the cursor used when hovering over a resize corner + /// + /// Defaults to [SystemMouseCursors.resizeUpRightDownLeft]. + final MouseCursor resizeUpRightDownLeftCursor; + + /// When provided, the cursor used when hovering over the up side. + /// + /// Defaults to [SystemMouseCursors.resizeUp]. + final MouseCursor resizeUpCursor; + + /// When provided, the cursor used when hovering over the bottom side. + /// + /// Defaults to [SystemMouseCursors.resizeDown]. + final MouseCursor resizeDownCursor; + + /// When provided, the cursor used when hovering over the left side. + /// + /// Defaults to [SystemMouseCursors.resizeLeft]. + final MouseCursor resizeLeftCursor; + + /// When provided, the cursor used when hovering over the right side. + /// + /// Defaults to [SystemMouseCursors.resizeRight]. + final MouseCursor resizeRightCursor; + + /// When provided, the cursor used when hovering over a moveable widget. + /// + /// Defaults to [SystemMouseCursors.move]. + final MouseCursor moveCursor; + @override - NesTheme copyWith({int? pixelSize}) { + NesTheme copyWith({ + int? pixelSize, + MouseCursor? clickCursor, + MouseCursor? resizeLeftRightCursor, + MouseCursor? resizeUpDownCursor, + MouseCursor? moveCursor, + MouseCursor? resizeUpLeftDownRightCursor, + MouseCursor? resizeUpRightDownLeftCursor, + MouseCursor? resizeUpCursor, + MouseCursor? resizeDownCursor, + MouseCursor? resizeLeftCursor, + MouseCursor? resizeRightCursor, + }) { return NesTheme( pixelSize: pixelSize ?? this.pixelSize, + clickCursor: clickCursor ?? this.clickCursor, + resizeLeftRightCursor: + resizeLeftRightCursor ?? this.resizeLeftRightCursor, + resizeUpDownCursor: resizeUpDownCursor ?? this.resizeUpDownCursor, + moveCursor: moveCursor ?? this.moveCursor, + resizeUpLeftDownRightCursor: + resizeUpLeftDownRightCursor ?? this.resizeUpLeftDownRightCursor, + resizeUpRightDownLeftCursor: + resizeUpRightDownLeftCursor ?? this.resizeUpRightDownLeftCursor, + resizeUpCursor: resizeUpCursor ?? this.resizeUpCursor, + resizeDownCursor: resizeDownCursor ?? this.resizeDownCursor, + resizeLeftCursor: resizeLeftCursor ?? this.resizeLeftCursor, + resizeRightCursor: resizeRightCursor ?? this.resizeRightCursor, ); } @@ -31,6 +117,19 @@ class NesTheme extends ThemeExtension { begin: pixelSize, end: otherExt?.pixelSize ?? pixelSize, ).lerp(t), + clickCursor: otherExt?.clickCursor ?? clickCursor, + resizeLeftRightCursor: + otherExt?.resizeLeftRightCursor ?? resizeLeftRightCursor, + resizeUpDownCursor: otherExt?.resizeUpDownCursor ?? resizeUpDownCursor, + moveCursor: otherExt?.moveCursor ?? moveCursor, + resizeUpLeftDownRightCursor: + otherExt?.resizeUpLeftDownRightCursor ?? resizeUpLeftDownRightCursor, + resizeUpRightDownLeftCursor: + otherExt?.resizeUpRightDownLeftCursor ?? resizeUpRightDownLeftCursor, + resizeUpCursor: otherExt?.resizeUpCursor ?? resizeUpCursor, + resizeDownCursor: otherExt?.resizeDownCursor ?? resizeDownCursor, + resizeLeftCursor: otherExt?.resizeLeftCursor ?? resizeLeftCursor, + resizeRightCursor: otherExt?.resizeRightCursor ?? resizeRightCursor, ); } } diff --git a/lib/src/widgets/nes_pressabled.dart b/lib/src/widgets/nes_pressabled.dart index c77c985..12a4611 100644 --- a/lib/src/widgets/nes_pressabled.dart +++ b/lib/src/widgets/nes_pressabled.dart @@ -52,7 +52,7 @@ class _NesPressableState extends State { return Transform.translate( offset: offSet, child: MouseRegion( - cursor: SystemMouseCursors.click, + cursor: nesTheme.clickCursor, child: GestureDetector( behavior: widget.behavior, onTap: () { diff --git a/lib/src/widgets/nes_split_panel.dart b/lib/src/widgets/nes_split_panel.dart index d317fd1..d38e2e5 100644 --- a/lib/src/widgets/nes_split_panel.dart +++ b/lib/src/widgets/nes_split_panel.dart @@ -159,6 +159,7 @@ class NesSplitPanelResizeHandler extends StatelessWidget { @override Widget build(BuildContext context) { + final nesTheme = context.nesThemeExtension(); final children = [ Expanded(child: child), GestureDetector( @@ -172,8 +173,8 @@ class NesSplitPanelResizeHandler extends StatelessWidget { }, child: MouseRegion( cursor: orientation == Axis.horizontal - ? SystemMouseCursors.resizeLeftRight - : SystemMouseCursors.resizeUpDown, + ? nesTheme.resizeLeftRightCursor + : nesTheme.resizeUpDownCursor, child: Container( width: orientation == Axis.horizontal ? resizerSize : null, height: orientation == Axis.vertical ? resizerSize : null, diff --git a/lib/src/widgets/nes_window.dart b/lib/src/widgets/nes_window.dart index 9fb15fe..3bfd0a9 100644 --- a/lib/src/widgets/nes_window.dart +++ b/lib/src/widgets/nes_window.dart @@ -50,8 +50,8 @@ class NesWindow extends StatelessWidget { /// The window child. final Widget? child; - MouseCursor _cursorFallback(MouseCursor cursor) { - if (!kIsWeb && Platform.isMacOS) { + MouseCursor _cursorFallback(MouseCursor cursor, MouseCursor defaultCursor) { + if (defaultCursor == cursor && !kIsWeb && Platform.isMacOS) { return SystemMouseCursors.grab; } return cursor; @@ -127,7 +127,10 @@ class NesWindow extends StatelessWidget { titleBar else MouseRegion( - cursor: _cursorFallback(SystemMouseCursors.move), + cursor: _cursorFallback( + nesTheme.moveCursor, + SystemMouseCursors.move, + ), child: GestureDetector( onPanUpdate: (details) { onMove?.call(details.delta); @@ -156,6 +159,7 @@ class NesWindow extends StatelessWidget { left: 0, child: _ResizeHandler( cursor: _cursorFallback( + nesTheme.resizeUpLeftDownRightCursor, SystemMouseCursors.resizeUpLeftDownRight, ), width: 12, @@ -180,6 +184,7 @@ class NesWindow extends StatelessWidget { right: 0, child: _ResizeHandler( cursor: _cursorFallback( + nesTheme.resizeUpRightDownLeftCursor, SystemMouseCursors.resizeUpRightDownLeft, ), width: 12, @@ -204,6 +209,7 @@ class NesWindow extends StatelessWidget { left: 0, child: _ResizeHandler( cursor: _cursorFallback( + nesTheme.resizeUpRightDownLeftCursor, SystemMouseCursors.resizeUpRightDownLeft, ), width: 12, @@ -228,6 +234,7 @@ class NesWindow extends StatelessWidget { right: 0, child: _ResizeHandler( cursor: _cursorFallback( + nesTheme.resizeUpLeftDownRightCursor, SystemMouseCursors.resizeUpLeftDownRight, ), width: 12, @@ -248,7 +255,7 @@ class NesWindow extends StatelessWidget { left: 12, right: 12, child: _ResizeHandler( - cursor: SystemMouseCursors.resizeUp, + cursor: nesTheme.resizeUpCursor, width: double.infinity, height: 12, handleDelta: (offset) { @@ -271,7 +278,7 @@ class NesWindow extends StatelessWidget { left: 12, right: 12, child: _ResizeHandler( - cursor: SystemMouseCursors.resizeDown, + cursor: nesTheme.resizeDownCursor, width: double.infinity, height: 12, handleDelta: (offset) { @@ -290,7 +297,7 @@ class NesWindow extends StatelessWidget { bottom: 12, left: 0, child: _ResizeHandler( - cursor: SystemMouseCursors.resizeLeft, + cursor: nesTheme.resizeLeftCursor, width: 12, height: double.infinity, handleDelta: (offset) { @@ -313,7 +320,7 @@ class NesWindow extends StatelessWidget { bottom: 12, right: 0, child: _ResizeHandler( - cursor: SystemMouseCursors.resizeRight, + cursor: nesTheme.resizeRightCursor, width: 12, height: double.infinity, handleDelta: (offset) {