Skip to content

Commit

Permalink
Add YaruPageIndicator(ThemeData).mouseCursor (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Mar 5, 2023
1 parent a0e8e92 commit ddf5ac9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/src/widgets/yaru_page_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class YaruPageIndicator extends StatelessWidget {
this.dotSize,
this.dotSpacing,
this.dotDecorationBuilder,
this.mouseCursor,
}) : assert(page >= 0 && page <= length - 1);

/// Determine the number of pages.
Expand Down Expand Up @@ -67,6 +68,9 @@ class YaruPageIndicator extends StatelessWidget {
/// Decoration of the dots.
final YaruDotDecorationBuilder? dotDecorationBuilder;

/// The cursor for a mouse pointer when it enters or is hovering over the widget.
final MouseCursor? mouseCursor;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
Expand Down Expand Up @@ -113,6 +117,10 @@ class YaruPageIndicator extends StatelessWidget {
Duration.zero;
final animationCurve =
this.animationCurve ?? indicatorTheme?.animationCurve ?? Curves.linear;
final mouseCursor = this.mouseCursor ??
indicatorTheme?.mouseCursor
?.resolve({if (onTap == null) MaterialState.disabled}) ??
(onTap == null ? SystemMouseCursors.basic : SystemMouseCursors.click);

return Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -132,9 +140,7 @@ class YaruPageIndicator extends StatelessWidget {
child: Padding(
padding: EdgeInsets.only(left: index != 0 ? dotSpacing : 0),
child: MouseRegion(
cursor: onTap == null
? SystemMouseCursors.basic
: SystemMouseCursors.click,
cursor: mouseCursor,
child: animationDuration == Duration.zero
? Container(
width: dotSize,
Expand Down
11 changes: 10 additions & 1 deletion lib/src/widgets/yaru_page_indicator_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class YaruPageIndicatorThemeData
this.dotSize,
this.dotSpacing,
this.dotDecorationBuilder,
this.mouseCursor,
});

/// Duration of a transition between two items.
Expand All @@ -39,6 +40,9 @@ class YaruPageIndicatorThemeData
/// Decoration of the dots.
final YaruDotDecorationBuilder? dotDecorationBuilder;

/// The cursor for a mouse pointer when it enters or is hovering over the widget.
final MaterialStateProperty<MouseCursor?>? mouseCursor;

/// Creates a copy with the given fields replaced with new values.
@override
YaruPageIndicatorThemeData copyWith({
Expand All @@ -47,13 +51,15 @@ class YaruPageIndicatorThemeData
double? dotSize,
double? dotSpacing,
YaruDotDecorationBuilder? dotDecorationBuilder,
MaterialStateProperty<MouseCursor?>? mouseCursor,
}) {
return YaruPageIndicatorThemeData(
animationDuration: animationDuration ?? this.animationDuration,
animationCurve: animationCurve ?? this.animationCurve,
dotSize: dotSize ?? this.dotSize,
dotSpacing: dotSpacing ?? this.dotSpacing,
dotDecorationBuilder: dotDecorationBuilder ?? this.dotDecorationBuilder,
mouseCursor: mouseCursor ?? this.mouseCursor,
);
}

Expand All @@ -74,6 +80,7 @@ class YaruPageIndicatorThemeData
dotSpacing: lerpDouble(dotSpacing, o?.dotSpacing, t),
dotDecorationBuilder:
t < 0.5 ? dotDecorationBuilder : o?.dotDecorationBuilder,
mouseCursor: t < 0.5 ? mouseCursor : o?.mouseCursor,
);
}

Expand All @@ -85,6 +92,7 @@ class YaruPageIndicatorThemeData
dotSize,
dotSpacing,
dotDecorationBuilder,
mouseCursor,
);
}

Expand All @@ -97,7 +105,8 @@ class YaruPageIndicatorThemeData
other.animationCurve == animationCurve &&
other.dotSize == dotSize &&
other.dotSpacing == dotSpacing &&
other.dotDecorationBuilder == dotDecorationBuilder;
other.dotDecorationBuilder == dotDecorationBuilder &&
other.mouseCursor == mouseCursor;
}
}

Expand Down

0 comments on commit ddf5ac9

Please sign in to comment.