Skip to content

Commit eac1971

Browse files
committed
ui [nfc]: Pull out clampLchLightness helper
We'll use this for stream headers in the Inbox view, coming up.
1 parent cc75cc2 commit eac1971

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/widgets/color.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'dart:ui';
2+
3+
import 'package:flutter_color_models/flutter_color_models.dart';
4+
5+
// This function promises to deal with "LCH" lightness, not "LAB" lightness,
6+
// but it's not yet true. We haven't found a Dart libary that can work with LCH:
7+
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1677537>
8+
// We use LAB because some quick reading suggests that the "L" axis
9+
// is the same in both representations:
10+
// <https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch>
11+
//
12+
// TODO try LCH; see linked discussion
13+
Color clampLchLightness(Color color, num lowerLimit, num upperLimit) {
14+
final asLab = LabColor.fromColor(color);
15+
return asLab
16+
.copyWith(lightness: asLab.lightness.clamp(lowerLimit, upperLimit))
17+
.toColor();
18+
}

lib/widgets/unread_count_badge.dart

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'dart:ui';
22

3-
import 'package:flutter_color_models/flutter_color_models.dart';
43
import 'package:flutter/material.dart';
54

5+
import 'color.dart';
66
import 'text.dart';
77

88
/// A widget to display a given number of unreads in a conversation.
@@ -37,25 +37,10 @@ class UnreadCountBadge extends StatelessWidget {
3737
// Follows `.unread-count` in Vlad's replit:
3838
// <https://replit.com/@VladKorobov/zulip-sidebar#script.js>
3939
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
40-
41-
// The design uses "LCH", not "LAB", but we haven't found a Dart libary
42-
// that can work with LCH:
43-
// <https://replit.com/@VladKorobov/zulip-sidebar#script.js>
44-
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1677537>
45-
// We use LAB because some quick reading suggests that the "L" axis
46-
// is the same in both representations:
47-
// <https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch>
48-
// and because the design doesn't use the LCH representation except to
49-
// adjust an "L" value.
5040
//
51-
// TODO try LCH; see linked discussion
5241
// TODO fix bug where our results differ from the replit's (see unit tests)
5342
// TODO profiling for expensive computation
54-
final asLab = LabColor.fromColor(baseStreamColor!);
55-
return asLab
56-
.copyWith(lightness: asLab.lightness.clamp(30, 70))
57-
.toColor()
58-
.withOpacity(0.3);
43+
return clampLchLightness(baseStreamColor!, 30, 70).withOpacity(0.3);
5944
}
6045

6146
@override

0 commit comments

Comments
 (0)