Phosphor icons: resolve by name via a generated map (T-314)
Replace the 49 hand-maintained named consts with one generated
label→codepoint map (phosphor_glyphs.g.dart, 1512 glyphs from the glyph
table via tool/gen_phosphor_glyphs.dart). Feature code now references
glyphs by their exact kebab-case name — PhosphorIcons.byName('folder') —
with no raw codepoints; this also lets a Lua extension name an icon
without crossing the FFI boundary with a codepoint.
byName is total: an unknown name degrades to the `placeholder` box so the
bug is visible (it's a real error), while phosphor_glyphs_test asserts
every byName('...') literal in lib/ resolves — recovering the typo check a
const gave. Migrated the 89 call sites. Adds EmptyIconPainter for an
intentional blank that still reserves the icon box; ClideFilterBox gains
showIcon to keep the slot aligned when blank.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@ class ClideAccordion extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(left: 4, top: 10, bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
ClideIcon(expanded ? PhosphorIcons.caretDown : PhosphorIcons.caretRight, size: 10, color: tokens.globalTextMuted),
|
||||
ClideIcon(expanded ? PhosphorIcons.byName('caret-down') : PhosphorIcons.byName('caret-right'), size: 10, color: tokens.globalTextMuted),
|
||||
const SizedBox(width: 6),
|
||||
if (leading != null) ...[leading!, const SizedBox(width: 6)],
|
||||
ClideText('$label · $count',
|
||||
|
||||
@@ -94,7 +94,7 @@ class _RightContent extends StatelessWidget {
|
||||
children: [
|
||||
_WinButton(icon: const PhosphorIconPainter(0xe32a), onTap: wc.minimize, tokens: tokens),
|
||||
_WinButton(icon: const PhosphorIconPainter(0xe45e), onTap: wc.toggleMaximize, tokens: tokens),
|
||||
_WinButton(icon: PhosphorIcons.xMark, onTap: wc.close, tokens: tokens, isClose: true),
|
||||
_WinButton(icon: PhosphorIcons.byName('x'), onTap: wc.close, tokens: tokens, isClose: true),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ class ClideFilterBox extends StatefulWidget {
|
||||
this.hint = 'Filter…',
|
||||
this.debounce = const Duration(milliseconds: 200),
|
||||
this.onSubmitted,
|
||||
this.icon = PhosphorIcons.magnifyingGlass,
|
||||
this.icon,
|
||||
this.showIcon = true,
|
||||
this.address,
|
||||
});
|
||||
|
||||
@@ -24,10 +25,16 @@ class ClideFilterBox extends StatefulWidget {
|
||||
final Duration debounce;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
|
||||
/// Leading glyph. Defaults to the search glass; pass null for inputs
|
||||
/// that aren't searches (e.g. a replace or glob field).
|
||||
/// Leading glyph. Defaults to the search glass (resolved at build, since
|
||||
/// [PhosphorIcons.byName] isn't const); pass a custom painter to override it,
|
||||
/// or set [showIcon] = false for inputs that aren't searches (a replace/glob
|
||||
/// field).
|
||||
final ClideIconPainter? icon;
|
||||
|
||||
/// Whether to draw a leading glyph. False draws a blank one but keeps the
|
||||
/// slot's space, so non-search fields stay aligned with search ones.
|
||||
final bool showIcon;
|
||||
|
||||
/// Makes this box addressable from the CLI (D-6 parity, T-270). When set,
|
||||
/// the box listens on the MessageBus `filter.set` channel for its address
|
||||
/// — so `clide ui filter <address> <text>` drives it exactly as a UI
|
||||
@@ -123,10 +130,14 @@ class _ClideFilterBoxState extends State<ClideFilterBox> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
||||
child: Row(
|
||||
children: [
|
||||
if (widget.icon != null) ...[
|
||||
ClideIcon(widget.icon!, size: 13, color: tokens.globalTextMuted),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
// The slot is always reserved (size + gap) so search and non-search
|
||||
// boxes align; showIcon: false just draws a blank glyph (T-314).
|
||||
ClideIcon(
|
||||
widget.showIcon ? (widget.icon ?? PhosphorIcons.byName('magnifying-glass')) : const EmptyIconPainter(),
|
||||
size: 13,
|
||||
color: tokens.globalTextMuted,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Stack(
|
||||
alignment: Alignment.centerLeft,
|
||||
@@ -160,7 +171,7 @@ class _ClideFilterBoxState extends State<ClideFilterBox> {
|
||||
onTap: _clear,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: ClideIcon(PhosphorIcons.xMark, size: 11, color: tokens.globalTextMuted),
|
||||
child: ClideIcon(PhosphorIcons.byName('x'), size: 11, color: tokens.globalTextMuted),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -11,6 +11,23 @@ abstract class ClideIconPainter {
|
||||
void paint(Canvas canvas, Color color);
|
||||
}
|
||||
|
||||
/// Draws nothing, but [ClideIcon] still reserves its `size×size` box — so a
|
||||
/// caller can keep the icon slot for alignment without showing a glyph. This is
|
||||
/// the *intentional* empty (e.g. a non-search filter field), distinct from an
|
||||
/// unknown glyph name, which renders a visible `placeholder` error box (T-314).
|
||||
class EmptyIconPainter extends ClideIconPainter {
|
||||
const EmptyIconPainter();
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Color color) {}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is EmptyIconPainter;
|
||||
|
||||
@override
|
||||
int get hashCode => (EmptyIconPainter).hashCode;
|
||||
}
|
||||
|
||||
class ClideIcon extends StatelessWidget {
|
||||
const ClideIcon(
|
||||
this.painter, {
|
||||
|
||||
@@ -114,7 +114,7 @@ class _ClideLightboxState extends State<ClideLightbox> {
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: 8,
|
||||
child: _IconChip(icon: PhosphorIcons.xMark, label: 'close', onTap: widget.onDismiss, tokens: tokens),
|
||||
child: _IconChip(icon: PhosphorIcons.byName('x'), label: 'close', onTap: widget.onDismiss, tokens: tokens),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
|
||||
@@ -12,13 +12,13 @@ import 'package:flutter/widgets.dart';
|
||||
({Color color, ClideIconPainter icon}) _styleFor(ToastSeverity s, SurfaceTokens t) {
|
||||
switch (s) {
|
||||
case ToastSeverity.success:
|
||||
return (color: t.statusSuccess, icon: PhosphorIcons.checkCircle);
|
||||
return (color: t.statusSuccess, icon: PhosphorIcons.byName('check-circle'));
|
||||
case ToastSeverity.warning:
|
||||
return (color: t.statusWarning, icon: PhosphorIcons.warningCircle);
|
||||
return (color: t.statusWarning, icon: PhosphorIcons.byName('warning-circle'));
|
||||
case ToastSeverity.error:
|
||||
return (color: t.statusError, icon: PhosphorIcons.warningCircle);
|
||||
return (color: t.statusError, icon: PhosphorIcons.byName('warning-circle'));
|
||||
case ToastSeverity.info:
|
||||
return (color: t.statusInfo, icon: PhosphorIcons.circlesFour);
|
||||
return (color: t.statusInfo, icon: PhosphorIcons.byName('circles-four'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class _ClideToastState extends State<ClideToast> {
|
||||
child: ClideTappable(
|
||||
onTap: widget.onDismiss,
|
||||
builder: (ctx, hovered, _) => ClideIcon(
|
||||
PhosphorIcons.xMark,
|
||||
PhosphorIcons.byName('x'),
|
||||
size: clideIconStandard,
|
||||
color: hovered ? tokens.globalForeground : tokens.globalTextMuted,
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:clide/widgets/src/clide_icon.dart';
|
||||
import 'package:clide/widgets/src/icons/phosphor_glyphs.g.dart';
|
||||
|
||||
class PhosphorIconPainter extends ClideIconPainter {
|
||||
const PhosphorIconPainter(this.codePoint, {this.family = 'Phosphor'});
|
||||
@@ -27,55 +28,23 @@ class PhosphorIconPainter extends ClideIconPainter {
|
||||
int get hashCode => Object.hash(codePoint, family);
|
||||
}
|
||||
|
||||
/// Phosphor glyphs, resolved by their exact kebab-case name (e.g. `folder`,
|
||||
/// `folder-simple`, `git-branch`). The full label→codepoint table is the
|
||||
/// generated [kPhosphorGlyphs]; raw codepoints live only there, so feature code
|
||||
/// reads `PhosphorIcons.byName('folder')` rather than `0xe24a` (T-314). A
|
||||
/// string key also lets a Lua extension name an icon without crossing the FFI
|
||||
/// boundary with a codepoint.
|
||||
abstract class PhosphorIcons {
|
||||
static const folder = PhosphorIconPainter(0xe24a);
|
||||
static const fileText = PhosphorIconPainter(0xe23a);
|
||||
static const gitBranch = PhosphorIconPainter(0xe278);
|
||||
static const gitCommit = PhosphorIconPainter(0xe27a);
|
||||
static const gitDiff = PhosphorIconPainter(0xe27c);
|
||||
static const gitPullRequest = PhosphorIconPainter(0xe282);
|
||||
static const magnifyingGlass = PhosphorIconPainter(0xe30c);
|
||||
static const terminal = PhosphorIconPainter(0xe47e);
|
||||
static const terminalWindow = PhosphorIconPainter(0xeae8);
|
||||
static const code = PhosphorIconPainter(0xe1bc);
|
||||
static const codeBlock = PhosphorIconPainter(0xeafe);
|
||||
static const pencilSimple = PhosphorIconPainter(0xe3b4);
|
||||
static const eye = PhosphorIconPainter(0xe220);
|
||||
static const eyeSlash = PhosphorIconPainter(0xe224);
|
||||
static const arrowClockwise = PhosphorIconPainter(0xe036);
|
||||
static const arrowsOutSimple = PhosphorIconPainter(0xe0a6);
|
||||
static const arrowsInSimple = PhosphorIconPainter(0xe09e);
|
||||
static const list = PhosphorIconPainter(0xe2f0);
|
||||
static const listChecks = PhosphorIconPainter(0xeadc);
|
||||
static const gear = PhosphorIconPainter(0xe270);
|
||||
static const puzzlePiece = PhosphorIconPainter(0xe596);
|
||||
static const keyboard = PhosphorIconPainter(0xe2d8);
|
||||
static const palette = PhosphorIconPainter(0xe6c8);
|
||||
static const warning = PhosphorIconPainter(0xe4e0);
|
||||
static const warningCircle = PhosphorIconPainter(0xe4e2);
|
||||
static const shieldCheck = PhosphorIconPainter(0xe40c);
|
||||
static const shieldWarning = PhosphorIconPainter(0xe412);
|
||||
static const check = PhosphorIconPainter(0xe182);
|
||||
static const checkCircle = PhosphorIconPainter(0xe184);
|
||||
static const caretLeft = PhosphorIconPainter(0xe138);
|
||||
static const caretRight = PhosphorIconPainter(0xe13a);
|
||||
static const caretDown = PhosphorIconPainter(0xe136);
|
||||
static const caretUp = PhosphorIconPainter(0xe13c);
|
||||
// Chevron-with-edge-line: reads as "collapse to / expand from the edge" (T-294).
|
||||
static const caretLineLeft = PhosphorIconPainter(0xe132);
|
||||
static const caretLineRight = PhosphorIconPainter(0xe130);
|
||||
static const graph = PhosphorIconPainter(0xeb58);
|
||||
static const treeStructure = PhosphorIconPainter(0xe67c);
|
||||
static const image = PhosphorIconPainter(0xe2ca);
|
||||
static const link = PhosphorIconPainter(0xe2e2);
|
||||
static const pushPin = PhosphorIconPainter(0xe3e2);
|
||||
static const arrowUUpLeft = PhosphorIconPainter(0xe08a);
|
||||
static const chatCircle = PhosphorIconPainter(0xe168);
|
||||
static const robot = PhosphorIconPainter(0xe762);
|
||||
static const ticket = PhosphorIconPainter(0xe490);
|
||||
static const lightbulb = PhosphorIconPainter(0xe2dc);
|
||||
static const notepad = PhosphorIconPainter(0xe63e);
|
||||
static const bookOpen = PhosphorIconPainter(0xe0e6);
|
||||
static const xMark = PhosphorIconPainter(0xe4f6);
|
||||
static const circlesFour = PhosphorIconPainter(0xe190);
|
||||
/// Shown when a name doesn't resolve. An unresolved name is a real error — a
|
||||
/// wrong or missing label — so the fallback is `placeholder`: the box reads
|
||||
/// as a render error and surfaces the bug honestly, rather than masking it as
|
||||
/// an intentional "unknown" the way a `question` mark would.
|
||||
static const String fallbackName = 'placeholder';
|
||||
|
||||
/// Resolve a glyph by its kebab-case [name]. A total function: an unknown
|
||||
/// name degrades to [fallbackName] so a bad value (a typo, a stale setting, a
|
||||
/// Lua extension's string) never crashes the UI. Typos in clide's own call
|
||||
/// sites are caught at CI by `phosphor_glyphs_test`, which asserts every
|
||||
/// `byName('…')` literal in `lib/` exists in the map.
|
||||
static PhosphorIconPainter byName(String name) => PhosphorIconPainter(kPhosphorGlyphs[name] ?? kPhosphorGlyphs[fallbackName]!);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user