Repository navigation
sleep: stop range durations from wrapping and orphaning their unit ("Min." alone on a line) #757
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,7 +185,7 @@ String sleepReadingText(AppLocalizations? l, num value, int places, | |
| /// A stage interval as one label. Seconds in, because that is what the analytics | ||
| /// interval carries; `hm` wants minutes. | ||
| String _rangeText(ana.StageInterval i) => | ||
| '${hm(i.loSec / 60)}–${hm(i.hiSec / 60)}'; | ||
| '${nbsp(hm(i.loSec / 60))}–${nbsp(hm(i.hiSec / 60))}'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Duration endpoints get cut off When text scaling or a narrow layout leaves less width than a localized duration endpoint needs, Allow line breaks within each endpoint or allocate enough width for the complete endpoint. Prompt for AI agentsIn `lib/ui2/screens/sleep_detail.dart` at line 188:
**Duration endpoints get cut off**
When text scaling or a narrow layout leaves less width than a localized duration endpoint needs, `_rangeText` makes each endpoint unbreakable, so `_stageRow` and `_Compare` can constrain it below its rendered width; the text then clips or overflows and the user sees a truncated duration.
Allow line breaks within each endpoint or allocate enough width for the complete endpoint.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep Chinese duration units whole inside range endpoints. In the zh locale,
|
||
|
|
||
| String _capitalise(String s) => | ||
| s.isEmpty ? s : s[0].toUpperCase() + s.substring(1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // A sleep stage duration is shown as a range, "1 Std. 34 Min.-2 Std. 54 Min.". | ||
| // Each side is one reading and must stay whole wherever it is drawn. Binding | ||
| // only ASCII spaces kept Latin units together but left CJK units (e.g. zh | ||
| // "分钟") breakable, since those scripts wrap between characters with no space | ||
| // to guard (#757 review). `nbsp` now glues every character with a word joiner, | ||
| // so no duration breaks internally in any locale; only the dash may wrap. | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| import 'package:openstrap_edge/state/locale_controller.dart'; | ||
| import 'package:openstrap_edge/ui2/screens/home_screen.dart' show hm, nbsp; | ||
|
|
||
| /// True iff a word joiner sits between every adjacent pair of code points, so | ||
| /// the run offers no internal line-break opportunity. | ||
| bool fullyGlued(String s) { | ||
| final runes = s.runes.toList(); | ||
| for (var i = 0; i + 1 < runes.length; i++) { | ||
| if (runes[i] != 0x2060 && runes[i + 1] != 0x2060) return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| void main() { | ||
| test('a duration never breaks internally, in Latin or CJK scripts', () async { | ||
| SharedPreferences.setMockInitialValues({}); | ||
| final c = LocaleController.seed('de'); | ||
| c.useForPresentation(); | ||
|
|
||
| final one = nbsp(hm(154)); // 2 h 34 min | ||
| expect(one.replaceAll('', ''), '2 Std. 34 Min.'); // unchanged text | ||
| expect(fullyGlued(one), isTrue); | ||
|
|
||
| // CJK has no spaces to bind, and wraps between characters — the gap the | ||
| // space-only version missed. | ||
| expect(nbsp('分钟'), '分钟'); | ||
| expect(fullyGlued(nbsp('1 小时 34 分钟')), isTrue); | ||
|
|
||
| await c.setCode(null); | ||
| c.dispose(); | ||
| }); | ||
|
|
||
| test('a range only ever wraps at the dash between its two durations', | ||
| () async { | ||
| SharedPreferences.setMockInitialValues({}); | ||
| final c = LocaleController.seed('de'); | ||
| c.useForPresentation(); | ||
|
|
||
| final range = '${nbsp(hm(94))}–${nbsp(hm(154))}'; | ||
| // The dash is the one separator left un-glued, so it is the only break. | ||
| expect(range.replaceAll('', '').split('–'), [hm(94), hm(154)]); | ||
| for (final part in range.split('–')) { | ||
| expect(fullyGlued(part), isTrue); | ||
| } | ||
|
|
||
| await c.setCode(null); | ||
| c.dispose(); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep comparison endpoints intact at large text sizes.
When an endpoint is wider than
_Compare’s value column, Flutter can split it despite the word joiners. Keep each endpoint intact and readable in this case.