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

Add YaruPageIndicator(ThemeData).mouseCursor #654

Merged
merged 1 commit into from
Mar 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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