mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-11 19:33:55 +01:00
The Log Meal tab did not fit this laptop, and had not for some time. Measured
under a real 1366x768 X server: it required 866px inside a 739px content pane
with every field EMPTY, and 938px with a day of meals logged.
Because the content frame was place()-centred it was sheared at BOTH edges at
once -- the "Diet Gate" title and the slot header (which meal you are being
asked to log) off the top, the calorie headline and the whole dashboard off the
bottom -- with no scrollbar anywhere in the package and nothing to indicate
content was missing. This is a hard lock: overrideredirect, a global grab, VT
switching disabled. Unreachable content is unrecoverable.
Two independent causes, both needed fixing:
- Every font size was handed to Tk as *points*. Tk encodes the unit in the
SIGN of the size, and _gatelock_typography carried a comment asserting the
opposite ("Tk has no separate px/pt distinction"). At ~100 DPI that made
every string ~30% oversized. Negative sizes now; the docstring records why.
- There was no scroll container. build_layout now uses gatelock's
ScrollableSurface, which top-anchors, scrolls by keyboard, and scrolls to
follow focus.
Font sizes alone were not enough: they take the layout to 702px, still over the
571px pane at 1024x600. Both fixes are load-bearing.
The grams/items selector was mouse-only. tk.OptionMenu's Menubutton defaults to
takefocus=0, so ::tk::FocusOK rejects it and it never entered the tab ring --
verified by walking the real ring, which ran Entry -> Text -> Listbox -> Button
-> TNotebook and skipped it entirely. Switching units rescales the whole entry,
so a pointerless user could not correct "250 grams" to "3 items" inside a lock
they cannot leave without logging a meal. It is now two Radiobuttons, which are
in the ring by default and take both Space and Return -- and which post nothing,
unlike a menu, whose grab-stealing is why screen-locker bans OptionMenu on lock
surfaces outright.
Also: the focus ring was invisible (Tk's default is 1px BLACK on #211D1B) and
_build_desc actively inverted it by setting highlightbackground, the UNfocused
ring, so the box outlined while idle and went black the moment it took focus.
Enter now activates buttons (X11 Tk binds only <space>). Text widgets no longer
trap Tab. notebook.enable_traversal() is called, so Ctrl+Tab and Ctrl+PageDown
work. wraplength drops 900 -> 640, the line-length cap, which also stops a
label forcing a 900px-wide layout onto a 1024px screen.
The Flutter app had two controls with no keyboard route at all. Its desktop
target is the web build in a Chrome --app window, so a touch gesture is not a
fallback there, it is the only interaction:
- Deleting a history entry was bound solely to onLongPress. Long-press has no
keyboard equivalent whatsoever. It now has a focusable IconButton; the
long-press stays as a redundant pointer shortcut.
- Calendar day cells were a bare GestureDetector, so navigating to
date-filtered history was pointer-only and invisible to a screen reader.
Now Semantics(button: true) over an InkWell.
Plus: the filter sheet built a TextEditingController inside build() with the
caret forced to end-of-text, so every keystroke discarded it and silently undid
mid-string Home/End/arrow editing. And nothing capped width, so on the 1366px
desktop window prose ran ~180 characters per line (twice the readable limit)
and a four-digit kcal field spanned ~1334px. AppWidth adds those caps.
Tests: the render check is a failing test, not a script -- ruff runs with
--unsafe-fixes, whose T201 fix DELETES print statements, which would silently
turn a diagnostic into a no-op. test_gate_layout_fits.py was verified red on
the pre-fix code ("content 866 in viewport 768 -> NO SCROLL VIEWPORT ->
UNREACHABLE CONTENT") and green after. The Flutter suite gains its first
keyboard-reachability assertions; it previously had ~109 tester.tap calls and
zero checks that anything was focusable.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
205 lines
7.5 KiB
Dart
205 lines
7.5 KiB
Dart
/// The app's design tokens: one identical palette shared across every one
|
|
/// of kuhy's apps (Flutter, web, Python/Tkinter alike) — see the
|
|
/// `unified-design-system` skill (`~/.claude/skills/unified-design-system/`)
|
|
/// for the frozen token table this file implements. Built from an explicit
|
|
/// `ColorScheme`, not `ColorScheme.fromSeed`, because the shared palette is
|
|
/// hand-picked, not algorithmically derived from one seed color.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Builds the app's single dark `ThemeData` from the shared token set.
|
|
ThemeData buildAppTheme() {
|
|
const colorScheme = ColorScheme.dark(
|
|
surface: Color(0xFF211D1B), // ink
|
|
surfaceContainerHighest: Color(0xFF38312E), // ink-raised-2
|
|
surfaceContainerHigh: Color(0xFF2B2624), // ink-raised-1
|
|
onSurface: Color(0xFFECEAE9), // text-on-dark
|
|
onSurfaceVariant: Color(0xFFAAA09A), // muted-on-dark
|
|
outline: Color(0xFF463E3A), // line-dark
|
|
primary: Color(0xFFB8862E), // accent
|
|
onPrimary: Color(
|
|
0xFF211D1B,
|
|
), // on-fill — every filled surface uses dark text
|
|
// secondary/tertiary — the shared palette has one accent, not a
|
|
// separate secondary hue, so these mirror primary. Without an explicit
|
|
// value here, widgets that reach for secondaryContainer (e.g.
|
|
// SegmentedButton's selected segment) silently fall back to Flutter's
|
|
// stock Material teal — confirmed live on-device in the todo app,
|
|
// which shares this same theme.dart template.
|
|
secondary: Color(0xFFB8862E), // accent
|
|
onSecondary: Color(0xFF211D1B), // on-fill
|
|
secondaryContainer: Color(0xFF463E3A), // line-dark
|
|
onSecondaryContainer: Color(0xFFB8862E), // accent
|
|
tertiary: Color(0xFFB8862E), // accent
|
|
onTertiary: Color(0xFF211D1B), // on-fill
|
|
tertiaryContainer: Color(0xFF463E3A), // line-dark
|
|
onTertiaryContainer: Color(0xFFB8862E), // accent
|
|
error: Color(0xFFE2585F), // danger
|
|
onError: Color(0xFF211D1B), // on-fill
|
|
);
|
|
return ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: colorScheme,
|
|
scaffoldBackgroundColor: colorScheme.surface,
|
|
extensions: const [AppStatusColors.dark],
|
|
textTheme: const TextTheme(
|
|
bodyLarge: TextStyle(fontSize: AppTextSize.body),
|
|
bodyMedium: TextStyle(fontSize: AppTextSize.body),
|
|
titleLarge: TextStyle(fontSize: AppTextSize.title),
|
|
titleMedium: TextStyle(fontSize: AppTextSize.subtitle),
|
|
labelMedium: TextStyle(fontSize: AppTextSize.label),
|
|
labelSmall: TextStyle(fontSize: AppTextSize.caption),
|
|
),
|
|
// Previously unset, so every TextField fell back to M3's default
|
|
// indigo focus color instead of the shared palette (open finding from
|
|
// the unified-design-system component doc).
|
|
inputDecorationTheme: InputDecorationTheme(
|
|
filled: true,
|
|
fillColor: colorScheme.surfaceContainerHigh,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
borderSide: BorderSide(color: colorScheme.outline),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
borderSide: BorderSide(color: colorScheme.outline),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
borderSide: BorderSide(color: colorScheme.primary, width: 2),
|
|
),
|
|
labelStyle: TextStyle(color: colorScheme.onSurfaceVariant),
|
|
),
|
|
// Previously unset, so every Divider fell back to M3's default grey
|
|
// instead of `line-dark` (same open finding as above).
|
|
dividerTheme: DividerThemeData(
|
|
color: colorScheme.outline,
|
|
thickness: 1,
|
|
space: AppSpacing.md,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Semantic status colors M3's [ColorScheme] has no role for (it only has
|
|
/// `error`). Success/warning are the shared `unified-design-system` values —
|
|
/// every status indicator (calendar day, slot chip, sync state) should read
|
|
/// these instead of an ad hoc `Colors.green`/`Colors.amber`.
|
|
@immutable
|
|
class AppStatusColors extends ThemeExtension<AppStatusColors> {
|
|
/// Creates a status-color set.
|
|
const AppStatusColors({required this.success, required this.warning});
|
|
|
|
/// The shared dark-theme instance — success/warning from the unified
|
|
/// palette (danger already exists as `colorScheme.error`).
|
|
static const dark = AppStatusColors(
|
|
success: Color(0xFF8A9A3C),
|
|
warning: Color(0xFFE0A63C),
|
|
);
|
|
|
|
/// Positive/on-track status (e.g. a fully-logged, in-budget day).
|
|
final Color success;
|
|
|
|
/// Caution/pending status (e.g. a partially-logged day).
|
|
final Color warning;
|
|
|
|
@override
|
|
AppStatusColors copyWith({Color? success, Color? warning}) => AppStatusColors(
|
|
success: success ?? this.success,
|
|
warning: warning ?? this.warning,
|
|
);
|
|
|
|
@override
|
|
AppStatusColors lerp(AppStatusColors? other, double t) {
|
|
if (other is! AppStatusColors) return this;
|
|
return AppStatusColors(
|
|
success: Color.lerp(success, other.success, t) ?? success,
|
|
warning: Color.lerp(warning, other.warning, t) ?? warning,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Shared spacing scale (4px base) — round any new value to one of these
|
|
/// instead of introducing an off-scale literal.
|
|
abstract final class AppSpacing {
|
|
/// 4px.
|
|
static const double xs = 4;
|
|
|
|
/// 8px.
|
|
static const double sm = 8;
|
|
|
|
/// 16px.
|
|
static const double md = 16;
|
|
|
|
/// 24px.
|
|
static const double lg = 24;
|
|
|
|
/// 32px.
|
|
static const double xl = 32;
|
|
|
|
/// 48px.
|
|
static const double xxl = 48;
|
|
}
|
|
|
|
/// Shared corner-radius scale. Nested radii should be `outer - gap`, not a
|
|
/// fixed constant — compute per instance per safe-design-rules rule 24.
|
|
abstract final class AppRadius {
|
|
/// Buttons, inputs, chips.
|
|
static const double sm = 8;
|
|
|
|
/// Cards.
|
|
static const double md = 12;
|
|
|
|
/// Sheets, dialogs.
|
|
static const double lg = 16;
|
|
}
|
|
|
|
/// Shared type scale (px). `body` is the floor for anything a user reads;
|
|
/// `label`/`caption` are for UI chrome only (timestamps, badges, tags).
|
|
abstract final class AppTextSize {
|
|
/// 12px — chrome only.
|
|
static const double caption = 12;
|
|
|
|
/// 14px — chrome only.
|
|
static const double label = 14;
|
|
|
|
/// 16px — the floor for actual reading content.
|
|
static const double body = 16;
|
|
|
|
/// 20px.
|
|
static const double subtitle = 20;
|
|
|
|
/// 24px.
|
|
static const double title = 24;
|
|
|
|
/// 32px.
|
|
static const double display = 32;
|
|
}
|
|
|
|
/// Line-length and layout caps for the desktop surface.
|
|
///
|
|
/// The Linux desktop build is this same Dart running as Flutter **web** in a
|
|
/// Chrome `--app` window, so every screen is laid out at whatever width that
|
|
/// window happens to be — commonly 1366px on the laptop. Without a cap, a
|
|
/// phone-width single-column design simply stretches: prose ran ~180 characters
|
|
/// per line (roughly 2x the readable limit) and a four-digit calorie field
|
|
/// spanned ~1334px. Neither is clipped, so nothing looks broken; it is just
|
|
/// unusable to read.
|
|
abstract final class AppWidth {
|
|
/// 640px — the prose/paragraph cap (tokens.md rule 21, 40rem, ~65-70 chars).
|
|
static const double prose = 640;
|
|
|
|
/// 420px — cap for a single-purpose input (a number, a short name).
|
|
///
|
|
/// Narrower than [prose] because a field wider than its longest plausible
|
|
/// value reads as a layout error rather than an affordance.
|
|
static const double field = 420;
|
|
|
|
/// Viewport height below which the layout should switch to its compact form.
|
|
///
|
|
/// 700px, i.e. 768 minus typical window chrome: the supported floor is a
|
|
/// 1366x768 panel, and these are *short* landscape viewports, which
|
|
/// phone-portrait test sizes never exercise.
|
|
static const double shortViewport = 700;
|
|
}
|