Skip to content

Commit

Permalink
Improve togglable widget style (#402)
Browse files Browse the repository at this point in the history
* Improve togglable widget style

Fixes #377

* Update goldens

* Adjustements

* Fix analysing

* Update goldens
  • Loading branch information
Jupi007 committed Nov 20, 2022
1 parent fe42d70 commit 7f59250
Show file tree
Hide file tree
Showing 130 changed files with 71 additions and 15 deletions.
21 changes: 19 additions & 2 deletions lib/src/controls/yaru_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,26 @@ class _YaruCheckboxPainter extends YaruTogglablePainter {
Paint()
..color = interactive
? Color.lerp(uncheckedColor, checkedColor, t)!
: Color.lerp(uncheckedDisabledColor, checkedDisabledColor, t)!
: Color.lerp(disabledUncheckedColor, disabledCheckedColor, t)!
..style = PaintingStyle.fill,
);

canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(
origin.dx + 0.5,
origin.dy + 0.5,
size.width - 1.0,
size.height - 1.0,
),
_kCheckboxBorderRadius,
),
Paint()
..color = interactive
? Color.lerp(uncheckedBorderColor, checkedColor, t)!
: Color.lerp(disabledUncheckedBorderColor, Colors.transparent, t)!
..style = PaintingStyle.stroke,
);
}

void _drawCheckMark(Canvas canvas, Size size, Offset origin, double t) {
Expand Down Expand Up @@ -252,7 +269,7 @@ class _YaruCheckboxPainter extends YaruTogglablePainter {

Paint _getCheckmarkPaint() {
return Paint()
..color = interactive ? checkmarkColor : checkmarkDisabledColor
..color = interactive ? checkmarkColor : disabledCheckmarkColor
..style = PaintingStyle.stroke
..strokeWidth = _kCheckboxDashStroke;
}
Expand Down
18 changes: 16 additions & 2 deletions lib/src/controls/yaru_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,23 @@ class _YaruRadioPainter extends YaruTogglablePainter {
Paint()
..color = interactive
? Color.lerp(uncheckedColor, checkedColor, t)!
: Color.lerp(uncheckedDisabledColor, checkedDisabledColor, t)!
: Color.lerp(disabledUncheckedColor, disabledCheckedColor, t)!
..style = PaintingStyle.fill,
);

canvas.drawOval(
Rect.fromLTWH(
origin.dx + 0.5,
origin.dy + 0.5,
size.width - 1.0,
size.height - 1.0,
),
Paint()
..color = interactive
? Color.lerp(uncheckedBorderColor, checkedColor, t)!
: Color.lerp(disabledUncheckedBorderColor, Colors.transparent, t)!
..style = PaintingStyle.stroke,
);
}

void _drawDot(Canvas canvas, Size size, Offset origin, double t) {
Expand All @@ -191,7 +205,7 @@ class _YaruRadioPainter extends YaruTogglablePainter {
height: dotSize.height * t,
),
Paint()
..color = interactive ? checkmarkColor : checkmarkDisabledColor
..color = interactive ? checkmarkColor : disabledCheckmarkColor
..style = PaintingStyle.fill,
);
}
Expand Down
25 changes: 21 additions & 4 deletions lib/src/controls/yaru_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,26 @@ class _YaruSwitchState extends YaruTogglableState<YaruSwitch> {

@override
Widget build(BuildContext context) {
return buildToggleable(_YaruSwitchPainter());
final colorScheme = Theme.of(context).colorScheme;

final uncheckedSwitchColor = colorScheme.onSurface.withOpacity(.25);
const uncheckedDotColor = Colors.white;
final disabledDotColor = colorScheme.onSurface.withOpacity(.4);

return buildToggleable(
_YaruSwitchPainter()
..uncheckedSwitchColor = uncheckedSwitchColor
..uncheckedDotColor = uncheckedDotColor
..disabledDotColor = disabledDotColor,
);
}
}

class _YaruSwitchPainter extends YaruTogglablePainter {
late Color uncheckedSwitchColor;
late Color uncheckedDotColor;
late Color disabledDotColor;

@override
void paintTogglable(
Canvas canvas,
Expand All @@ -136,8 +151,8 @@ class _YaruSwitchPainter extends YaruTogglablePainter {
),
Paint()
..color = interactive
? Color.lerp(uncheckedColor, checkedColor, t)!
: Color.lerp(uncheckedDisabledColor, checkedDisabledColor, t)!
? Color.lerp(uncheckedSwitchColor, checkedColor, t)!
: Color.lerp(disabledUncheckedColor, disabledCheckedColor, t)!
..style = PaintingStyle.fill,
);
}
Expand All @@ -155,7 +170,9 @@ class _YaruSwitchPainter extends YaruTogglablePainter {
final center = Offset.lerp(start, end, t)! + origin;

final paint = Paint()
..color = interactive ? checkmarkColor : checkmarkDisabledColor
..color = interactive
? Color.lerp(uncheckedDotColor, checkmarkColor, t)!
: disabledDotColor
..style = PaintingStyle.fill;

drawStateIndicator(canvas, size, center);
Expand Down
22 changes: 15 additions & 7 deletions lib/src/controls/yaru_togglable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ abstract class YaruTogglableState<S extends YaruTogglable> extends State<S>
final colorScheme = Theme.of(context).colorScheme;

// Normal colors
final uncheckedColor = colorScheme.onSurface.withOpacity(.3);
const uncheckedColor = Colors.transparent;
final uncheckedBorderColor = colorScheme.onSurface.withOpacity(.25);
final checkedColor = colorScheme.primary;
final checkmarkColor = colorScheme.onPrimary;

// Disabled colors
final uncheckedDisabledColor = colorScheme.onSurface.withOpacity(.1);
final uncheckedDisabledBorderColor = colorScheme.onSurface.withOpacity(.1);
final checkedDisabledColor = colorScheme.onSurface.withOpacity(.2);
final checkmarkDisabledColor = colorScheme.onSurface.withOpacity(.5);

Expand Down Expand Up @@ -266,11 +268,13 @@ abstract class YaruTogglableState<S extends YaruTogglable> extends State<S>
..sizePosition = _sizePosition
..indicatorPosition = _indicatorPosition
..uncheckedColor = uncheckedColor
..uncheckedBorderColor = uncheckedBorderColor
..checkedColor = checkedColor
..checkmarkColor = checkmarkColor
..uncheckedDisabledColor = uncheckedDisabledColor
..checkedDisabledColor = checkedDisabledColor
..checkmarkDisabledColor = checkmarkDisabledColor
..disabledUncheckedColor = uncheckedDisabledColor
..disabledUncheckedBorderColor = uncheckedDisabledBorderColor
..disabledCheckedColor = checkedDisabledColor
..disabledCheckmarkColor = checkmarkDisabledColor
..hoverIndicatorColor = hoverIndicatorColor
..focusIndicatorColor = focusIndicatorColor,
),
Expand All @@ -291,11 +295,15 @@ abstract class YaruTogglablePainter extends ChangeNotifier
late bool? oldChecked;

late Color uncheckedColor;
late Color uncheckedBorderColor;
late Color checkedColor;
late Color checkmarkColor;
late Color uncheckedDisabledColor;
late Color checkedDisabledColor;
late Color checkmarkDisabledColor;

late Color disabledUncheckedColor;
late Color disabledUncheckedBorderColor;
late Color disabledCheckedColor;
late Color disabledCheckmarkColor;

late Color hoverIndicatorColor;
late Color focusIndicatorColor;

Expand Down
Binary file modified test/controls/goldens/yaru_check_button-checked-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-focused-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-hovered-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-hovered-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-pressed-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-checked-pressed-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-tristate-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-tristate-hovered-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-tristate-hovered-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-tristate-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-tristate-pressed-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-unchecked-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-unchecked-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-unckecked-focused-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-unckecked-hovered-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_check_button-unckecked-pressed-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/controls/goldens/yaru_checkbox-checked-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-focused-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-focused-light.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-hovered-light.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-light.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-checked-pressed-light.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-focused-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-focused-light.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-hovered-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-hovered-light.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-light.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-pressed-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-tristate-pressed-light.png
Binary file modified test/controls/goldens/yaru_checkbox-unchecked-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-unchecked-light.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-disabled-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-disabled-light.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-focused-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-focused-light.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-hovered-light.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_checkbox-unckecked-pressed-light.png
Binary file modified test/controls/goldens/yaru_popup_menu_item-checked-dark.png
Binary file modified test/controls/goldens/yaru_popup_menu_item-checked-light.png
Binary file modified test/controls/goldens/yaru_popup_menu_item-unchecked-dark.png
Binary file modified test/controls/goldens/yaru_popup_menu_item-unchecked-light.png
Binary file modified test/controls/goldens/yaru_radio-checked-dark.png
Binary file modified test/controls/goldens/yaru_radio-checked-focused-dark.png
Binary file modified test/controls/goldens/yaru_radio-checked-focused-light.png
Binary file modified test/controls/goldens/yaru_radio-checked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_radio-checked-hovered-light.png
Binary file modified test/controls/goldens/yaru_radio-checked-light.png
Binary file modified test/controls/goldens/yaru_radio-checked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_radio-checked-pressed-light.png
Binary file modified test/controls/goldens/yaru_radio-unchecked-dark.png
Binary file modified test/controls/goldens/yaru_radio-unchecked-light.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-disabled-dark.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-disabled-light.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-focused-dark.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-focused-light.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-hovered-light.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_radio-unckecked-pressed-light.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-focused-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-focused-light.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-hovered-light.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-light.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-checked-pressed-light.png
Binary file modified test/controls/goldens/yaru_radio_button-unchecked-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-unchecked-light.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-disabled-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-focused-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-focused-light.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-hovered-light.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_radio_button-unckecked-pressed-light.png
Binary file modified test/controls/goldens/yaru_switch-checked-disabled-dark.png
Binary file modified test/controls/goldens/yaru_switch-checked-disabled-light.png
Binary file modified test/controls/goldens/yaru_switch-unchecked-dark.png
Binary file modified test/controls/goldens/yaru_switch-unchecked-light.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-disabled-dark.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-disabled-light.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-focused-dark.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-focused-light.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-hovered-dark.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-hovered-light.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-pressed-dark.png
Binary file modified test/controls/goldens/yaru_switch-unckecked-pressed-light.png
Binary file modified test/controls/goldens/yaru_switch_button-off-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-off-disabled-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-off-disabled-light.png
Binary file modified test/controls/goldens/yaru_switch_button-off-focused-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-off-focused-light.png
Binary file modified test/controls/goldens/yaru_switch_button-off-hovered-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-off-hovered-light.png
Binary file modified test/controls/goldens/yaru_switch_button-off-light.png
Binary file modified test/controls/goldens/yaru_switch_button-off-pressed-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-off-pressed-light.png
Binary file modified test/controls/goldens/yaru_switch_button-on-disabled-dark.png
Binary file modified test/controls/goldens/yaru_switch_button-on-disabled-light.png

0 comments on commit 7f59250

Please sign in to comment.