Skip to content

Commit

Permalink
Change how we determine the background colors
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette committed Dec 17, 2024
1 parent 787bd31 commit 61846e0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class PropertyEditorController extends DisposableController
position: cursorPosition,
);
final args = result?.args ?? <EditableArgument>[];
_editableArgs.value = args;
// TODO(elliette): Once the server sends back the arguments in a
// consistent order, we can remove sorting by name.
_editableArgs.value = args..sort((a, b) => a.name.compareTo(b.name));
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class _EditablePropertyItem extends StatelessWidget {
color:
argument.hasArgument
? theme.colorScheme.emphasizedRowBackgroundColor
: theme.colorScheme.deemphasizedRowBackgroundColor,
: null,
border: Border(bottom: defaultBorderSide(Theme.of(context))),
),
child: _ListItemPadding(
Expand Down
10 changes: 6 additions & 4 deletions packages/devtools_app_shared/lib/src/ui/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ extension DevToolsSharedColorScheme on ColorScheme {
Color get alternatingBackgroundColor2 =>
isLight ? surface.darken(0.06) : surface.brighten(0.06);

Color? get emphasizedRowBackgroundColor =>
isLight ? null : background.brighten(0.15);
Color? get emphasizedRowBackgroundColor {
if (surface.isGreyscale()) {
return primaryContainer;
}

Color? get deemphasizedRowBackgroundColor =>
isLight ? background.darken(0.15) : null;
return surface.accent();
}

Color get selectedRowBackgroundColor =>
isLight ? const Color(0xFFC7C6CA) : const Color(0xFF5E5E62);
Expand Down
29 changes: 29 additions & 0 deletions packages/devtools_app_shared/lib/src/ui/ui_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math' as math;
import 'dart:ui';

import 'package:logging/logging.dart';
Expand Down Expand Up @@ -74,4 +75,32 @@ extension ColorExtension on Color {
blue: c.b + ((1.0 - c.b) * percent),
);
}

bool isGreyscale() {
final averageChannel = (r + g + b) / 3;
final lowestChannel = math.max(0, averageChannel - 0.05);
final highestChannel = math.min(1, averageChannel + 0.05);
return [
r,
g,
b
].every((channel) => channel >= lowestChannel && channel <= highestChannel);
}

Color accent() {
if (isGreyscale()) return this;

final sorted = [r, g, b]..sort();
return Color.from(
alpha: a,
red: _calculateAccentChannel(r, sorted),
blue: _calculateAccentChannel(b, sorted),
green: _calculateAccentChannel(g, sorted));
}

double _calculateAccentChannel(double channel, List<double> sorted) {
if (sorted.first == channel) return (sorted.first + sorted.last) / 1.5;
if (sorted.last == channel) return (sorted.first + sorted.last) / 2.5;
return channel;
}
}

0 comments on commit 61846e0

Please sign in to comment.