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

Check/Radio/Switch/Button/ListTile: allow customizing mouse cursor #648

Merged
merged 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/src/widgets/yaru_check_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'yaru_checkbox.dart';
import 'yaru_toggle_button.dart';
import 'yaru_toggle_button_theme.dart';

/// A desktop style check button with an interactive label.
class YaruCheckButton extends StatelessWidget {
Expand All @@ -16,6 +17,7 @@ class YaruCheckButton extends StatelessWidget {
this.tristate = false,
this.autofocus = false,
this.focusNode,
this.mouseCursor,
});

/// See [Checkbox.value]
Expand All @@ -42,8 +44,16 @@ class YaruCheckButton extends StatelessWidget {
/// See [Checkbox.autofocus].
final bool autofocus;

/// See [Checkbox.mouseCursor].
final MouseCursor? mouseCursor;

@override
Widget build(BuildContext context) {
final mouseCursor = this.mouseCursor ??
YaruToggleButtonTheme.of(context)
?.mouseCursor
?.resolve({if (onChanged == null) MaterialState.disabled});

return YaruToggleButton(
title: title,
subtitle: subtitle,
Expand All @@ -54,7 +64,12 @@ class YaruCheckButton extends StatelessWidget {
tristate: tristate,
focusNode: focusNode,
autofocus: autofocus,
mouseCursor: mouseCursor,
),
mouseCursor: mouseCursor ??
(onChanged != null
? SystemMouseCursors.click
: SystemMouseCursors.basic),
onToggled: onChanged == null ? null : _onToggled,
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/widgets/yaru_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class YaruCheckbox extends StatefulWidget implements YaruTogglable<bool?> {
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
this.mouseCursor,
}) : assert(tristate || value != null);

/// Whether this checkbox is checked.
Expand Down Expand Up @@ -125,6 +126,9 @@ class YaruCheckbox extends StatefulWidget implements YaruTogglable<bool?> {
@override
final bool autofocus;

@override
final MouseCursor? mouseCursor;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down Expand Up @@ -249,6 +253,9 @@ class _YaruCheckboxState extends YaruTogglableState<YaruCheckbox> {
..disabledCheckmarkColor = disabledCheckmarkColor
..hoverIndicatorColor = hoverIndicatorColor
..focusIndicatorColor = focusIndicatorColor,
mouseCursor: widget.mouseCursor ??
checkboxTheme.mouseCursor
?.resolve({if (!widget.interactive) MaterialState.disabled}),
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/yaru_checkbox_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class YaruCheckboxListTile extends StatelessWidget {
this.visualDensity,
this.focusNode,
this.enableFeedback,
this.mouseCursor,
}) : assert(tristate || value != null),
assert(!isThreeLine || subtitle != null);

Expand Down Expand Up @@ -98,6 +99,9 @@ class YaruCheckboxListTile extends StatelessWidget {
/// See [CheckboxListTile.enableFeedback].
final bool? enableFeedback;

/// See [CheckboxListTile.mouseCursor].
final MouseCursor? mouseCursor;

void _handleValueChange() {
assert(onChanged != null);
switch (value) {
Expand All @@ -121,6 +125,7 @@ class YaruCheckboxListTile extends StatelessWidget {
onChanged: onChanged,
autofocus: autofocus,
tristate: tristate,
mouseCursor: mouseCursor,
);

switch (controlAffinity) {
Expand Down Expand Up @@ -154,6 +159,7 @@ class YaruCheckboxListTile extends StatelessWidget {
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
mouseCursor: mouseCursor,
),
);
}
Expand Down
15 changes: 14 additions & 1 deletion lib/src/widgets/yaru_checkbox_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ class YaruCheckboxThemeData extends ThemeExtension<YaruCheckboxThemeData>
this.borderColor,
this.checkmarkColor,
this.indicatorColor,
this.mouseCursor,
});

final MaterialStateProperty<Color?>? color;
final MaterialStateProperty<Color?>? borderColor;
final MaterialStateProperty<Color?>? checkmarkColor;
final MaterialStateProperty<Color?>? indicatorColor;
final MaterialStateProperty<MouseCursor?>? mouseCursor;

@override
YaruCheckboxThemeData copyWith({
MaterialStateProperty<Color?>? color,
MaterialStateProperty<Color?>? borderColor,
MaterialStateProperty<Color?>? checkmarkColor,
MaterialStateProperty<Color?>? indicatorColor,
MaterialStateProperty<MouseCursor?>? mouseCursor,
}) {
return YaruCheckboxThemeData(
color: color ?? this.color,
borderColor: borderColor ?? this.borderColor,
checkmarkColor: checkmarkColor ?? this.checkmarkColor,
indicatorColor: indicatorColor ?? this.indicatorColor,
mouseCursor: mouseCursor ?? this.mouseCursor,
);
}

Expand Down Expand Up @@ -62,6 +66,12 @@ class YaruCheckboxThemeData extends ThemeExtension<YaruCheckboxThemeData>
t,
Color.lerp,
),
mouseCursor: MaterialStateProperty.lerp<MouseCursor?>(
mouseCursor,
o?.mouseCursor,
t,
(a, b, t) => t < 0.5 ? a : b,
),
);
}

Expand All @@ -74,6 +84,7 @@ class YaruCheckboxThemeData extends ThemeExtension<YaruCheckboxThemeData>
);
properties.add(DiagnosticsProperty('checkmarkColor', checkmarkColor));
properties.add(DiagnosticsProperty('indicatorColor', indicatorColor));
properties.add(DiagnosticsProperty('mouseCursor', mouseCursor));
}

@override
Expand All @@ -83,7 +94,8 @@ class YaruCheckboxThemeData extends ThemeExtension<YaruCheckboxThemeData>
other.color == color &&
other.borderColor == borderColor &&
other.checkmarkColor == checkmarkColor &&
other.indicatorColor == indicatorColor;
other.indicatorColor == indicatorColor &&
other.mouseCursor == mouseCursor;
}

@override
Expand All @@ -93,6 +105,7 @@ class YaruCheckboxThemeData extends ThemeExtension<YaruCheckboxThemeData>
borderColor,
checkmarkColor,
indicatorColor,
mouseCursor,
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/widgets/yaru_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class YaruRadio<T> extends StatefulWidget implements YaruTogglable<T?> {
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
this.mouseCursor,
}) : assert(toggleable || value != null);

/// The value represented by this radio button.
Expand Down Expand Up @@ -135,6 +136,9 @@ class YaruRadio<T> extends StatefulWidget implements YaruTogglable<T?> {
@override
final bool autofocus;

@override
final MouseCursor? mouseCursor;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down Expand Up @@ -241,6 +245,9 @@ class _YaruRadioState<T> extends YaruTogglableState<YaruRadio<T?>> {
..disabledCheckmarkColor = disabledCheckmarkColor
..hoverIndicatorColor = hoverIndicatorColor
..focusIndicatorColor = focusIndicatorColor,
mouseCursor: widget.mouseCursor ??
radioTheme.mouseCursor
?.resolve({if (!widget.interactive) MaterialState.disabled}),
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/src/widgets/yaru_radio_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'yaru_radio.dart';
import 'yaru_toggle_button.dart';
import 'yaru_toggle_button_theme.dart';

/// A desktop style radio button with an interactive label.
class YaruRadioButton<T> extends StatelessWidget {
Expand All @@ -17,6 +18,7 @@ class YaruRadioButton<T> extends StatelessWidget {
this.toggleable = false,
this.autofocus = false,
this.focusNode,
this.mouseCursor,
});

/// See [Radio.value]
Expand Down Expand Up @@ -46,8 +48,16 @@ class YaruRadioButton<T> extends StatelessWidget {
/// See [Radio.autofocus].
final bool autofocus;

/// See [Radio.mouseCursor].
final MouseCursor? mouseCursor;

@override
Widget build(BuildContext context) {
final mouseCursor = this.mouseCursor ??
YaruToggleButtonTheme.of(context)
?.mouseCursor
?.resolve({if (onChanged == null) MaterialState.disabled});

return YaruToggleButton(
title: title,
subtitle: subtitle,
Expand All @@ -59,7 +69,12 @@ class YaruRadioButton<T> extends StatelessWidget {
toggleable: toggleable,
focusNode: focusNode,
autofocus: autofocus,
mouseCursor: mouseCursor,
),
mouseCursor: mouseCursor ??
(onChanged != null
? SystemMouseCursors.click
: SystemMouseCursors.basic),
onToggled: onChanged == null ? null : _onToggled,
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/yaru_radio_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class YaruRadioListTile<T> extends StatelessWidget {
this.visualDensity,
this.focusNode,
this.enableFeedback,
this.mouseCursor,
}) : assert(!isThreeLine || subtitle != null);

/// See [RadioListTile.value].
Expand Down Expand Up @@ -101,6 +102,9 @@ class YaruRadioListTile<T> extends StatelessWidget {
/// See [RadioListTile.enableFeedback].
final bool? enableFeedback;

/// See [RadioListTile.mouseCursor].
final MouseCursor? mouseCursor;

void _handleValueChange() {
assert(onChanged != null);
if (groupValue != value || !toggleable) {
Expand All @@ -119,6 +123,7 @@ class YaruRadioListTile<T> extends StatelessWidget {
onChanged: onChanged,
toggleable: toggleable,
autofocus: autofocus,
mouseCursor: mouseCursor,
);

switch (controlAffinity) {
Expand Down Expand Up @@ -152,6 +157,7 @@ class YaruRadioListTile<T> extends StatelessWidget {
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
mouseCursor: mouseCursor,
),
);
}
Expand Down
15 changes: 14 additions & 1 deletion lib/src/widgets/yaru_radio_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ class YaruRadioThemeData extends ThemeExtension<YaruRadioThemeData>
this.borderColor,
this.checkmarkColor,
this.indicatorColor,
this.mouseCursor,
});

final MaterialStateProperty<Color?>? color;
final MaterialStateProperty<Color?>? borderColor;
final MaterialStateProperty<Color?>? checkmarkColor;
final MaterialStateProperty<Color?>? indicatorColor;
final MaterialStateProperty<MouseCursor?>? mouseCursor;

@override
YaruRadioThemeData copyWith({
MaterialStateProperty<Color?>? color,
MaterialStateProperty<Color?>? borderColor,
MaterialStateProperty<Color?>? checkmarkColor,
MaterialStateProperty<Color?>? indicatorColor,
MaterialStateProperty<MouseCursor?>? mouseCursor,
}) {
return YaruRadioThemeData(
color: color ?? this.color,
borderColor: borderColor ?? this.borderColor,
checkmarkColor: checkmarkColor ?? this.checkmarkColor,
indicatorColor: indicatorColor ?? this.indicatorColor,
mouseCursor: mouseCursor ?? this.mouseCursor,
);
}

Expand Down Expand Up @@ -62,6 +66,12 @@ class YaruRadioThemeData extends ThemeExtension<YaruRadioThemeData>
t,
Color.lerp,
),
mouseCursor: MaterialStateProperty.lerp<MouseCursor?>(
mouseCursor,
o?.mouseCursor,
t,
(a, b, t) => t < 0.5 ? a : b,
),
);
}

Expand All @@ -74,6 +84,7 @@ class YaruRadioThemeData extends ThemeExtension<YaruRadioThemeData>
);
properties.add(DiagnosticsProperty('checkmarkColor', checkmarkColor));
properties.add(DiagnosticsProperty('indicatorColor', indicatorColor));
properties.add(DiagnosticsProperty('mouseCursor', mouseCursor));
}

@override
Expand All @@ -83,7 +94,8 @@ class YaruRadioThemeData extends ThemeExtension<YaruRadioThemeData>
other.color == color &&
other.borderColor == borderColor &&
other.checkmarkColor == checkmarkColor &&
other.indicatorColor == indicatorColor;
other.indicatorColor == indicatorColor &&
other.mouseCursor == mouseCursor;
}

@override
Expand All @@ -93,6 +105,7 @@ class YaruRadioThemeData extends ThemeExtension<YaruRadioThemeData>
borderColor,
checkmarkColor,
indicatorColor,
mouseCursor,
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/widgets/yaru_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class YaruSwitch extends StatefulWidget implements YaruTogglable<bool> {
this.thumbColor,
this.focusNode,
this.autofocus = false,
this.mouseCursor,
});

/// Whether this switch is on or off.
Expand Down Expand Up @@ -101,6 +102,9 @@ class YaruSwitch extends StatefulWidget implements YaruTogglable<bool> {
@override
final bool autofocus;

@override
final MouseCursor? mouseCursor;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down Expand Up @@ -219,6 +223,9 @@ class _YaruSwitchState extends YaruTogglableState<YaruSwitch> {
..disabledCheckedThumbColor = disabledCheckedThumbColor
..hoverIndicatorColor = hoverIndicatorColor
..focusIndicatorColor = focusIndicatorColor,
mouseCursor: widget.mouseCursor ??
switchTheme.mouseCursor
?.resolve({if (!widget.interactive) MaterialState.disabled}),
),
);
}
Expand Down
Loading