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

Implement mouse cursors #67

Merged
merged 4 commits into from
May 10, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.0.12]
* Add mouse cursors to help button, push button and `TextField`

## [0.0.11]
* Implement `TextField`

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.11"
version: "0.0.12"
matcher:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions lib/src/buttons/checkbox.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_ui/macos_ui.dart';

Expand Down
96 changes: 50 additions & 46 deletions lib/src/buttons/help_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_ui/macos_ui.dart';

Expand Down Expand Up @@ -170,52 +171,55 @@ class _HelpButtonState extends State<HelpButton>
? Color.fromRGBO(255, 255, 255, 0.25)
: Color.fromRGBO(0, 0, 0, 0.25);

return GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: enabled ? _handleTapDown : null,
onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed,
child: Semantics(
label: widget.semanticLabel,
button: true,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 20,
minHeight: 20,
),
child: FadeTransition(
opacity: _opacityAnimation,
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: !enabled
? DynamicColorX.macosResolve(disabledColor!, context)
: backgroundColor,
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(-0.1, -0.1),
),
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(0.1, 0.1),
),
BoxShadow(
color: CupertinoColors.tertiarySystemFill,
offset: Offset(0, 0),
),
],
),
child: Padding(
padding: EdgeInsets.all(8),
child: Align(
alignment: widget.alignment,
widthFactor: 1.0,
heightFactor: 1.0,
child: Icon(
CupertinoIcons.question,
color: foregroundColor,
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: enabled ? _handleTapDown : null,
onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed,
child: Semantics(
label: widget.semanticLabel,
button: true,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 20,
minHeight: 20,
),
child: FadeTransition(
opacity: _opacityAnimation,
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: !enabled
? DynamicColorX.macosResolve(disabledColor!, context)
: backgroundColor,
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(-0.1, -0.1),
),
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(0.1, 0.1),
),
BoxShadow(
color: CupertinoColors.tertiarySystemFill,
offset: Offset(0, 0),
),
],
),
child: Padding(
padding: EdgeInsets.all(8),
child: Align(
alignment: widget.alignment,
widthFactor: 1.0,
heightFactor: 1.0,
child: Icon(
CupertinoIcons.question,
color: foregroundColor,
),
),
),
),
Expand Down
70 changes: 37 additions & 33 deletions lib/src/buttons/push_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_ui/macos_ui.dart';

Expand Down Expand Up @@ -232,39 +233,42 @@ class _PushButtonState extends State<PushButton>
final TextStyle textStyle =
theme.typography!.headline!.copyWith(color: foregroundColor);

return GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: enabled ? _handleTapDown : null,
onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed,
child: Semantics(
button: true,
label: widget.semanticLabel,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 49,
minHeight: 20,
),
child: FadeTransition(
opacity: _opacityAnimation,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: borderRadius,
color: !enabled
? DynamicColorX.macosResolve(disabledColor, context)
: backgroundColor,
),
child: Padding(
padding: buttonPadding!,
child: Align(
alignment: widget.alignment,
widthFactor: 1.0,
heightFactor: 1.0,
// TODO(groovin): show proper text color in light theme
child: DefaultTextStyle(
style: textStyle,
child: widget.child,
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: enabled ? _handleTapDown : null,
onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed,
child: Semantics(
button: true,
label: widget.semanticLabel,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 49,
minHeight: 20,
),
child: FadeTransition(
opacity: _opacityAnimation,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: borderRadius,
color: !enabled
? DynamicColorX.macosResolve(disabledColor, context)
: backgroundColor,
),
child: Padding(
padding: buttonPadding!,
child: Align(
alignment: widget.alignment,
widthFactor: 1.0,
heightFactor: 1.0,
// TODO(groovin): show proper text color in light theme
child: DefaultTextStyle(
style: textStyle,
child: widget.child,
),
),
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/src/buttons/radio_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_ui/macos_ui.dart';

Expand Down
50 changes: 29 additions & 21 deletions lib/src/fields/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1121,26 +1121,29 @@ class _TextFieldState extends State<TextField>
widget.suffix!
// Otherwise, try to show a clear button if its visibility mode matches.
else if (_showClearButton(text))
GestureDetector(
key: _clearGlobalKey,
onTap: widget.enabled ?? true
? () {
// Special handle onChanged for ClearButton
// Also call onChanged when the clear button is tapped.
final bool textChanged =
_effectiveController.text.isNotEmpty;
_effectiveController.clear();
if (widget.onChanged != null && textChanged)
widget.onChanged!(_effectiveController.text);
}
: null,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: Icon(
CupertinoIcons.clear_thick_circled,
size: 18.0,
color:
DynamicColorX.macosResolve(_kClearButtonColor, context),
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
key: _clearGlobalKey,
onTap: widget.enabled ?? true
? () {
// Special handle onChanged for ClearButton
// Also call onChanged when the clear button is tapped.
final bool textChanged =
_effectiveController.text.isNotEmpty;
_effectiveController.clear();
if (widget.onChanged != null && textChanged)
widget.onChanged!(_effectiveController.text);
}
: null,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: Icon(
CupertinoIcons.clear_thick_circled,
size: 18.0,
color:
DynamicColorX.macosResolve(_kClearButtonColor, context),
),
),
),
),
Expand Down Expand Up @@ -1346,7 +1349,7 @@ class _TextFieldState extends State<TextField>
),
);

final Widget child = Semantics(
Widget child = Semantics(
enabled: enabled,
onTap: !enabled || widget.readOnly
? null
Expand Down Expand Up @@ -1386,6 +1389,11 @@ class _TextFieldState extends State<TextField>
),
);

child = MouseRegion(
cursor: SystemMouseCursors.text,
child: child,
);

if (kIsWeb) {
return Shortcuts(
shortcuts: scrollShortcutOverrides,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macos_ui
description: Flutter widgets and themes implementing the current macOS design language.
version: 0.0.11
version: 0.0.12
homepage: 'https://github.com/GroovinChip/macos_ui'

environment:
Expand Down