Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to customize the package cursors #121

Merged
merged 1 commit into from
Jan 29, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
101 changes: 100 additions & 1 deletion lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,102 @@ class NesTheme extends ThemeExtension<NesTheme> {
/// {@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,
);
}

Expand All @@ -31,6 +117,19 @@ class NesTheme extends ThemeExtension<NesTheme> {
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,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/nes_pressabled.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _NesPressableState extends State<NesPressable> {
return Transform.translate(
offset: offSet,
child: MouseRegion(
cursor: SystemMouseCursors.click,
cursor: nesTheme.clickCursor,
child: GestureDetector(
behavior: widget.behavior,
onTap: () {
Expand Down
5 changes: 3 additions & 2 deletions lib/src/widgets/nes_split_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class NesSplitPanelResizeHandler extends StatelessWidget {

@override
Widget build(BuildContext context) {
final nesTheme = context.nesThemeExtension<NesTheme>();
final children = [
Expanded(child: child),
GestureDetector(
Expand All @@ -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,
Expand Down
21 changes: 14 additions & 7 deletions lib/src/widgets/nes_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -156,6 +159,7 @@ class NesWindow extends StatelessWidget {
left: 0,
child: _ResizeHandler(
cursor: _cursorFallback(
nesTheme.resizeUpLeftDownRightCursor,
SystemMouseCursors.resizeUpLeftDownRight,
),
width: 12,
Expand All @@ -180,6 +184,7 @@ class NesWindow extends StatelessWidget {
right: 0,
child: _ResizeHandler(
cursor: _cursorFallback(
nesTheme.resizeUpRightDownLeftCursor,
SystemMouseCursors.resizeUpRightDownLeft,
),
width: 12,
Expand All @@ -204,6 +209,7 @@ class NesWindow extends StatelessWidget {
left: 0,
child: _ResizeHandler(
cursor: _cursorFallback(
nesTheme.resizeUpRightDownLeftCursor,
SystemMouseCursors.resizeUpRightDownLeft,
),
width: 12,
Expand All @@ -228,6 +234,7 @@ class NesWindow extends StatelessWidget {
right: 0,
child: _ResizeHandler(
cursor: _cursorFallback(
nesTheme.resizeUpLeftDownRightCursor,
SystemMouseCursors.resizeUpLeftDownRight,
),
width: 12,
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading