Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
vumanhsn97 committed Mar 5, 2024
2 parents b17546a + e9da375 commit 6c69d9d
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ metrics

coverage_report
coverage
example/macos/Flutter/GeneratedPluginRegistrant.swift
173 changes: 94 additions & 79 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: ff0a9a3ce75ee73f200ca7e2f47745698c917ef9

COCOAPODS: 1.12.1
COCOAPODS: 1.13.0
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/buttons/radio_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MacosRadioButton<T> extends StatelessWidget {
final MacosThemeData theme = MacosTheme.of(context);
final isLight = !theme.brightness.isDark;
return GestureDetector(
onTap: () => onChanged!(value),
onTap: isDisabled ? null : () => onChanged!(value),
child: Semantics(
checked: selected,
label: semanticLabel,
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
181 changes: 139 additions & 42 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 @@ -279,18 +307,16 @@ class _SidebarItem extends StatelessWidget {
),
child: Row(
children: [
if (hasLeading)
Padding(
padding: EdgeInsets.only(right: spacing),
child: MacosIconTheme.merge(
data: MacosIconThemeData(
color:
selected ? MacosColors.white : theme.primaryColor,
size: itemSize.iconSize,
),
child: item.leading!,
if (hasLeading) ...[
MacosIconTheme.merge(
data: MacosIconThemeData(
color: selected ? MacosColors.white : theme.primaryColor,
size: itemSize.iconSize,
),
child: item.leading!,
),
SizedBox(width: spacing),
],
DefaultTextStyle(
style: labelStyle.copyWith(
color: selected ? textLuminance(selectedColor) : null,
Expand Down Expand Up @@ -497,3 +523,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

0 comments on commit 6c69d9d

Please sign in to comment.