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

Fix incorrect sidebar and sidebar item color #484

Merged
merged 98 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
aae8eb9
automatic changes
Adrian-Samoticha Aug 4, 2023
968cd31
imitate macOS’ push button look
Adrian-Samoticha Aug 6, 2023
b93084c
make push button appear secondary when window resigns main state
Adrian-Samoticha Aug 6, 2023
b4d22f1
migrate to stream builder
Adrian-Samoticha Aug 6, 2023
afc3a9c
fix incorrect text color in push button when window resigns main state
Adrian-Samoticha Aug 6, 2023
ab3092e
add missing comma
Adrian-Samoticha Aug 7, 2023
cb70113
implement `AccentColorListener`
Adrian-Samoticha Aug 7, 2023
6e77ab9
make push button listen to accent color changes
Adrian-Samoticha Aug 7, 2023
ba42d75
add missing comma
Adrian-Samoticha Aug 7, 2023
a549bca
deprecate `PushButtonTheme`
Adrian-Samoticha Aug 7, 2023
ba3d7ce
mimic macOS’ push button click effect
Adrian-Samoticha Aug 7, 2023
07490f0
do not init `WindowMainStateListener` if platform isn’t macOS
Adrian-Samoticha Aug 7, 2023
aa8f90d
do not init `AccentColorListener` if platform isn’t macOS
Adrian-Samoticha Aug 7, 2023
9b95a43
remove unused imports
Adrian-Samoticha Aug 7, 2023
0f52aaa
remove reference to deprecated API in documentation
Adrian-Samoticha Aug 7, 2023
85fe22f
deprecate `pressedOpacity`
Adrian-Samoticha Aug 7, 2023
856bfb0
remove deprecated `pressedOpacity` from `debugFillProperties`
Adrian-Samoticha Aug 7, 2023
3ca7e81
document `AccentColor`
Adrian-Samoticha Aug 7, 2023
3c96252
document `AccentColor` values
Adrian-Samoticha Aug 7, 2023
3d06510
increment version number
Adrian-Samoticha Aug 7, 2023
80bcf9a
add changelog entry for version 2.0.1
Adrian-Samoticha Aug 7, 2023
db6088b
upgrade to macos_window_utils 1.2.0
Adrian-Samoticha Aug 11, 2023
2423822
initialize `_isWindowMain` properly
Adrian-Samoticha Aug 11, 2023
1ef31a8
rename `isWindowMain` to `isMainWindow`
Adrian-Samoticha Aug 11, 2023
f064102
replace `print` with `debugPrint`
Adrian-Samoticha Aug 11, 2023
9040eb9
deprecate properties of `PushButtonThemeData` rather than `PushButton…
Adrian-Samoticha Aug 11, 2023
0df03af
fix typo in `AccentColor` documentation
Adrian-Samoticha Aug 11, 2023
bc32402
fix typo in `AccentColorListener` docs
Adrian-Samoticha Aug 11, 2023
ea6a7e5
automatic changes
Adrian-Samoticha Aug 4, 2023
f01d422
imitate macOS’ push button look
Adrian-Samoticha Aug 6, 2023
d0255e1
make push button appear secondary when window resigns main state
Adrian-Samoticha Aug 6, 2023
5e90519
migrate to stream builder
Adrian-Samoticha Aug 6, 2023
08727e0
fix incorrect text color in push button when window resigns main state
Adrian-Samoticha Aug 6, 2023
0c75ce2
add missing comma
Adrian-Samoticha Aug 7, 2023
7e9e602
implement `AccentColorListener`
Adrian-Samoticha Aug 7, 2023
6a31e1c
make push button listen to accent color changes
Adrian-Samoticha Aug 7, 2023
3eaab39
add missing comma
Adrian-Samoticha Aug 7, 2023
5d230a5
deprecate `PushButtonTheme`
Adrian-Samoticha Aug 7, 2023
c99b3f0
mimic macOS’ push button click effect
Adrian-Samoticha Aug 7, 2023
8196267
do not init `WindowMainStateListener` if platform isn’t macOS
Adrian-Samoticha Aug 7, 2023
555bae6
do not init `AccentColorListener` if platform isn’t macOS
Adrian-Samoticha Aug 7, 2023
b8b22d7
remove unused imports
Adrian-Samoticha Aug 7, 2023
04f2a11
remove reference to deprecated API in documentation
Adrian-Samoticha Aug 7, 2023
7e0f365
deprecate `pressedOpacity`
Adrian-Samoticha Aug 7, 2023
f27803d
remove deprecated `pressedOpacity` from `debugFillProperties`
Adrian-Samoticha Aug 7, 2023
cfacc99
document `AccentColor`
Adrian-Samoticha Aug 7, 2023
5cf616f
document `AccentColor` values
Adrian-Samoticha Aug 7, 2023
23ab438
increment version number
Adrian-Samoticha Aug 7, 2023
4aa2296
add changelog entry for version 2.0.1
Adrian-Samoticha Aug 7, 2023
c39ba50
upgrade to macos_window_utils 1.2.0
Adrian-Samoticha Aug 11, 2023
6a5dbe6
initialize `_isWindowMain` properly
Adrian-Samoticha Aug 11, 2023
6aa9d8a
rename `isWindowMain` to `isMainWindow`
Adrian-Samoticha Aug 11, 2023
db655a7
replace `print` with `debugPrint`
Adrian-Samoticha Aug 11, 2023
2058812
deprecate properties of `PushButtonThemeData` rather than `PushButton…
Adrian-Samoticha Aug 11, 2023
c017df4
fix typo in `AccentColor` documentation
Adrian-Samoticha Aug 11, 2023
5757632
fix typo in `AccentColorListener` docs
Adrian-Samoticha Aug 11, 2023
f767d4d
Merge branch 'macosui-dev' into dev
Adrian-Samoticha Aug 11, 2023
c97b901
remove push button theme test
Adrian-Samoticha Aug 11, 2023
ce55875
Update CHANGELOG.md
Adrian-Samoticha Aug 12, 2023
3c1d16f
change documentation of `WindowMainStateListener`
Adrian-Samoticha Aug 12, 2023
ad79ce5
update documentation
Adrian-Samoticha Aug 12, 2023
a90c980
update documentation
Adrian-Samoticha Aug 12, 2023
d229e15
update documentation
Adrian-Samoticha Aug 12, 2023
7d2ec54
change `var` to `final`
Adrian-Samoticha Aug 12, 2023
a3183b5
update deprecation message
Adrian-Samoticha Aug 12, 2023
92658d9
improve formatting
Adrian-Samoticha Aug 12, 2023
7b81123
improve formatting
Adrian-Samoticha Aug 12, 2023
fb22efa
fix grammatical error in debug print message
Adrian-Samoticha Aug 12, 2023
040b4a0
improve formatting
Adrian-Samoticha Aug 13, 2023
3a8aecb
rename `deinit` methods to `dispose`
Adrian-Samoticha Aug 15, 2023
48c2c26
move `utils.dart` into `utils` directory
Adrian-Samoticha Aug 15, 2023
ce94aa9
move `WindowMainStateListener` to separate file
Adrian-Samoticha Aug 15, 2023
ef8c156
move `AccentColorListener` to separate file
Adrian-Samoticha Aug 15, 2023
7fa0f23
move `MacOSBrightnessOverrideHandler` to separate file
Adrian-Samoticha Aug 15, 2023
3e50ae4
add example to `AccentColorListener`
Adrian-Samoticha Aug 15, 2023
47e6974
rename `isWindowMain` to `isMainWindow`
Adrian-Samoticha Aug 15, 2023
7b9b1b6
add example to `WindowMainStateListener`
Adrian-Samoticha Aug 15, 2023
a4b6c45
replace `child: ...` with `child: …` to avoid confusing the dots with…
Adrian-Samoticha Aug 19, 2023
4bd7d33
Update lib/src/utils/accent_color_listener.dart
Adrian-Samoticha Aug 19, 2023
21ebe83
Update lib/src/utils/accent_color_listener.dart
Adrian-Samoticha Aug 19, 2023
053befb
Update lib/src/utils/accent_color_listener.dart
Adrian-Samoticha Aug 19, 2023
9394422
rename `onChangedStream` to `onChanged`
Adrian-Samoticha Aug 19, 2023
76caa07
move `AccentColorListener` constructor to top of class
Adrian-Samoticha Aug 19, 2023
e8190d6
move `WindowMainStateListener` to top of class
Adrian-Samoticha Aug 19, 2023
673c720
add “Updated” heading to changelog entry for version 2.0.1
Adrian-Samoticha Aug 19, 2023
e78cd55
migrate to `ExcludeSemantics` in popup button
Adrian-Samoticha Aug 19, 2023
a74b207
Merge branch 'macosui:dev' into dev
Adrian-Samoticha Sep 30, 2023
523cb67
update `LastUpgradeVersion` and `LastUpgradeCheck` in example
Adrian-Samoticha Sep 30, 2023
4d4519c
fix typo
Adrian-Samoticha Sep 30, 2023
02d504e
format `window.dart`
Adrian-Samoticha Sep 30, 2023
6557d05
improve formatting for `window.dart`
Adrian-Samoticha Sep 30, 2023
97751dc
fix sidebar appearing too dark
Adrian-Samoticha Oct 3, 2023
873807a
make sidebar items adapt their color based on the user’s selected sys…
Adrian-Samoticha Oct 7, 2023
2b1dba1
update changelog entry for version 2.0.1
Adrian-Samoticha Oct 7, 2023
5e49ad6
automatic changes
Adrian-Samoticha Oct 30, 2023
a2b0656
Merge branch 'dev' of https://github.com/macosui/macos_ui into macosu…
Adrian-Samoticha Oct 30, 2023
73a56fb
Merge branch 'macosui-dev' into dev
Adrian-Samoticha Oct 30, 2023
1f563c0
bump version to 2.0.3
Adrian-Samoticha Oct 30, 2023
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
## [2.0.3]
### 🛠️ Fixed 🛠️
* Fixed a bug that caused the sidebar to appear darker than intended.

### 🔄 Updated 🔄
* `SidebarItems` has now respects the user’s selected accent color and mimics the look of macOS’ sidebar items more closely.

## [2.0.2]
### 🛠️ Fixed 🛠️
* Fixed images in generated documentation.

## [2.0.1]
### 🔄 Updated 🔄
* `PushButton` has received a facelift. It now mimics the look and feel of native macOS buttons more closely.
* **Note:** As a result, its `pressedOpacity` property and the `PushButtonTheme` class have been deprecated.
* **Note:** As a result, its `pressedOpacity` property and the `PushButtonTheme` class have been deprecated.

## [2.0.0]
### 🚨 Breaking Changes 🚨
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layout/sidebar/sidebar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SidebarItem with Diagnosticable {
final Color? unselectedColor;

/// The [shape] property specifies the outline (border) of the
/// decoration. The shape must not be null. It's used alonside
/// decoration. The shape must not be null. It's used alongside
/// [selectedColor].
final ShapeBorder? shape;

Expand Down
163 changes: 131 additions & 32 deletions lib/src/layout/sidebar/sidebar_items.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_ui/src/enums/accent_color.dart';
import 'package:macos_ui/src/library.dart';

const Duration _kExpand = Duration(milliseconds: 200);
Expand Down Expand Up @@ -79,7 +80,8 @@ class SidebarItems extends StatelessWidget {

/// The color to paint the item when it's selected.
///
/// If null, [MacosThemeData.primaryColor] is used.
/// If null, the color is chosen automatically based on the user’s selected
/// system accent color and whether the sidebar is in the main window.
final Color? selectedColor;

/// The color to paint the item when it's unselected.
Expand All @@ -97,6 +99,21 @@ class SidebarItems extends StatelessWidget {
/// Defaults to [SystemMouseCursors.basic].
final MouseCursor? cursor;

/// The user’s selected system accent color.
AccentColor get _accentColor =>
AccentColorListener.instance.currentAccentColor ?? AccentColor.blue;

/// Returns the sidebar item’s selected color.
Color _getColor(BuildContext context) {
final isMainWindow = WindowMainStateListener.instance.isMainWindow;

return _ColorProvider.getSelectedColor(
accentColor: _accentColor,
isDarkModeEnabled: MacosTheme.of(context).brightness.isDark,
isWindowMain: isMainWindow,
);
}

List<SidebarItem> get _allItems {
List<SidebarItem> result = [];
for (var element in items) {
Expand All @@ -117,39 +134,50 @@ class SidebarItems extends StatelessWidget {
final theme = MacosTheme.of(context);
return MacosIconTheme.merge(
data: const MacosIconThemeData(size: 20),
child: _SidebarItemsConfiguration(
selectedColor: selectedColor ?? theme.primaryColor,
unselectedColor: unselectedColor ?? MacosColors.transparent,
shape: shape ?? _defaultShape,
itemSize: itemSize,
child: ListView(
controller: scrollController,
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.all(10.0 - theme.visualDensity.horizontal),
children: List.generate(items.length, (index) {
final item = items[index];
if (item.disclosureItems != null) {
return MouseRegion(
cursor: cursor!,
child: _DisclosureSidebarItem(
item: item,
selectedItem: _allItems[currentIndex],
onChanged: (item) {
onChanged(_allItems.indexOf(item));
},
child: StreamBuilder(
stream: AccentColorListener.instance.onChanged,
builder: (context, _) {
return StreamBuilder<bool>(
stream: WindowMainStateListener.instance.onChanged,
builder: (context, _) {
return _SidebarItemsConfiguration(
selectedColor: selectedColor ?? _getColor(context),
unselectedColor: unselectedColor ?? MacosColors.transparent,
shape: shape ?? _defaultShape,
itemSize: itemSize,
child: ListView(
controller: scrollController,
physics: const ClampingScrollPhysics(),
padding:
EdgeInsets.all(10.0 - theme.visualDensity.horizontal),
children: List.generate(items.length, (index) {
final item = items[index];
if (item.disclosureItems != null) {
return MouseRegion(
cursor: cursor!,
child: _DisclosureSidebarItem(
item: item,
selectedItem: _allItems[currentIndex],
onChanged: (item) {
onChanged(_allItems.indexOf(item));
},
),
);
}
return MouseRegion(
cursor: cursor!,
child: _SidebarItem(
item: item,
selected: _allItems[currentIndex] == item,
onClick: () => onChanged(_allItems.indexOf(item)),
),
);
}),
),
);
}
return MouseRegion(
cursor: cursor!,
child: _SidebarItem(
item: item,
selected: _allItems[currentIndex] == item,
onClick: () => onChanged(_allItems.indexOf(item)),
),
);
}),
),
},
);
},
),
);
}
Expand Down Expand Up @@ -497,3 +525,74 @@ class __DisclosureSidebarItemState extends State<_DisclosureSidebarItem>
);
}
}

class _ColorProvider {
/// Returns the selected color based on the provided parameters.
static Color getSelectedColor({
required AccentColor accentColor,
required bool isDarkModeEnabled,
required bool isWindowMain,
}) {
if (isDarkModeEnabled) {
if (!isWindowMain) {
return const MacosColor.fromRGBO(76, 78, 65, 1.0);
}

switch (accentColor) {
case AccentColor.blue:
return const MacosColor.fromRGBO(22, 105, 229, 0.749);

case AccentColor.purple:
return const MacosColor.fromRGBO(204, 45, 202, 0.749);

case AccentColor.pink:
return const MacosColor.fromRGBO(229, 74, 145, 0.749);

case AccentColor.red:
return const MacosColor.fromRGBO(238, 64, 68, 0.749);

case AccentColor.orange:
return const MacosColor.fromRGBO(244, 114, 0, 0.749);

case AccentColor.yellow:
return const MacosColor.fromRGBO(233, 176, 0, 0.749);

case AccentColor.green:
return const MacosColor.fromRGBO(76, 177, 45, 0.749);

case AccentColor.graphite:
return const MacosColor.fromRGBO(129, 129, 122, 0.824);
}
}

if (!isWindowMain) {
return const MacosColor.fromRGBO(213, 213, 208, 1.0);
}

switch (accentColor) {
case AccentColor.blue:
return const MacosColor.fromRGBO(9, 129, 255, 0.749);

case AccentColor.purple:
return const MacosColor.fromRGBO(162, 28, 165, 0.749);

case AccentColor.pink:
return const MacosColor.fromRGBO(234, 81, 152, 0.749);

case AccentColor.red:
return const MacosColor.fromRGBO(220, 32, 40, 0.749);

case AccentColor.orange:
return const MacosColor.fromRGBO(245, 113, 0, 0.749);

case AccentColor.yellow:
return const MacosColor.fromRGBO(240, 180, 2, 0.749);

case AccentColor.green:
return const MacosColor.fromRGBO(66, 174, 33, 0.749);

case AccentColor.graphite:
return const MacosColor.fromRGBO(174, 174, 167, 0.847);
}
}
}
Loading
Loading