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

Theme update #94

Merged
merged 8 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.1.2]
* Updated the theme api
* Properties in `MacosThemeData` and in `Typography` can't be null
* Renamed `DynamicColorX` to `MacosDynamicColor`
* Added the method `lerp` on all theme datas.

## [0.1.1]
* Implemented `Label` ([#61](https://github.com/GroovinChip/macos_ui/issues/61))
* Capacity Indicator now works as expected ([#49](https://github.com/GroovinChip/macos_ui/issues/49))
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.1.1"
version: "0.1.2"
matcher:
dependency: transitive
description:
Expand Down
3 changes: 0 additions & 3 deletions lib/macos_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ library macos_ui;

export 'src/buttons/checkbox.dart';
export 'src/buttons/help_button.dart';
export 'src/buttons/help_button_theme.dart';
export 'src/buttons/push_button.dart';
export 'src/buttons/push_button_theme.dart';
export 'src/buttons/radio_button.dart';
export 'src/buttons/switch.dart';
export 'src/fields/text_field.dart';
Expand All @@ -32,6 +30,5 @@ export 'src/layout/title_bar.dart';
export 'src/macos_app.dart';
export 'src/styles/colors.dart';
export 'src/styles/macos_theme.dart';
export 'src/styles/macos_theme_data.dart';
export 'src/styles/typography.dart';
export 'src/util.dart';
11 changes: 5 additions & 6 deletions lib/src/buttons/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class Checkbox extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMacosTheme(context));
bool isLight = context.macosTheme.brightness != Brightness.dark;
final MacosThemeData theme = MacosTheme.of(context);
bool isLight = !theme.brightness.isDark;
return GestureDetector(
onTap: () {
if (value == null || value == false) {
Expand All @@ -101,12 +102,10 @@ class Checkbox extends StatelessWidget {
alignment: Alignment.center,
decoration: isDisabled || value == null || value == true
? BoxDecoration(
color: DynamicColorX.macosResolve(
color: MacosDynamicColor.resolve(
isDisabled
? disabledColor
: activeColor ??
context.macosTheme.primaryColor ??
CupertinoColors.activeBlue,
: activeColor ?? theme.primaryColor,
context,
),
borderRadius: BorderRadius.circular(4.0),
Expand All @@ -116,7 +115,7 @@ class Checkbox extends StatelessWidget {
border: Border.all(
style: isLight ? BorderStyle.solid : BorderStyle.none,
width: 0.5,
color: DynamicColorX.macosResolve(
color: MacosDynamicColor.resolve(
offBorderColor,
context,
),
Expand Down
108 changes: 101 additions & 7 deletions lib/src/buttons/help_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ class _HelpButtonState extends State<HelpButton>
Widget build(BuildContext context) {
final bool enabled = widget.enabled;
final MacosThemeData theme = MacosTheme.of(context);
final Color? backgroundColor = DynamicColorX.macosResolve(
final Color backgroundColor = MacosDynamicColor.resolve(
widget.color ?? theme.helpButtonTheme.color,
context,
);

final Color? disabledColor = DynamicColorX.macosResolve(
final Color disabledColor = MacosDynamicColor.resolve(
widget.disabledColor ?? theme.helpButtonTheme.disabledColor,
context,
);

final Color? foregroundColor = widget.enabled
? iconLuminance(backgroundColor!, theme.brightness!.isDark)
: theme.brightness!.isDark
? iconLuminance(backgroundColor, theme.brightness.isDark)
: theme.brightness.isDark
? Color.fromRGBO(255, 255, 255, 0.25)
: Color.fromRGBO(0, 0, 0, 0.25);

Expand All @@ -192,9 +192,7 @@ class _HelpButtonState extends State<HelpButton>
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: !enabled
? DynamicColorX.macosResolve(disabledColor!, context)
: backgroundColor,
color: !enabled ? disabledColor : backgroundColor,
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
Expand Down Expand Up @@ -230,3 +228,99 @@ class _HelpButtonState extends State<HelpButton>
);
}
}

/// Overrides the default style of its [HelpButton] descendants.
///
/// See also:
///
/// * [HelpButtonThemeData], which is used to configure this theme.
class HelpButtonTheme extends InheritedTheme {
/// Create a [HelpButtonTheme].
///
/// The [data] parameter must not be null.
const HelpButtonTheme({
Key? key,
required this.data,
required Widget child,
}) : super(key: key, child: child);

/// The configuration of this theme.
final HelpButtonThemeData data;

/// The closest instance of this class that encloses the given context.
///
/// If there is no enclosing [HelpButtonTheme] widget, then
/// [MacosThemeData.helpButtonTheme] is used.
///
/// Typical usage is as follows:
///
/// ```dart
/// HelpButtonTheme theme = HelpButtonTheme.of(context);
/// ```
static HelpButtonThemeData of(BuildContext context) {
final HelpButtonTheme? buttonTheme =
context.dependOnInheritedWidgetOfExactType<HelpButtonTheme>();
return buttonTheme?.data ?? MacosTheme.of(context).helpButtonTheme;
}

@override
Widget wrap(BuildContext context, Widget child) {
return HelpButtonTheme(data: data, child: child);
}

@override
bool updateShouldNotify(HelpButtonTheme oldWidget) => data != oldWidget.data;
}

/// A style that overrides the default appearance of
/// [HelpButton]s when it's used with [HelpButtonTheme] or with the
/// overall [MacosTheme]'s [MacosThemeData.helpButtonTheme].
///
/// See also:
///
/// * [HelpButtonTheme], the theme which is configured with this class.
/// * [MacosThemeData.helpButtonTheme], which can be used to override the default
/// style for [HelpButton]s below the overall [MacosTheme].
class HelpButtonThemeData with Diagnosticable {
/// Creates a [HelpButtonThemeData].
///
/// The [style] may be null.
const HelpButtonThemeData({
required this.color,
required this.disabledColor,
});

/// The default background color for [HelpButton]
final Color color;

/// The default disabled color for [HelpButton]
final Color disabledColor;

HelpButtonThemeData copyWith(HelpButtonThemeData? themeData) {
if (themeData == null) {
return this;
}
return HelpButtonThemeData(
color: themeData.color,
disabledColor: themeData.disabledColor,
);
}

/// Linearly interpolate between two tooltip themes.
///
/// All the properties must be non-null.
static HelpButtonThemeData lerp(
HelpButtonThemeData a, HelpButtonThemeData b, double t) {
return HelpButtonThemeData(
color: Color.lerp(a.color, b.color, t)!,
disabledColor: Color.lerp(a.color, b.color, t)!,
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(ColorProperty('color', color));
properties.add(ColorProperty('disabledColor', disabledColor));
}
}
88 changes: 0 additions & 88 deletions lib/src/buttons/help_button_theme.dart

This file was deleted.

Loading