From e67cc63998d1f31c030685bbf48b6e9cce882cec Mon Sep 17 00:00:00 2001 From: lead Date: Wed, 18 Nov 2026 22:15:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E9=87=8D=E5=81=9A=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=99=A8=E7=95=8C=E9=9D=A2=E5=B9=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20DPI=20=E5=8F=91=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 交叉编译补嵌 runner.exe.manifest:GNUn res 不再丢掉 DPI 声明,缩放屏不再位图拉伸 - main.cpp 建窗前自行声明 Per-Monitor V2 DPI 感知(三级回退) - win32_window 初始窗口按显示器工作区上限收缩,避免 150% 缩放后超出屏幕 - 重做主题:中性石墨底 + 高对比正文、统一字号/间距/圆角令牌、Segoe UI + 雅黑字体栈 - 首页/下载/设置/关于四页重排,宽屏自适应、小窗不溢出 - 修复下拉框字体丢失、封面遮罩盖住占位、任务状态未翻译等问题 - 截图脚本:注入 CJK/图标字体、runAsync 取像素、补小窗回归用例 --- GC-UI/CI.md | 19 + GC-UI/README.md | 31 +- GC-UI/frontend/lib/main.dart | 2 + GC-UI/frontend/lib/pages.dart | 2078 ++++++++++------- GC-UI/frontend/lib/shell.dart | 270 ++- GC-UI/frontend/lib/theme.dart | 918 +++++++- GC-UI/frontend/tool/render_shots_test.dart | 174 +- GC-UI/frontend/windows/runner/main.cpp | 73 + .../frontend/windows/runner/win32_window.cpp | 20 +- buildsh/cross/CMakeLists.txt | 13 + 10 files changed, 2518 insertions(+), 1080 deletions(-) diff --git a/GC-UI/CI.md b/GC-UI/CI.md index 0eb54f7..865bddb 100644 --- a/GC-UI/CI.md +++ b/GC-UI/CI.md @@ -137,6 +137,25 @@ GC-UI.exe flutter_windows.dll data/{icudtl.dat, app.so, flutter_assets/} - `Runner.rc` 在 windres 下有两处不兼容:图标用反斜杠相对路径、`VERSION_AS_STRING` 依赖命令行传 `-D` 的转义字符串。脚本生成一份路径与宏都已规整的 rc 副本再编译。 +### 交叉编译必须自己嵌 DPI 清单 + +`windows/runner/CMakeLists.txt` 把 `runner.exe.manifest` 当**源文件**列进 target, +Visual Studio 生成器会把它交给链接器(`/MANIFESTINPUT`)自动嵌入 exe; +但 `buildsh/cross/CMakeLists.txt` 只用 windres 编 `Runner.rc`,CMake 不会做这一步。 +结果就是交叉编出来的 `GC-UI.exe` **完全没有清单**:Windows 认为它「DPI 不感知」, +在 125% / 150% 缩放的屏幕上把整块窗口当位图拉伸 —— 界面整体发虚,中文小字最明显。 + +现在两处都已加固,改这块代码时不要拆掉任何一处: + +| 位置 | 做法 | +|---|---| +| `buildsh/cross/CMakeLists.txt` | 往 `Runner.cross.rc` 追加 `1 24 "/runner.exe.manifest"`(id 1 = CREATEPROCESS_MANIFEST_RESOURCE_ID,type 24 = RT_MANIFEST) | +| `windows/runner/main.cpp` | 建窗之前调 `SetProcessDpiAwarenessContext(PER_MONITOR_AWARE_V2)`,失败依次退到 `SetProcessDpiAwareness` / `SetProcessDPIAware` | + +`main.cpp` 那层是兜底:即使清单因为工具链原因没嵌进去,程序自己也会声明 DPI 感知。 +验证办法(Windows):`GC-UI.exe` 属性 →「兼容性」里不该出现「替代高 DPI 缩放行为」, +或在 125% 缩放下截图,文字边缘应是锐利的 1.25 倍像素,而不是模糊的插值。 + `.gitea/workflows` 里的 `windows` 任务仍然跑在 `windows-latest` 上;若手头只有 macOS/Linux 构建机,可以把该任务的 `runs-on` 换成对应标签,直接复用这套交叉编译脚本, 不再需要 VS Build Tools。 diff --git a/GC-UI/README.md b/GC-UI/README.md index 3870a03..2e92303 100644 --- a/GC-UI/README.md +++ b/GC-UI/README.md @@ -149,14 +149,35 @@ flutter test # 前后端联调(需要后端正在运行;后端没起时自动跳过) flutter test test/backend_contract_test.dart -# 生成界面截图到 test/shots/(视觉检查用) +# 生成界面截图到 test/shots/(视觉检查用,不需要后端) flutter test tool/render_shots_test.dart ``` -截图脚本覆盖四个页面(首页 / 下载 / 设置 / 关于)再加一整套外壳: -`test/shots/home.png`、`download.png`、`settings.png`、`about.png`、`shell.png`。 -需要先在本机 17890 端口跑起后端;脚本用 `runAsync` 给真实 HTTP 留出时间, -否则 `flutter_test` 的假时钟会让页面停在加载态。 +截图脚本覆盖四个页面(首页 / 下载 / 设置 / 关于),再加一整套外壳与 1024×680 小窗回归: +`test/shots/home.png`、`download.png`、`settings.png`、`about.png`、`shell.png`、 +`home-small.png`、`download-small.png`、`settings-small.png`,以及浅色主题的 +`home-light.png`、`settings-light.png`。小窗用例会顺带抓布局溢出(RenderFlex overflow)。 + +四个页面都用预置数据(`initialModels` / `initialSources` / `initialAbout` 等)渲染, +所以**不需要先起后端**。测试环境的字体是 Ahem(所有字都是方块),脚本会显式加载 +系统里的 Noto Sans SC / 微软雅黑 / 苹方,并顺带加载 Material 图标字体,中文和图标才正常。 +截图必须放在 `runAsync` 里取像素(`toImage` / `toByteData` 走真实引擎管线), +否则 fake async 时钟不推进,每个用例会卡满 10 分钟才超时。 + +## 界面清晰度(DPI) + +`GC-UI.exe` 必须在启动时就声明 DPI 感知,否则 Windows 在 125% / 150% 缩放下会把 +整块窗口当位图拉伸,界面看起来「糊」—— 中文小字最先糊。两处保证: + +- `windows/runner/runner.exe.manifest`:PerMonitorV2(原生 MSVC 构建由 CMake 自动嵌入) +- `windows/runner/main.cpp`:建窗前再声明一次,依次尝试 + `SetProcessDpiAwarenessContext` → `SetProcessDpiAwareness` → `SetProcessDPIAware` +- `buildsh/cross/CMakeLists.txt`:交叉编译时把清单写进 `.rc`(windres 不会自动嵌入) + +另外主题里做了两件跟「清晰」有关的事:字体族走 +`Segoe UI + Microsoft YaHei UI`(macOS 走苹方)而不是让引擎随意回退; +正文最小 12px、行高固定,中文不再挤成一片。详见 +[CI.md 的「交叉编译必须自己嵌 DPI 清单」](CI.md#交叉编译必须自己嵌-dpi-清单)。 ## 「关于」页展示的技术栈 diff --git a/GC-UI/frontend/lib/main.dart b/GC-UI/frontend/lib/main.dart index db9e56e..96286a5 100644 --- a/GC-UI/frontend/lib/main.dart +++ b/GC-UI/frontend/lib/main.dart @@ -42,6 +42,8 @@ class _GcUiAppState extends State { return MaterialApp( title: 'Morris GC', debugShowCheckedModeBanner: false, + // 桌面端不要移动端那套拉伸回弹和边缘光晕。 + scrollBehavior: const GcScrollBehavior(), theme: buildGcTheme(Brightness.light), darkTheme: buildGcTheme(Brightness.dark), themeMode: mode, diff --git a/GC-UI/frontend/lib/pages.dart b/GC-UI/frontend/lib/pages.dart index 5f0ef66..86e485b 100644 --- a/GC-UI/frontend/lib/pages.dart +++ b/GC-UI/frontend/lib/pages.dart @@ -138,95 +138,89 @@ class _HomePageViewState extends State { final settings = widget.controller.settings; return RefreshIndicator( onRefresh: _load, + color: GcColors.accent, + backgroundColor: GcColors.surface, child: ListView( - padding: const EdgeInsets.fromLTRB(26, 24, 26, 28), + physics: const AlwaysScrollableScrollPhysics(), + padding: const EdgeInsets.fromLTRB( + GcSpace.xxl, GcSpace.xxl, GcSpace.xxl, GcSpace.xxxl), children: [ _hero(settings), - const SizedBox(height: 18), - Row( - children: [ - Expanded( - child: Text( - T('home.installed'), - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - GcHint(T('home.count', [_models.length])), - const SizedBox(width: 10), - IconButton( - tooltip: T('common.refresh'), - onPressed: _load, - icon: const Icon(Icons.refresh_rounded, size: 18), - color: GcColors.faint, - ), - ], - ), + const SizedBox(height: GcSpace.xxl), + _sectionHeader(), if (_notice != null) ...[ - const SizedBox(height: 8), - GcCard( - padding: const EdgeInsets.all(12), - child: Text( - _notice!, - style: TextStyle(fontSize: 12, color: GcColors.warn), - ), + const SizedBox(height: GcSpace.md), + GcMessage( + title: _notice!, + icon: Icons.info_outline_rounded, + color: GcColors.warn, ), ], - const SizedBox(height: 12), + const SizedBox(height: GcSpace.lg), if (_loading) const Padding( - padding: EdgeInsets.symmetric(vertical: 40), - child: Center(child: CircularProgressIndicator(strokeWidth: 2.4)), + padding: EdgeInsets.symmetric(vertical: 48), + child: Center( + child: SizedBox( + width: 22, + height: 22, + child: CircularProgressIndicator(strokeWidth: 2), + ), + ), ) else if (_error != null) - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(T('common.error'), - style: TextStyle(color: GcColors.danger)), - const SizedBox(height: 8), - GcHint(_error!), - ], + GcMessage( + title: T('common.error'), + message: _error, + icon: Icons.cloud_off_rounded, + color: GcColors.danger, + action: OutlinedButton( + onPressed: _load, + child: Text(T('common.retry')), ), ) else if (_models.isEmpty) _emptyState() else - Wrap( - spacing: 16, - runSpacing: 16, - children: [ - for (final model in _models) - _ModelCard( - model: model, - previewUrl: widget.controller.api.previewUrl(model), - onLaunch: () => _launch(model), - onOpenFolder: () => _openFolder(model.directory), - onDelete: () => _delete(model), - ), - ], + LayoutBuilder( + builder: (context, constraints) { + const spacing = GcSpace.lg; + final columns = + (constraints.maxWidth / 320).floor().clamp(1, 4); + final cardWidth = + (constraints.maxWidth - spacing * (columns - 1)) / columns; + return Wrap( + spacing: spacing, + runSpacing: spacing, + children: [ + for (final model in _models) + SizedBox( + width: cardWidth, + child: _ModelCard( + model: model, + previewUrl: widget.controller.api.previewUrl(model), + onLaunch: () => _launch(model), + onOpenFolder: () => _openFolder(model.directory), + onDelete: () => _delete(model), + ), + ), + ], + ); + }, ), ], ), ); } + /// 顶部横幅:产品定位 + 主操作 + 关键指标。 + /// + /// 不用渐变:深色主题下的低对比渐变会让整块区域发灰,看起来就是「糊」。 Widget _hero(SettingsInfo? settings) { - return Container( - padding: const EdgeInsets.all(26), - decoration: BoxDecoration( - gradient: const LinearGradient( - colors: [Color(0xFF16233C), Color(0xFF0E1A31)], - begin: Alignment.topLeft, - end: Alignment.bottomRight, - ), - borderRadius: BorderRadius.circular(16), - border: Border.all(color: GcColors.line), - ), + final enabledSources = + settings?.sources.where((s) => s.enabled).length ?? 0; + return GcCard( + padding: const EdgeInsets.all(GcSpace.xxl + 2), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -235,125 +229,186 @@ class _HomePageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - T('home.title'), - style: const TextStyle( - fontSize: 24, - fontWeight: FontWeight.w700, - color: Colors.white, + 'MODEL LIBRARY', + style: TextStyle( + fontSize: 11, + height: 1.2, + letterSpacing: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.accent, ), ), - const SizedBox(height: 9), + const SizedBox(height: GcSpace.md), + Text( + T('home.title'), + style: TextStyle( + fontSize: 26, + height: 1.25, + fontWeight: FontWeight.w600, + letterSpacing: -0.2, + color: GcColors.ink, + ), + ), + const SizedBox(height: GcSpace.sm), ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 500), + constraints: const BoxConstraints(maxWidth: 460), child: Text( T('home.subtitle'), - style: const TextStyle( - fontSize: 12.5, - color: Color(0xFFA9BEDF), - height: 1.5, + style: TextStyle( + fontSize: 13, + height: 1.65, + color: GcColors.muted, ), ), ), - const SizedBox(height: 16), - Wrap( - spacing: 10, - runSpacing: 8, + const SizedBox(height: GcSpace.xl), + Row( children: [ - FilledButton( - onPressed: _models.isEmpty ? null : () => _launch(_models.first), - child: Text(T('home.launch')), + FilledButton.icon( + onPressed: + _models.isEmpty ? null : () => _launch(_models.first), + icon: const Icon(Icons.play_arrow_rounded, size: 18), + label: Text(T('home.launch')), ), + const SizedBox(width: GcSpace.md), OutlinedButton( onPressed: () => widget.controller.goTo(1), child: Text(T('home.download')), ), - OutlinedButton( + const SizedBox(width: GcSpace.xs), + TextButton( onPressed: () => widget.controller.goTo(2), child: Text(T('home.settings')), ), ], ), - const SizedBox(height: 10), + const SizedBox(height: GcSpace.md), Text( T('home.launchHint'), - style: const TextStyle(fontSize: 11, color: Color(0xFF7E93B8)), + style: TextStyle( + fontSize: 12, + height: 1.55, + color: GcColors.faint, + ), ), ], ), ), - const SizedBox(width: 16), - Row( - children: [ - _stat('${_models.length}', T('home.stats.models'), 96), - const SizedBox(width: 10), - _stat('${settings?.sources.where((s) => s.enabled).length ?? 0}', - T('home.stats.sources'), 96), - const SizedBox(width: 10), - _stat('${settings?.memoryBudgetMb ?? 0} MB', - T('home.stats.memory'), 112), - ], + const SizedBox(width: GcSpace.xxl), + Container( + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.xl, + vertical: GcSpace.lg, + ), + decoration: BoxDecoration( + color: GcColors.surfaceAlt, + borderRadius: BorderRadius.circular(GcRadius.control), + border: Border.all(color: GcColors.line), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + GcMetric( + value: '${_models.length}', + label: T('home.stats.models'), + ), + _metricDivider(), + GcMetric( + value: '$enabledSources', + label: T('home.stats.sources'), + ), + _metricDivider(), + GcMetric( + value: '${settings?.memoryBudgetMb ?? 0}', + label: T('home.stats.memory'), + ), + ], + ), ), ], ), ); } - Widget _stat(String value, String label, double width) { + Widget _metricDivider() { return Container( - width: width, - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - decoration: BoxDecoration( - color: GcColors.surfaceAlt, - borderRadius: BorderRadius.circular(14), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - value, - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w600, - color: Colors.white, - ), + width: 1, + height: 34, + margin: const EdgeInsets.symmetric(horizontal: GcSpace.xl), + color: GcColors.line, + ); + } + + Widget _sectionHeader() { + return Row( + children: [ + Text( + T('home.installed'), + style: TextStyle( + fontSize: 16, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.ink, ), - const SizedBox(height: 2), - Text( - label, - style: const TextStyle(fontSize: 10.5, color: Color(0xFF7E93B8)), - ), - ], - ), + ), + const SizedBox(width: GcSpace.sm), + GcPill(T('home.count', [_models.length]), subtle: true), + const Spacer(), + IconButton( + tooltip: T('common.refresh'), + onPressed: _load, + icon: const Icon(Icons.refresh_rounded, size: 18), + ), + ], ); } Widget _emptyState() { return GcCard( - padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 34), + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.xxxl, + vertical: 40, + ), child: Column( children: [ + Container( + width: 52, + height: 52, + alignment: Alignment.center, + decoration: BoxDecoration( + color: GcColors.accentSoft, + borderRadius: BorderRadius.circular(GcRadius.panel), + ), + child: Icon( + Icons.travel_explore_rounded, + size: 26, + color: GcColors.accent, + ), + ), + const SizedBox(height: GcSpace.lg), Text( T('home.empty'), style: TextStyle( - fontSize: 15, + fontSize: 16, + height: 1.4, fontWeight: FontWeight.w600, color: GcColors.ink, ), ), - const SizedBox(height: 10), + const SizedBox(height: GcSpace.sm), ConstrainedBox( constraints: const BoxConstraints(maxWidth: 420), child: Text( T('home.emptyHint'), textAlign: TextAlign.center, style: TextStyle( - fontSize: 12, - color: GcColors.faint, - height: 1.5, + fontSize: 12.5, + height: 1.7, + color: GcColors.muted, ), ), ), - const SizedBox(height: 16), + const SizedBox(height: GcSpace.xl), FilledButton( onPressed: () => widget.controller.goTo(1), child: Text(T('home.emptyAction')), @@ -393,258 +448,237 @@ class _ModelCardState extends State<_ModelCard> { onEnter: (_) => setState(() => _hover = true), onExit: (_) => setState(() => _hover = false), cursor: SystemMouseCursors.click, - child: AnimatedContainer( - duration: const Duration(milliseconds: 160), - curve: Curves.easeOut, - width: 336, - transform: Matrix4.translationValues(0, _hover ? -3 : 0, 0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(16), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(_hover ? 0.42 : 0.22), - blurRadius: _hover ? 26 : 14, - offset: Offset(0, _hover ? 10 : 6), - ), - ], - ), - child: GcCard( - padding: EdgeInsets.zero, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // 封面:图片 + 底部渐变遮罩 + 播放提示 + 版本徽章。 - ClipRRect( - borderRadius: - const BorderRadius.vertical(top: Radius.circular(13)), - child: SizedBox( - height: 152, - width: double.infinity, - child: Stack( - fit: StackFit.expand, + child: GcCard( + padding: EdgeInsets.zero, + clip: true, + borderColor: _hover ? GcColors.lineStrong : GcColors.line, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _cover(model), + Padding( + padding: const EdgeInsets.fromLTRB( + GcSpace.lg, + GcSpace.md + 2, + GcSpace.lg, + GcSpace.md, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( children: [ - Container( - color: const Color(0xFF0B1226), - child: model.hasPreview - ? Image.network( - widget.previewUrl, - fit: BoxFit.cover, - // 只按展示尺寸解码,避免大图占用内存、拖慢首帧。 - cacheWidth: 672, - errorBuilder: (context, error, stack) => - const _PreviewFallback(), - ) - : const _PreviewFallback(), - ), - const DecoratedBox( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Color(0x00000000), - Color(0x22000000), - Color(0xE60A1226), - ], - stops: [0.45, 0.72, 1.0], + Expanded( + child: Text( + model.name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 14.5, + height: 1.35, + fontWeight: FontWeight.w600, + color: GcColors.ink, ), ), ), - Positioned( - left: 14, - right: 14, - bottom: 11, - child: Row( - children: [ - if (model.version.isNotEmpty) - _CoverPill( - text: 'v${model.version}', - color: GcColors.accent, - ), - if (model.author.isNotEmpty) ...[ - const SizedBox(width: 8), - Flexible( - child: Text( - model.author, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: const TextStyle( - fontSize: 10.5, - color: Colors.white70, - ), - ), - ), - ], - const Spacer(), - AnimatedOpacity( - opacity: _hover ? 1 : 0, - duration: const Duration(milliseconds: 160), - child: Container( - width: 30, - height: 30, - decoration: BoxDecoration( - color: GcColors.accent.withOpacity(0.9), - shape: BoxShape.circle, - ), - child: const Icon(Icons.play_arrow_rounded, - size: 20, color: Color(0xFF08101F)), - ), - ), - ], + const SizedBox(width: GcSpace.sm), + Text( + model.sizeText, + style: TextStyle( + fontSize: 12, + height: 1.35, + color: GcColors.faint, ), ), ], ), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(16, 13, 16, 15), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - model.name, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 14.5, - fontWeight: FontWeight.w700, - color: GcColors.ink, - ), - ), - ), - const SizedBox(width: 8), - Text( - model.sizeText, - style: TextStyle( - fontSize: 10.5, - color: GcColors.faint, - ), - ), - ], - ), - const SizedBox(height: 7), - // 简介:固定两行高度,避免卡片高低不齐。 - SizedBox( - height: 34, - child: Text( - model.description.isEmpty - ? T('home.noDescription') - : model.description, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 12, - height: 1.4, - color: model.description.isEmpty - ? GcColors.faint - : GcColors.muted, - ), + const SizedBox(height: GcSpace.sm - 2), + SizedBox( + height: 36, + child: Text( + model.description.isEmpty + ? T('home.noDescription') + : model.description, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.5, + height: 1.45, + color: model.description.isEmpty + ? GcColors.faint + : GcColors.muted, ), ), - if (model.tags.isNotEmpty) ...[ - const SizedBox(height: 8), - Wrap( + ), + if (model.tags.isNotEmpty) ...[ + const SizedBox(height: GcSpace.sm + 2), + SizedBox( + height: 20, + child: Wrap( spacing: 6, - runSpacing: 4, + runSpacing: 6, children: [ for (final tag in model.tags.take(3)) - _CoverPill( - text: tag, - color: GcColors.muted, - subtle: true, - ), + GcPill(tag, subtle: true), ], ), - ], - const SizedBox(height: 13), - Row( - children: [ - FilledButton.icon( - onPressed: widget.onLaunch, - icon: const Icon(Icons.play_arrow_rounded, size: 17), - label: Text(T('home.launch')), - ), - const Spacer(), - TextButton( - onPressed: widget.onOpenFolder, - child: Text(T('home.open')), - ), - TextButton( - onPressed: widget.onDelete, - style: TextButton.styleFrom( - foregroundColor: GcColors.danger, - ), - child: Text(T('home.delete')), - ), - ], ), ], - ), + const SizedBox(height: GcSpace.md + 2), + Row( + children: [ + FilledButton.icon( + onPressed: widget.onLaunch, + icon: const Icon(Icons.play_arrow_rounded, size: 18), + label: Text(T('home.launch')), + ), + const Spacer(), + IconButton( + tooltip: T('home.open'), + onPressed: widget.onOpenFolder, + icon: const Icon(Icons.folder_open_rounded, size: 18), + ), + IconButton( + tooltip: T('home.delete'), + onPressed: widget.onDelete, + icon: + const Icon(Icons.delete_outline_rounded, size: 18), + ), + ], + ), + ], ), - ], + ), + ], + ), + ), + ); + } + + /// 封面:按卡片宽度和屏幕像素比解码,避免被放大后发虚。 + Widget _cover(ModelInfo model) { + final dpr = MediaQuery.devicePixelRatioOf(context); + final decodeWidth = + (MediaQuery.sizeOf(context).width * dpr).clamp(320, 900).round(); + return SizedBox( + height: 156, + width: double.infinity, + child: Stack( + fit: StackFit.expand, + children: [ + _PreviewFallback(model: model), + if (model.hasPreview) + Image.network( + widget.previewUrl, + fit: BoxFit.cover, + cacheWidth: decodeWidth, + filterQuality: FilterQuality.medium, + gaplessPlayback: true, + errorBuilder: (context, error, stack) => const SizedBox.shrink(), + ), + DecoratedBox( + decoration: BoxDecoration( + // 只用「透明 → 深色」的遮罩,别用 alphaBlend:叠加不透明底色 + // 会把整张封面盖平,占位字母也跟着消失。 + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + GcColors.appBg.withOpacity(0.0), + GcColors.appBg.withOpacity(0.32), + GcColors.appBg.withOpacity(0.88), + ], + stops: const [0.42, 0.72, 1.0], + ), + ), ), - ), - ), - ); - } -} - -/// 封面上的小胶囊标签(版本 / 标签)。 -class _CoverPill extends StatelessWidget { - const _CoverPill({ - required this.text, - required this.color, - this.subtle = false, - }); - - final String text; - final Color color; - final bool subtle; - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3), - decoration: BoxDecoration( - color: subtle ? GcColors.surfaceAlt : color.withOpacity(0.14), - borderRadius: BorderRadius.circular(999), - border: Border.all( - color: subtle ? GcColors.line : color.withOpacity(0.35), - ), - ), - child: Text( - text, - style: TextStyle( - fontSize: 10, - height: 1.1, - color: subtle ? GcColors.faint : color, - fontWeight: FontWeight.w600, - ), + Positioned( + left: GcSpace.md, + right: GcSpace.sm, + bottom: GcSpace.sm, + child: Row( + children: [ + if (model.version.isNotEmpty) + GcPill('v${model.version}', color: GcColors.accent), + if (model.author.isNotEmpty) ...[ + const SizedBox(width: GcSpace.sm), + Flexible( + child: Text( + model.author, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 11.5, + height: 1.3, + color: GcColors.muted, + ), + ), + ), + ], + const Spacer(), + AnimatedOpacity( + opacity: _hover ? 1 : 0, + duration: const Duration(milliseconds: 140), + child: Container( + width: 26, + height: 26, + decoration: BoxDecoration( + color: GcColors.accentFill, + shape: BoxShape.circle, + ), + child: Icon( + Icons.play_arrow_rounded, + size: 18, + color: GcColors.onAccent, + ), + ), + ), + ], + ), + ), + ], ), ); } } +/// 没有封面时的占位:型号首字 + 淡淡的网格感,比一个大「◎」更像封面。 class _PreviewFallback extends StatelessWidget { - const _PreviewFallback(); + const _PreviewFallback({this.model}); + + final ModelInfo? model; @override Widget build(BuildContext context) { - return Container( - decoration: const BoxDecoration( + final label = (model?.name ?? '').characters.isEmpty + ? '◎' + : model!.name.characters.first; + return DecoratedBox( + decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, - colors: [Color(0xFF16233C), Color(0xFF0B1226)], + colors: [ + Color.alphaBlend( + GcColors.accent.withOpacity(0.22), + GcColors.surfaceAlt, + ), + GcColors.surfaceAlt, + ], ), ), - child: const Center( + child: Center( child: Text( - '◎', - style: TextStyle(fontSize: 34, color: Color(0xFF24365A)), + label, + style: TextStyle( + fontSize: 46, + height: 1.0, + fontWeight: FontWeight.w600, + color: Color.alphaBlend( + GcColors.accent.withOpacity(0.55), + GcColors.surfaceAlt, + ), + ), ), ), ); @@ -826,7 +860,8 @@ class _DownloadPageViewState extends State { } } - Future _jobAction(Future Function(String id) action, String id) async { + Future _jobAction( + Future Function(String id) action, String id) async { try { await action(id); await _refreshJobs(); @@ -839,12 +874,13 @@ class _DownloadPageViewState extends State { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.fromLTRB(24, 22, 24, 24), + padding: const EdgeInsets.fromLTRB( + GcSpace.xxl, GcSpace.xxl, GcSpace.xxl, GcSpace.xl), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox(width: 300, child: _sourcePanel()), - const SizedBox(width: 16), + SizedBox(width: 268, child: _sourcePanel()), + const SizedBox(width: GcSpace.xl), Expanded(child: _modelPanel()), ], ), @@ -853,205 +889,164 @@ class _DownloadPageViewState extends State { Widget _sourcePanel() { return GcCard( + padding: const EdgeInsets.all(GcSpace.lg), child: Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ GcSectionTitle(T('dl.sources')), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.xs + 2), + GcHint(T('dl.subtitle')), + const SizedBox(height: GcSpace.md), for (final source in _sources) Padding( - padding: const EdgeInsets.only(bottom: 6), - child: Material( - color: source.id == _selectedSourceId - ? GcColors.surfaceAlt - : Colors.transparent, - borderRadius: BorderRadius.circular(9), - child: InkWell( - borderRadius: BorderRadius.circular(9), - onTap: () => _selectSource(source.id), - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 12, vertical: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - source.name, - style: TextStyle( - fontSize: 12.5, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - if (!source.enabled) - Text( - 'off', - style: TextStyle( - fontSize: 10, color: GcColors.faint), - ), - ], - ), - const SizedBox(height: 2), - Text( - source.host, - style: TextStyle( - fontSize: 10.5, color: GcColors.faint), - ), - ], - ), - ), - ), - ), + padding: const EdgeInsets.only(bottom: GcSpace.xs + 2), + child: _sourceTile(source), + ), + const SizedBox(height: GcSpace.sm), + SizedBox( + width: double.infinity, + child: OutlinedButton.icon( + onPressed: _load, + icon: const Icon(Icons.refresh_rounded, size: 18), + label: Text(T('dl.refresh')), ), - const SizedBox(height: 10), - GcHint(T('dl.subtitle')), - const SizedBox(height: 12), - OutlinedButton.icon( - onPressed: _load, - icon: const Icon(Icons.refresh_rounded, size: 16), - label: Text(T('dl.refresh')), ), ], ), ); } + Widget _sourceTile(SourceInfo source) { + final selected = source.id == _selectedSourceId; + return Material( + color: selected ? GcColors.accentSoft : Colors.transparent, + borderRadius: BorderRadius.circular(GcRadius.control), + child: InkWell( + borderRadius: BorderRadius.circular(GcRadius.control), + hoverColor: GcColors.surfaceAlt, + onTap: () => _selectSource(source.id), + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.md, + vertical: GcSpace.md - 2, + ), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(GcRadius.control), + border: Border.all( + color: selected + ? GcColors.accent.withOpacity(0.45) + : Colors.transparent, + ), + ), + child: Row( + children: [ + Icon( + selected + ? Icons.radio_button_checked_rounded + : Icons.radio_button_unchecked_rounded, + size: 16, + color: selected ? GcColors.accent : GcColors.ghost, + ), + const SizedBox(width: GcSpace.sm + 2), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + source.name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 13, + height: 1.35, + fontWeight: FontWeight.w600, + color: selected ? GcColors.accent : GcColors.ink, + ), + ), + const SizedBox(height: 1), + Text( + source.host, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 11.5, + height: 1.35, + color: GcColors.faint, + ), + ), + ], + ), + ), + if (!source.enabled) const GcPill('off', subtle: true), + ], + ), + ), + ), + ); + } + Widget _modelPanel() { + final models = _index?.models ?? const []; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - Expanded( - child: Text( - T('dl.available'), - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - if (_index != null) - GcHint(_index!.fromCache - ? '${T('dl.ready', [_index!.models.length])} · ${T('dl.fromCache')}' - : T('dl.ready', [_index!.models.length])), - ], + GcPageHeader( + title: T('dl.available'), + subtitle: _index == null + ? null + : (_index!.fromCache + ? '${T('dl.ready', [ + models.length + ])} · ${T('dl.fromCache')}' + : T('dl.ready', [models.length])), + trailing: IconButton( + tooltip: T('common.refresh'), + onPressed: _load, + icon: const Icon(Icons.refresh_rounded, size: 18), + ), ), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.lg), Expanded( child: ListView( + padding: const EdgeInsets.only(bottom: GcSpace.sm), children: [ if (_loading) const Padding( - padding: EdgeInsets.symmetric(vertical: 40), + padding: EdgeInsets.symmetric(vertical: 48), child: Center( - child: CircularProgressIndicator(strokeWidth: 2.4)), - ) - else if (_error != null) - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(T('common.error'), - style: TextStyle(color: GcColors.danger)), - const SizedBox(height: 8), - GcHint(_error!), - ], - ), - ) - else if (_index == null || _index!.models.isEmpty) - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(T('dl.empty'), - style: TextStyle(color: GcColors.ink)), - const SizedBox(height: 8), - GcHint(T('dl.emptyHint')), - ], - ), - ) - else - for (final model in _index!.models) - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: GcCard( - padding: const EdgeInsets.all(14), - child: Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Text( - model.name, - style: TextStyle( - fontSize: 13, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - const SizedBox(width: 8), - Text( - 'v${model.version} · ${model.sizeText}', - style: TextStyle( - fontSize: 10.5, - color: GcColors.faint), - ), - if (model.installed) ...[ - const SizedBox(width: 8), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 6, vertical: 2), - decoration: BoxDecoration( - color: GcColors.ok - .withOpacity(0.16), - borderRadius: - BorderRadius.circular(5), - ), - child: Text( - T('dl.installed'), - style: TextStyle( - fontSize: 10, - color: GcColors.ok), - ), - ), - ], - ], - ), - const SizedBox(height: 4), - Text( - model.description, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 11.5, - color: GcColors.muted, - height: 1.4, - ), - ), - ], - ), - ), - const SizedBox(width: 12), - FilledButton( - onPressed: () => _download(model), - child: Text(model.installed - ? T('dl.reinstall') - : T('dl.download')), - ), - ], - ), + child: SizedBox( + width: 22, + height: 22, + child: CircularProgressIndicator(strokeWidth: 2), ), ), - const SizedBox(height: 8), + ) + else if (_error != null) + GcMessage( + title: T('common.error'), + message: _error, + icon: Icons.cloud_off_rounded, + color: GcColors.danger, + action: OutlinedButton( + onPressed: _load, + child: Text(T('common.retry')), + ), + ) + else if (models.isEmpty) + GcMessage( + title: T('dl.empty'), + message: T('dl.emptyHint'), + icon: Icons.inbox_rounded, + ) + else + for (final model in models) + Padding( + padding: const EdgeInsets.only(bottom: GcSpace.md), + child: _remoteRow(model), + ), + const SizedBox(height: GcSpace.sm), _jobsPanel(), ], ), @@ -1060,8 +1055,83 @@ class _DownloadPageViewState extends State { ); } + Widget _remoteRow(RemoteModelInfo model) { + return GcCard( + padding: const EdgeInsets.fromLTRB( + GcSpace.lg, + GcSpace.md + 2, + GcSpace.lg, + GcSpace.md + 2, + ), + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Flexible( + child: Text( + model.name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 14, + height: 1.35, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + ), + const SizedBox(width: GcSpace.sm), + Text( + 'v${model.version} · ${model.sizeText}', + style: TextStyle( + fontSize: 12, + height: 1.35, + color: GcColors.faint, + ), + ), + if (model.installed) ...[ + const SizedBox(width: GcSpace.sm), + GcPill(T('dl.installed'), color: GcColors.ok), + ], + ], + ), + const SizedBox(height: GcSpace.xs + 1), + Text( + model.description, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.5, + height: 1.5, + color: GcColors.muted, + ), + ), + ], + ), + ), + const SizedBox(width: GcSpace.lg), + if (model.installed) + OutlinedButton( + onPressed: () => _download(model), + child: Text(T('dl.reinstall')), + ) + else + FilledButton( + onPressed: () => _download(model), + child: Text(T('dl.download')), + ), + ], + ), + ); + } + Widget _jobsPanel() { return GcCard( + padding: const EdgeInsets.all(GcSpace.lg), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -1079,84 +1149,96 @@ class _DownloadPageViewState extends State { child: Text(T('dl.clearDone')), ), ), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), if (_jobs.isEmpty) GcHint(T('dl.bgEmpty')) else for (final job in _jobs) Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - '${job.name} v${job.version}', - style: TextStyle( - fontSize: 12.5, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - Text( - _stateLabel(job.state), - style: TextStyle( - fontSize: 11, - color: job.state == 'Failed' - ? GcColors.danger - : job.state == 'Completed' - ? GcColors.ok - : GcColors.faint, - ), - ), - const SizedBox(width: 8), - if (job.isActive) - TextButton( - onPressed: () => _jobAction( - widget.controller.api.cancelJob, job.id), - child: Text(T('dl.cancel')), - ) - else if (job.canRetry) - TextButton( - onPressed: () => _jobAction( - widget.controller.api.retryJob, job.id), - child: Text(T('dl.retry')), - ) - else - TextButton( - onPressed: () => _jobAction( - widget.controller.api.removeJob, job.id), - child: Text(T('dl.removeTask')), - ), - ], - ), - const SizedBox(height: 6), - LinearProgressIndicator( - value: job.progress.clamp(0, 1).toDouble(), - minHeight: 4, - ), - const SizedBox(height: 4), - Text( - job.error ?? job.detailText, - style: TextStyle( - fontSize: 10.5, color: GcColors.faint), - ), - ], - ), + padding: const EdgeInsets.only(bottom: GcSpace.md), + child: _jobRow(job), ), ], ), ); } + Widget _jobRow(JobInfo job) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text( + '${job.name} v${job.version}', + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 13, + height: 1.35, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + ), + GcPill( + _stateLabel(job.state), + color: job.state == 'Failed' + ? GcColors.danger + : job.state == 'Completed' + ? GcColors.ok + : GcColors.accent, + ), + const SizedBox(width: GcSpace.sm), + if (job.isActive) + TextButton( + onPressed: () => + _jobAction(widget.controller.api.cancelJob, job.id), + child: Text(T('dl.cancel')), + ) + else if (job.canRetry) + TextButton( + onPressed: () => + _jobAction(widget.controller.api.retryJob, job.id), + child: Text(T('dl.retry')), + ) + else + TextButton( + onPressed: () => + _jobAction(widget.controller.api.removeJob, job.id), + child: Text(T('dl.removeTask')), + ), + ], + ), + const SizedBox(height: GcSpace.sm - 2), + ClipRRect( + borderRadius: BorderRadius.circular(2), + child: LinearProgressIndicator( + value: job.progress.clamp(0, 1).toDouble(), + minHeight: 4, + backgroundColor: GcColors.surfaceAlt, + ), + ), + const SizedBox(height: GcSpace.xs + 1), + Text( + job.error ?? job.detailText, + style: TextStyle( + fontSize: 11.5, + height: 1.4, + color: GcColors.faint, + ), + ), + ], + ); + } + String _stateLabel(String state) { switch (state) { case 'Queued': return T('dl.status.queued'); case 'Running': + case 'Downloading': return T('dl.status.downloading'); case 'Completed': return T('dl.status.done'); @@ -1217,42 +1299,105 @@ class _SettingsPageViewState extends State { Widget build(BuildContext context) { final settings = widget.controller.settings; if (settings == null) { - return const Center(child: CircularProgressIndicator(strokeWidth: 2.4)); + return const Center( + child: SizedBox( + width: 22, + height: 22, + child: CircularProgressIndicator(strokeWidth: 2), + ), + ); } _syncFrom(settings); - return ListView( - padding: const EdgeInsets.fromLTRB(26, 24, 26, 28), - children: [ - Text( - T('set.title'), - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, - color: GcColors.ink, + return LayoutBuilder( + builder: (context, constraints) { + final twoColumns = constraints.maxWidth >= 960; + final cards = [ + _generalCard(settings), + _appearanceCard(settings), + _memoryCard(settings), + _sourcesCard(settings), + _storageCard(settings), + _updateCard(settings), + _backendCard(settings), + ]; + + Widget column(List items) => Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (var i = 0; i < items.length; i++) ...[ + if (i > 0) const SizedBox(height: GcSpace.lg), + items[i], + ], + ], + ); + + final left = []; + final right = []; + for (var i = 0; i < cards.length; i++) { + if (twoColumns && i.isOdd) { + right.add(cards[i]); + } else { + left.add(cards[i]); + } + } + + return SingleChildScrollView( + padding: const EdgeInsets.fromLTRB( + GcSpace.xxl, + GcSpace.xxl, + GcSpace.xxl, + GcSpace.xxxl, ), - ), - const SizedBox(height: 6), - GcHint(T('set.subtitle')), - const SizedBox(height: 18), - _generalCard(settings), - const SizedBox(height: 16), - _appearanceCard(settings), - const SizedBox(height: 16), - _memoryCard(settings), - const SizedBox(height: 16), - _sourcesCard(settings), - const SizedBox(height: 16), - _storageCard(settings), - const SizedBox(height: 16), - _updateCard(settings), - const SizedBox(height: 16), - _backendCard(settings), - if (_status != null) ...[ - const SizedBox(height: 14), - GcHint(_status!), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + GcPageHeader( + title: T('set.title'), + subtitle: T('set.subtitle'), + trailing: _status == null + ? null + : GcPill( + _status!, + color: GcColors.ok, + icon: Icons.check_rounded, + ), + ), + const SizedBox(height: GcSpace.xxl), + if (twoColumns) + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(child: column(left)), + const SizedBox(width: GcSpace.lg), + Expanded(child: column(right)), + ], + ) + else + column(cards), + ], + ), + ); + }, + ); + } + + Widget _label(String text) { + return Text( + text, + style: TextStyle(fontSize: 13, height: 1.5, color: GcColors.muted), + ); + } + + Widget _cardRow(String label, Widget control) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: GcSpace.sm), + child: Row( + children: [ + SizedBox(width: 124, child: _label(label)), + Expanded(child: control), ], - ], + ), ); } @@ -1262,15 +1407,24 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.general')), - const SizedBox(height: 14), - Row( - children: [ - SizedBox(width: 160, child: Text(T('set.language'), - style: TextStyle(fontSize: 12.5, color: GcColors.muted))), - DropdownButton( + const SizedBox(height: GcSpace.lg), + _cardRow( + T('set.language'), + Align( + alignment: Alignment.centerLeft, + child: DropdownButton( value: _language, dropdownColor: GcColors.surfaceAlt, underline: const SizedBox.shrink(), + borderRadius: BorderRadius.circular(GcRadius.control), + // 从主题样式派生,才能继承字体族(自建 TextStyle 会丢掉 + // fontFamily,中文就回退成系统兜底字体)。 + style: Theme.of(context).textTheme.bodyLarge!.copyWith( + fontSize: 13, + height: 1.4, + fontWeight: FontWeight.w400, + color: GcColors.ink, + ), items: >[ DropdownMenuItem( value: 'auto', @@ -1285,39 +1439,48 @@ class _SettingsPageViewState extends State { onChanged: (value) async { if (value == null) return; setState(() => _language = value); - await widget.controller.saveSettings( - SettingsPatch(language: value)); + await widget.controller + .saveSettings(SettingsPatch(language: value)); }, ), - ], + ), ), - const SizedBox(height: 10), - Row( - children: [ - SizedBox(width: 160, child: Text(T('set.fps'), - style: TextStyle(fontSize: 12.5, color: GcColors.muted))), - Expanded( - child: Slider( - value: _fps.toDouble(), - min: 24, - max: 120, - divisions: 4, - label: '$_fps', - onChanged: (value) => setState(() => _fps = value.round()), - onChangeEnd: (value) async { - await widget.controller - .saveSettings(SettingsPatch(renderFps: value.round())); - if (mounted) setState(() => _status = T('common.applied')); - }, + _cardRow( + T('set.fps'), + Row( + children: [ + Expanded( + child: Slider( + value: _fps.toDouble(), + min: 24, + max: 120, + divisions: 4, + label: '$_fps', + onChanged: (value) => setState(() => _fps = value.round()), + onChangeEnd: (value) async { + await widget.controller.saveSettings( + SettingsPatch(renderFps: value.round())); + if (mounted) { + setState(() => _status = T('common.applied')); + } + }, + ), ), - ), - SizedBox( - width: 46, - child: Text('$_fps', + SizedBox( + width: 48, + child: Text( + '$_fps', + textAlign: TextAlign.end, style: TextStyle( - fontSize: 12.5, color: GcColors.ink)), - ), - ], + fontSize: 13, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + ), + ], + ), ), GcHint(T('set.fps.desc')), ], @@ -1333,25 +1496,25 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.appearance')), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), GcHint(T('set.theme.desc')), - const SizedBox(height: 10), + const SizedBox(height: GcSpace.md), SegmentedButton( segments: >[ ButtonSegment( value: ThemeMode.dark, label: Text(T('set.theme.dark')), - icon: const Icon(Icons.dark_mode_outlined, size: 15), + icon: const Icon(Icons.dark_mode_outlined, size: 16), ), ButtonSegment( value: ThemeMode.light, label: Text(T('set.theme.light')), - icon: const Icon(Icons.light_mode_outlined, size: 15), + icon: const Icon(Icons.light_mode_outlined, size: 16), ), ButtonSegment( value: ThemeMode.system, label: Text(T('set.theme.system')), - icon: const Icon(Icons.brightness_auto_outlined, size: 15), + icon: const Icon(Icons.brightness_auto_outlined, size: 16), ), ], selected: {_themeMode}, @@ -1360,27 +1523,31 @@ class _SettingsPageViewState extends State { final mode = selection.first; setState(() => _themeMode = mode); GcPalette.mode.value = mode; // 立即预览 - await widget.controller - .saveSettings(SettingsPatch(theme: GcPalette.modeToName(mode))); + await widget.controller.saveSettings( + SettingsPatch(theme: GcPalette.modeToName(mode))); if (mounted) setState(() => _status = T('common.applied')); }, ), - const SizedBox(height: 16), + const SizedBox(height: GcSpace.xl), GcHint(T('set.accent.desc')), - const SizedBox(height: 14), + const SizedBox(height: GcSpace.md + 2), Wrap( - spacing: 10, - runSpacing: 10, + spacing: GcSpace.sm + 2, + runSpacing: GcSpace.sm + 2, children: [ for (final color in GcPalette.presets) _accentSwatch(color, current), _customAccentChip(), ], ), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.md), Text( '${T('set.accent')}: ${GcPalette.toHex(current)}', - style: TextStyle(fontSize: 11.5, color: GcColors.faint), + style: TextStyle( + fontSize: 11.5, + height: 1.4, + color: GcColors.faint, + ), ), ], ), @@ -1388,32 +1555,30 @@ class _SettingsPageViewState extends State { } Widget _accentSwatch(Color color, Color current) { - // ignore: deprecated_member_use final selected = color.value == current.value; return Tooltip( message: GcPalette.toHex(color), child: GestureDetector( onTap: () => _applyAccent(GcPalette.toHex(color)), child: Container( - width: 36, - height: 36, + width: 34, + height: 34, decoration: BoxDecoration( color: color, - borderRadius: BorderRadius.circular(10), + borderRadius: BorderRadius.circular(GcRadius.control), border: Border.all( - color: selected ? Colors.white : Colors.transparent, + color: selected ? GcColors.ink : Colors.transparent, width: 2, ), - boxShadow: [ - BoxShadow( - color: color.withOpacity(selected ? 0.55 : 0.18), - blurRadius: selected ? 14 : 6, - ), - ], ), child: selected - ? const Icon(Icons.check_rounded, - size: 19, color: Color(0xFF08101F)) + ? Icon( + Icons.check_rounded, + size: 18, + color: color.computeLuminance() > 0.42 + ? const Color(0xFF0A1226) + : Colors.white, + ) : null, ), ), @@ -1426,22 +1591,25 @@ class _SettingsPageViewState extends State { child: GestureDetector( onTap: _pickCustomAccent, child: Container( - height: 36, - padding: const EdgeInsets.symmetric(horizontal: 12), + height: 34, + padding: const EdgeInsets.symmetric(horizontal: GcSpace.md), decoration: BoxDecoration( color: GcColors.surfaceAlt, - borderRadius: BorderRadius.circular(10), + borderRadius: BorderRadius.circular(GcRadius.control), border: Border.all(color: GcColors.line), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ - Icon(Icons.colorize_rounded, - size: 16, color: GcColors.faint), - const SizedBox(width: 6), + Icon(Icons.colorize_rounded, size: 16, color: GcColors.faint), + const SizedBox(width: GcSpace.xs + 2), Text( T('set.accent.custom'), - style: TextStyle(fontSize: 11.5, color: GcColors.muted), + style: TextStyle( + fontSize: 12, + height: 1.3, + color: GcColors.muted, + ), ), ], ), @@ -1457,17 +1625,15 @@ class _SettingsPageViewState extends State { final hex = await showDialog( context: context, builder: (context) => AlertDialog( - backgroundColor: GcColors.surfaceAlt, + backgroundColor: GcColors.surface, title: Text(T('set.accent.custom')), content: TextField( controller: controller, autofocus: true, - style: TextStyle(color: GcColors.ink), + style: Theme.of(context).textTheme.bodyLarge!.copyWith(fontSize: 13), decoration: InputDecoration( hintText: '#8FB6FF', - hintStyle: TextStyle(color: GcColors.faint), helperText: T('set.accent.hexHint'), - helperStyle: TextStyle(color: GcColors.faint, fontSize: 11), ), onSubmitted: (value) => Navigator.of(context).pop(value), ), @@ -1506,9 +1672,9 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.memory')), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), GcHint(T('set.memory.desc')), - const SizedBox(height: 14), + const SizedBox(height: GcSpace.lg), Row( children: [ Switch( @@ -1519,16 +1685,20 @@ class _SettingsPageViewState extends State { .saveSettings(SettingsPatch(memoryAuto: value)); }, ), - const SizedBox(width: 10), + const SizedBox(width: GcSpace.md), Expanded( child: Text( T('set.memory.auto'), - style: TextStyle(fontSize: 12.5, color: GcColors.muted), + style: TextStyle( + fontSize: 13, + height: 1.5, + color: GcColors.muted, + ), ), ), ], ), - const SizedBox(height: 6), + const SizedBox(height: GcSpace.xs), Row( children: [ Expanded( @@ -1542,31 +1712,30 @@ class _SettingsPageViewState extends State { ? null : (value) => setState(() => _memory = value), onChangeEnd: (value) async { - await widget.controller.saveSettings( - SettingsPatch(memoryMb: value.round())); + await widget.controller + .saveSettings(SettingsPatch(memoryMb: value.round())); if (mounted) setState(() => _status = T('common.applied')); }, ), ), SizedBox( - width: 96, + width: 104, child: Text( '${_memory.round()} MB', - style: TextStyle(fontSize: 12.5, color: GcColors.ink), + textAlign: TextAlign.end, + style: TextStyle( + fontSize: 13, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), ), ), ], ), - const SizedBox(height: 6), - Row( - children: [ - Text( - '${T('set.memory.current')}: ${settings.memoryUsageText}', - style: TextStyle(fontSize: 11.5, color: GcColors.faint), - ), - ], - ), - const SizedBox(height: 6), + const SizedBox(height: GcSpace.xs), + GcHint('${T('set.memory.current')}: ${settings.memoryUsageText}'), + const SizedBox(height: GcSpace.xs), GcHint(T('set.memory.hint')), ], ), @@ -1579,39 +1748,47 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.sources')), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), GcHint(T('set.sources.desc')), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.md), for (final source in settings.sources) Padding( - padding: const EdgeInsets.only(bottom: 8), + padding: const EdgeInsets.only(bottom: GcSpace.md), child: Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ Text( source.name, style: TextStyle( - fontSize: 12.5, + fontSize: 13, + height: 1.4, fontWeight: FontWeight.w600, color: GcColors.ink, ), ), - const SizedBox(height: 2), + const SizedBox(height: 1), Text( source.url, + maxLines: 1, + overflow: TextOverflow.ellipsis, style: TextStyle( - fontSize: 10.5, color: GcColors.faint), + fontSize: 11.5, + height: 1.4, + color: GcColors.faint, + ), ), ], ), ), - Text( - source.enabled ? T('set.sourceEnabled') : '—', - style: TextStyle(fontSize: 11, color: GcColors.faint), - ), + const SizedBox(width: GcSpace.sm), + if (source.enabled) + GcPill(T('set.sourceEnabled'), color: GcColors.ok) + else + const GcPill('—', subtle: true), ], ), ), @@ -1626,13 +1803,23 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.storage')), - const SizedBox(height: 12), - _pathRow(T('set.modelDir'), settings.modelRoot), - const SizedBox(height: 8), - _pathRow(T('set.dataDir'), settings.dataRoot), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.md), + GcFieldRow( + label: T('set.modelDir'), + value: settings.modelRoot, + selectable: true, + valueColor: GcColors.muted, + ), + GcFieldRow( + label: T('set.dataDir'), + value: settings.dataRoot, + selectable: true, + valueColor: GcColors.muted, + ), + const SizedBox(height: GcSpace.md), Wrap( - spacing: 10, + spacing: GcSpace.sm + 2, + runSpacing: GcSpace.sm + 2, children: [ OutlinedButton( onPressed: () async { @@ -1658,34 +1845,15 @@ class _SettingsPageViewState extends State { ); } - Widget _pathRow(String label, String value) { - return Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 160, - child: Text(label, - style: TextStyle(fontSize: 12.5, color: GcColors.muted)), - ), - Expanded( - child: SelectableText( - value, - style: TextStyle(fontSize: 11.5, color: GcColors.faint), - ), - ), - ], - ); - } - Widget _updateCard(SettingsInfo settings) { return GcCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('update.title')), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), GcHint(T('set.checkUpdate.desc')), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.md), Row( children: [ Switch( @@ -1696,18 +1864,27 @@ class _SettingsPageViewState extends State { .saveSettings(SettingsPatch(autoUpdateOnStartup: value)); }, ), - const SizedBox(width: 10), + const SizedBox(width: GcSpace.md), Expanded( child: Text( T('update.auto'), - style: TextStyle(fontSize: 12.5, color: GcColors.muted), + style: TextStyle( + fontSize: 13, + height: 1.5, + color: GcColors.muted, + ), ), ), ], ), - const SizedBox(height: 8), - _pathRow(T('update.source'), settings.updateRepository), - const SizedBox(height: 12), + const SizedBox(height: GcSpace.sm), + GcFieldRow( + label: T('update.source'), + value: settings.updateRepository, + selectable: true, + valueColor: GcColors.muted, + ), + const SizedBox(height: GcSpace.md), FilledButton( onPressed: () => widget.controller.checkUpdate(force: true), child: Text(T('update.checkNow')), @@ -1724,22 +1901,37 @@ class _SettingsPageViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle(T('set.backend')), - const SizedBox(height: 8), + const SizedBox(height: GcSpace.md), GcHint(T('set.backend.desc')), - const SizedBox(height: 12), - _pathRow('API', widget.controller.api.baseUrl), - const SizedBox(height: 8), - _pathRow(T('set.version'), settings.version), - const SizedBox(height: 8), - _pathRow(T('set.platform'), settings.platform), - const SizedBox(height: 8), - _pathRow( - T('set.backend.ui'), - health == null + const SizedBox(height: GcSpace.md), + GcFieldRow( + label: 'API', + value: widget.controller.api.baseUrl, + selectable: true, + valueColor: GcColors.muted, + ), + GcFieldRow( + label: T('set.version'), + value: settings.version, + valueColor: GcColors.muted, + ), + GcFieldRow( + label: T('set.platform'), + value: settings.platform, + valueColor: GcColors.muted, + ), + GcFieldRow( + label: T('set.backend.ui'), + value: health == null ? '—' : health.uiAvailable ? T('set.backend.uiOk') : '${T('set.backend.uiBad')}${health.uiError == null ? '' : ' · ${health.uiError}'}', + valueColor: health == null + ? GcColors.muted + : health.uiAvailable + ? GcColors.ok + : GcColors.danger, ), ], ), @@ -1804,156 +1996,258 @@ class _AboutPageViewState extends State { @override Widget build(BuildContext context) { return ListView( - padding: const EdgeInsets.fromLTRB(26, 24, 26, 28), + padding: const EdgeInsets.fromLTRB( + GcSpace.xxl, + GcSpace.xxl, + GcSpace.xxl, + GcSpace.xxxl, + ), children: [ - Text( - T('nav.about'), - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, - color: GcColors.ink, - ), + GcPageHeader( + title: T('nav.about'), + subtitle: T('app.tagline'), ), - const SizedBox(height: 18), + const SizedBox(height: GcSpace.xxl), if (_loading) const Padding( - padding: EdgeInsets.symmetric(vertical: 40), - child: Center(child: CircularProgressIndicator(strokeWidth: 2.4)), + padding: EdgeInsets.symmetric(vertical: 48), + child: Center( + child: SizedBox( + width: 22, + height: 22, + child: CircularProgressIndicator(strokeWidth: 2), + ), + ), ) else if (_error != null) - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(T('common.error'), - style: TextStyle(color: GcColors.danger)), - const SizedBox(height: 8), - GcHint(_error!), - const SizedBox(height: 12), - OutlinedButton( - onPressed: _load, - child: Text(T('common.retry')), - ), - ], + GcMessage( + title: T('common.error'), + message: _error, + icon: Icons.error_outline_rounded, + color: GcColors.danger, + action: OutlinedButton( + onPressed: _load, + child: Text(T('common.retry')), ), ) else ...[ - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - _about?.appName ?? 'Morris GC', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w700, - color: GcColors.ink, - ), - ), - const SizedBox(height: 6), - GcHint(T('app.tagline')), - const SizedBox(height: 14), - _row(T('set.version'), 'v${_about?.version ?? '—'}'), - const SizedBox(height: 8), - _row(T('set.platform'), _about?.platform ?? '—'), - const SizedBox(height: 8), - _row(T('about.architecture'), T('about.architectureValue')), - const SizedBox(height: 8), - _row(T('about.sourceLanguage'), _about?.sourceLanguage ?? 'C#'), - const SizedBox(height: 8), - _row(T('about.frontend'), _about?.frontend ?? 'Flutter'), - const SizedBox(height: 8), - _row(T('set.license'), T('set.licenseValue')), - const SizedBox(height: 14), - OutlinedButton( - onPressed: () async { - final url = _about?.repository; - if (url == null || url.isEmpty) return; - try { - await widget.controller.api.openUrl(url); - } catch (_) { - // 忽略 - } - }, - child: Text(T('about.openRepository')), - ), - ], - ), - ), - const SizedBox(height: 16), - GcCard( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - GcSectionTitle( - T('about.developers'), - trailing: GcHint(T('about.contributorsHint')), - ), - const SizedBox(height: 12), - if ((_about?.contributors ?? const []).isEmpty) - GcHint(T('about.noContributors')) - else - for (final contributor in _about!.contributors) - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Row( - children: [ - CircleAvatar( - radius: 16, - backgroundColor: GcColors.surfaceAlt, - backgroundImage: contributor.avatarUrl == null - ? null - : NetworkImage(contributor.avatarUrl!), - child: contributor.avatarUrl == null - ? Text('◎', - style: TextStyle( - fontSize: 12, color: GcColors.accent)) - : null, - ), - const SizedBox(width: 12), - Expanded( - child: Text( - contributor.name, - style: TextStyle( - fontSize: 12.5, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - Text( - T('about.contributions', - [contributor.contributions]), - style: TextStyle( - fontSize: 11, color: GcColors.faint), - ), - ], - ), - ), - ], - ), - ), + _versionCard(), + const SizedBox(height: GcSpace.lg), + _contributorsCard(), ], ], ); } - Widget _row(String label, String value) { - return Row( + Widget _versionCard() { + final about = _about; + + // 左边身份卡、右边信息表:宽屏两栏,窄屏自动堆叠。 + final identity = Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ - SizedBox( - width: 160, - child: Text(label, - style: TextStyle(fontSize: 12.5, color: GcColors.muted)), + Row( + children: [ + Container( + width: 44, + height: 44, + alignment: Alignment.center, + decoration: BoxDecoration( + color: GcColors.accentSoft, + borderRadius: BorderRadius.circular(GcRadius.card), + ), + child: Text( + '◎', + style: TextStyle( + fontSize: 22, height: 1.1, color: GcColors.accent), + ), + ), + const SizedBox(width: GcSpace.lg), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + about?.appName ?? 'Morris GC', + style: TextStyle( + fontSize: 20, + height: 1.3, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + const SizedBox(height: 2), + Text( + T('app.tagline'), + style: TextStyle( + fontSize: 12.5, + height: 1.5, + color: GcColors.faint, + ), + ), + ], + ), + ), + ], ), - Expanded( - child: SelectableText( - value, - style: TextStyle(fontSize: 12, color: GcColors.ink), - ), + const SizedBox(height: GcSpace.lg), + Wrap( + spacing: GcSpace.sm, + runSpacing: GcSpace.sm, + children: [ + GcPill('v${about?.version ?? '—'}', color: GcColors.accent), + ], + ), + const SizedBox(height: GcSpace.lg), + OutlinedButton( + onPressed: () async { + final url = about?.repository; + if (url == null || url.isEmpty) return; + try { + await widget.controller.api.openUrl(url); + } catch (_) { + // 忽略 + } + }, + child: Text(T('about.openRepository')), ), ], ); + + final details = Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.min, + children: [ + GcFieldRow( + label: T('set.platform'), + value: about?.platform ?? '—', + ), + GcFieldRow( + label: T('about.architecture'), + value: T('about.architectureValue'), + ), + GcFieldRow( + label: T('about.sourceLanguage'), + value: about?.sourceLanguage ?? 'C#', + ), + GcFieldRow( + label: T('about.frontend'), + value: about?.frontend ?? 'Flutter', + ), + GcFieldRow( + label: T('set.license'), + value: T('set.licenseValue'), + ), + ], + ); + + return GcCard( + padding: const EdgeInsets.all(GcSpace.xxl), + child: LayoutBuilder( + builder: (context, constraints) { + if (constraints.maxWidth < 720) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + identity, + const GcDivider(verticalPadding: GcSpace.lg), + details, + ], + ); + } + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(flex: 4, child: identity), + const SizedBox(width: GcSpace.xxxl), + Expanded(flex: 5, child: details), + ], + ); + }, + ), + ); + } + + Widget _contributorsCard() { + final contributors = _about?.contributors ?? const []; + return GcCard( + padding: const EdgeInsets.all(GcSpace.xxl), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GcSectionTitle( + T('about.developers'), + subtitle: T('about.contributorsHint'), + ), + const SizedBox(height: GcSpace.lg), + if (contributors.isEmpty) + GcHint(T('about.noContributors')) + else + Wrap( + spacing: GcSpace.xl, + runSpacing: GcSpace.md, + children: [ + for (final contributor in contributors) + SizedBox( + width: 220, + child: Row( + children: [ + CircleAvatar( + radius: 18, + backgroundColor: GcColors.surfaceAlt, + backgroundImage: contributor.avatarUrl == null + ? null + : NetworkImage(contributor.avatarUrl!), + child: contributor.avatarUrl == null + ? Text( + '◎', + style: TextStyle( + fontSize: 14, + color: GcColors.accent, + ), + ) + : null, + ), + const SizedBox(width: GcSpace.md), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + contributor.name, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 13, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + Text( + T( + 'about.contributions', + [contributor.contributions], + ), + style: TextStyle( + fontSize: 11.5, + height: 1.4, + color: GcColors.faint, + ), + ), + ], + ), + ), + ], + ), + ), + ], + ), + ], + ), + ); } } diff --git a/GC-UI/frontend/lib/shell.dart b/GC-UI/frontend/lib/shell.dart index eabb431..cc14a59 100644 --- a/GC-UI/frontend/lib/shell.dart +++ b/GC-UI/frontend/lib/shell.dart @@ -14,12 +14,31 @@ class _NavItem { } const List<_NavItem> _navItems = <_NavItem>[ - _NavItem(Icons.grid_view_rounded, 'nav.home'), + _NavItem(Icons.dashboard_rounded, 'nav.home'), _NavItem(Icons.download_rounded, 'nav.download'), _NavItem(Icons.tune_rounded, 'nav.settings'), _NavItem(Icons.info_outline_rounded, 'nav.about'), ]; +/// 桌面端滚动行为:去掉移动端的拉伸回弹和边缘光晕,滚轮更跟手。 +class GcScrollBehavior extends MaterialScrollBehavior { + const GcScrollBehavior(); + + @override + Widget buildOverscrollIndicator( + BuildContext context, + Widget child, + ScrollableDetails details, + ) { + return child; + } + + @override + ScrollPhysics getScrollPhysics(BuildContext context) { + return const ClampingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + } +} + /// 应用外壳:左侧导航 + 右侧内容 + 底部更新状态条。 class ShellPage extends StatefulWidget { const ShellPage({super.key, required this.controller}); @@ -52,6 +71,7 @@ class _ShellPageState extends State { body: Row( children: [ _Sidebar(controller: controller), + Container(width: 1, color: GcColors.line), Expanded( child: Column( children: [ @@ -75,9 +95,9 @@ class _ShellPageState extends State { } return const Center( child: SizedBox( - width: 26, - height: 26, - child: CircularProgressIndicator(strokeWidth: 2.4), + width: 22, + height: 22, + child: CircularProgressIndicator(strokeWidth: 2), ), ); } @@ -124,52 +144,25 @@ class _Sidebar extends StatelessWidget { Widget build(BuildContext context) { final settings = controller.settings; return Container( - width: 236, + width: GcSize.sidebar, color: GcColors.sideBg, - padding: const EdgeInsets.fromLTRB(16, 20, 16, 18), + padding: const EdgeInsets.fromLTRB( + GcSpace.xl, GcSpace.xxl, GcSpace.lg, GcSpace.lg), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - Container( - width: 26, - height: 26, - decoration: BoxDecoration( - color: GcColors.surfaceAlt, - borderRadius: BorderRadius.circular(8), - ), - alignment: Alignment.center, - child: Text( - '◎', - style: TextStyle(fontSize: 14, color: GcColors.accent), - ), - ), - const SizedBox(width: 10), - Expanded( - child: Text( - 'Morris GC', - style: TextStyle( - fontSize: 13, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), - ), - ), - ], - ), - const SizedBox(height: 6), - GcHint(T('app.tagline')), - const SizedBox(height: 26), + _brand(), + const SizedBox(height: GcSpace.xxxl), const Padding( - padding: EdgeInsets.only(left: 14, bottom: 6), + padding: EdgeInsets.only(left: 10, bottom: GcSpace.sm), child: Text( 'MENU', style: TextStyle( - fontSize: 9.5, - letterSpacing: 1.2, + fontSize: 11, + height: 1.2, + letterSpacing: 1.4, fontWeight: FontWeight.w600, - color: Color(0xFF4C5F80), + color: Color(0xFF5C6A80), ), ), ), @@ -181,25 +174,91 @@ class _Sidebar extends StatelessWidget { ), const Spacer(), Container(height: 1, color: GcColors.line), - const SizedBox(height: 10), + const SizedBox(height: GcSpace.md), Padding( - padding: const EdgeInsets.only(left: 14), - child: Text( - 'v${settings?.version ?? '—'}', - style: TextStyle(fontSize: 10.5, color: GcColors.faint), - ), - ), - Padding( - padding: const EdgeInsets.only(left: 14, top: 2), - child: Text( - settings?.platform ?? '—', - style: const TextStyle(fontSize: 10, color: Color(0xFF4F6080)), + padding: const EdgeInsets.only(left: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'v${settings?.version ?? '—'}', + style: TextStyle( + fontSize: 12, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.muted, + ), + ), + const SizedBox(height: 2), + Text( + settings?.platform ?? '—', + style: TextStyle( + fontSize: 11.5, + height: 1.4, + color: GcColors.ghost, + ), + ), + ], ), ), ], ), ); } + + /// 品牌区:一个渐变圆角标 + 名称 + 一句定位。 + Widget _brand() { + return Row( + children: [ + Container( + width: 32, + height: 32, + alignment: Alignment.center, + decoration: BoxDecoration( + color: GcColors.accentSoft, + borderRadius: BorderRadius.circular(9), + border: Border.all( + color: Color.alphaBlend( + GcColors.accent.withOpacity(0.35), GcColors.sideBg), + ), + ), + child: Text( + '◎', + style: TextStyle(fontSize: 16, height: 1.1, color: GcColors.accent), + ), + ), + const SizedBox(width: GcSpace.md), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Morris GC', + style: TextStyle( + fontSize: 14, + height: 1.3, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + const SizedBox(height: 1), + Text( + 'SCIENCE · CLASSROOM', + style: TextStyle( + fontSize: 10, + height: 1.3, + letterSpacing: 0.9, + fontWeight: FontWeight.w600, + color: GcColors.ghost, + ), + ), + ], + ), + ), + ], + ); + } } class _NavButton extends StatelessWidget { @@ -216,29 +275,34 @@ class _NavButton extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only(bottom: 4), + padding: const EdgeInsets.only(bottom: GcSpace.xs), child: Material( - color: active ? GcColors.surfaceAlt : Colors.transparent, - borderRadius: BorderRadius.circular(9), + color: active ? GcColors.accentSoft : Colors.transparent, + borderRadius: BorderRadius.circular(GcRadius.control), child: InkWell( - borderRadius: BorderRadius.circular(9), + borderRadius: BorderRadius.circular(GcRadius.control), onTap: onTap, + hoverColor: GcColors.surfaceHover, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.md, + vertical: 11, + ), child: Row( children: [ Icon( item.icon, - size: 16, + size: 17, color: active ? GcColors.accent : GcColors.faint, ), - const SizedBox(width: 10), + const SizedBox(width: GcSpace.md), Text( T(item.labelKey), style: TextStyle( - fontSize: 12.5, + fontSize: 13.5, + height: 1.2, fontWeight: active ? FontWeight.w600 : FontWeight.w400, - color: active ? GcColors.ink : GcColors.muted, + color: active ? GcColors.accent : GcColors.muted, ), ), ], @@ -262,20 +326,28 @@ class _UpdateBar extends StatelessWidget { color: GcColors.surface, border: Border(top: BorderSide(color: GcColors.line)), ), - padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 9), + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.xxl, + vertical: GcSpace.md, + ), child: Row( children: [ - Text('⟳', - style: TextStyle(fontSize: 16, color: GcColors.accent)), - const SizedBox(width: 12), + Icon( + Icons.sync_rounded, + size: 18, + color: GcColors.accent, + ), + const SizedBox(width: GcSpace.md), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ Text( controller.updateStatus, style: TextStyle( - fontSize: 12.5, + fontSize: 13, + height: 1.35, fontWeight: FontWeight.w600, color: GcColors.ink, ), @@ -284,23 +356,41 @@ class _UpdateBar extends StatelessWidget { if (controller.updateDetail.isNotEmpty) Text( controller.updateDetail, - style: TextStyle(fontSize: 11, color: GcColors.faint), + style: TextStyle( + fontSize: 12, + height: 1.4, + color: GcColors.faint, + ), overflow: TextOverflow.ellipsis, ), if (controller.launcherNotice.isNotEmpty) Text( controller.launcherNotice, - style: TextStyle(fontSize: 11, color: GcColors.warn), + style: TextStyle( + fontSize: 12, + height: 1.4, + color: GcColors.warn, + ), ), ], ), ), - if (controller.updateBusy) - const SizedBox( - width: 130, - child: LinearProgressIndicator(minHeight: 4), + if (controller.updateBusy) ...[ + const SizedBox(width: GcSpace.lg), + SizedBox( + width: 140, + child: ClipRRect( + borderRadius: BorderRadius.circular(3), + child: LinearProgressIndicator( + value: controller.updateProgress > 0 + ? controller.updateProgress.clamp(0, 1).toDouble() + : null, + minHeight: 4, + ), + ), ), - const SizedBox(width: 14), + ], + const SizedBox(width: GcSpace.lg), TextButton( onPressed: controller.updateBusy ? null @@ -324,24 +414,32 @@ class _BackendDown extends StatelessWidget { child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 520), child: GcCard( - padding: const EdgeInsets.all(28), + padding: const EdgeInsets.all(GcSpace.xxl), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - T('common.error'), - style: TextStyle( - fontSize: 17, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), + Row( + children: [ + Icon(Icons.error_outline_rounded, + size: 20, color: GcColors.danger), + const SizedBox(width: GcSpace.sm), + Text( + T('common.error'), + style: TextStyle( + fontSize: 16, + height: 1.35, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + ], ), - const SizedBox(height: 10), + const SizedBox(height: GcSpace.md), GcHint(controller.loadError ?? ''), - const SizedBox(height: 6), - GcHint('后端地址:${controller.api.baseUrl}'), - const SizedBox(height: 16), + const SizedBox(height: GcSpace.xs), + GcHint('${T('set.backend')}: ${controller.api.baseUrl}'), + const SizedBox(height: GcSpace.lg), FilledButton( onPressed: controller.bootstrap, child: Text(T('common.retry')), diff --git a/GC-UI/frontend/lib/theme.dart b/GC-UI/frontend/lib/theme.dart index 1033bea..f7239d1 100644 --- a/GC-UI/frontend/lib/theme.dart +++ b/GC-UI/frontend/lib/theme.dart @@ -1,9 +1,91 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -/// 主题偏好(可在设置页切换,并持久化到后端 settings.theme)。 +// --------------------------------------------------------------------------- +// 设计令牌 +// --------------------------------------------------------------------------- + +/// 间距 / 圆角:全应用统一取值,避免各处 13.5、17 之类的散数。 +class GcSpace { + GcSpace._(); + + static const double xs = 4; + static const double sm = 8; + static const double md = 12; + static const double lg = 16; + static const double xl = 20; + static const double xxl = 24; + static const double xxxl = 32; +} + +/// 圆角。 +class GcRadius { + GcRadius._(); + + static const double control = 8; + static const double card = 12; + static const double panel = 16; + static const double pill = 999; +} + +/// 尺寸:侧栏 / 控件高度。 +class GcSize { + GcSize._(); + + static const double sidebar = 248; + static const double control = 40; + static const double controlSmall = 32; +} + +/// 字体。 /// -/// 支持深色 / 浅色 / 跟随系统三种;[mode] 变化会让 `main.dart` 重建 -/// `MaterialApp`,`themeMode` 交给 Flutter 决定实际亮度。 +/// 中文界面「发糊」的一大来源是字体回退到了很细的旧字体:Windows 上 +/// Segoe UI 没有中文字形,缺字时由系统回退,字号一小就糊成一片。 +/// 这里显式指定「拉丁用系统 UI 字体 + 中文用雅黑 / 苹方」,并把行高 +/// 钉死,避免不同平台的默认行高把中文挤在一起。 +class GcFonts { + GcFonts._(); + + /// 拉丁字形字体。macOS 留空,走系统默认(苹方),不要写死字体名。 + static String? get family { + if (kIsWeb) return null; + switch (defaultTargetPlatform) { + case TargetPlatform.windows: + return 'Segoe UI'; + case TargetPlatform.linux: + return 'Noto Sans'; + default: + return null; + } + } + + /// 中文字形回退顺序:先细体、再常规体,最后才是旧版回退。 + static List get fallback { + if (kIsWeb) return const ['Noto Sans CJK SC', 'sans-serif']; + switch (defaultTargetPlatform) { + case TargetPlatform.windows: + return const [ + 'Microsoft YaHei UI', + 'Microsoft YaHei', + 'SimHei' + ]; + case TargetPlatform.linux: + return const [ + 'Noto Sans CJK SC', + 'Noto Sans SC', + 'WenQuanYi Micro Hei' + ]; + default: + return const [ + 'PingFang SC', + 'Hiragino Sans GB', + 'Noto Sans CJK SC' + ]; + } + } +} + +/// 主题偏好(可在设置页切换,并持久化到后端 settings.theme)。 class GcPalette { GcPalette._(); @@ -14,7 +96,8 @@ class GcPalette { ValueNotifier(defaultAccent); /// 当前主题模式(dark / light / system)。 - static final ValueNotifier mode = ValueNotifier(ThemeMode.dark); + static final ValueNotifier mode = + ValueNotifier(ThemeMode.dark); /// 设置页可选的预设色板。 static const List presets = [ @@ -89,8 +172,9 @@ class GcPalette { /// 配色:浅色 / 深色两套,按当前 [Brightness] 取值。 /// -/// 以前这里是 const 常量,主题只能是深色 —— 设置里的 `theme` 字段写了也没人读。 -/// 改成 getter 后,所有引用点自动跟随主题;代价是不能再放进 const 上下文。 +/// 深色不再用「深蓝底 + 半透明白」,而是中性石墨底 + 高对比正文: +/// 半透明叠加会让中文笔画边缘出现灰边,看着就是「糊」。这里所有文字 +/// 颜色都是不透明的实色。 class GcColors { GcColors._(); @@ -99,48 +183,79 @@ class GcColors { static bool get isDark => _dark; /// 由 `MaterialApp.builder` 在每次构建前按实际亮度绑定。 - static void bind(Brightness brightness) => _dark = brightness == Brightness.dark; + static void bind(Brightness brightness) => + _dark = brightness == Brightness.dark; static Color _pick(int dark, int light) => Color(_dark ? dark : light); - static Color get appBg => _pick(0xFF0A1226, 0xFFF3F6FB); - static Color get sideBg => _pick(0xFF0C1529, 0xFFFFFFFF); - static Color get surface => _pick(0xFF111C33, 0xFFFFFFFF); - static Color get surfaceAlt => _pick(0xFF16233C, 0xFFE9EFFA); - static Color get line => _pick(0xFF1B2740, 0xFFD8E2F2); - static Color get ink => _pick(0xFFF2F6FF, 0xFF0F1B2D); - static Color get muted => _pick(0xFFA9B8D4, 0xFF46587A); - static Color get faint => _pick(0xFF7C90B4, 0xFF7286A6); - static Color get warn => _pick(0xFFFFC46B, 0xFFB26A00); - static Color get danger => _pick(0xFFFF7A7A, 0xFFC0392B); - static Color get ok => _pick(0xFF6BE3A2, 0xFF1E8E5A); + // ---- 底与面 ---- + static Color get appBg => _pick(0xFF080B12, 0xFFF3F6FB); + static Color get sideBg => _pick(0xFF0C1119, 0xFFFFFFFF); + static Color get surface => _pick(0xFF131B28, 0xFFFFFFFF); + static Color get surfaceAlt => _pick(0xFF1A2434, 0xFFEDF2F9); + static Color get surfaceHover => _pick(0xFF202B3D, 0xFFE2EAF5); - /// 侧栏「MENU」一类最弱的说明文字。 - static Color get ghost => _pick(0xFF4C5F80, 0xFF97A8C4); + // ---- 描边 ---- + static Color get line => _pick(0xFF243044, 0xFFDEE6F1); + static Color get lineStrong => _pick(0xFF33425A, 0xFFC4D1E3); + + // ---- 文字 ---- + static Color get ink => _pick(0xFFEAF0FA, 0xFF0E1522); + static Color get muted => _pick(0xFFA7B4C8, 0xFF48566B); + static Color get faint => _pick(0xFF7E8CA3, 0xFF69788E); + static Color get ghost => _pick(0xFF5C6A80, 0xFF94A2B6); + + // ---- 状态 ---- + static Color get warn => _pick(0xFFF2C57C, 0xFF9A5B00); + static Color get danger => _pick(0xFFF08A8A, 0xFFB3261E); + static Color get ok => _pick(0xFF74DFA8, 0xFF12714A); /// 当前强调色(动态,跟随设置)。 static Color get accent => GcPalette.accent.value; - /// 强调色的加深版本,用于主按钮 / 轨道。浅色主题下需要反向调整, - /// 否则强调色在浅背景上对比度不足。 - static Color get accentStrong => _strongen(accent); + /// 主按钮填充色:深色主题直接用强调色(浅底深字最清晰), + /// 浅色主题把强调色压深,避免白底上「浅蓝底 + 白字」看不清。 + static Color get accentFill => _dark ? accent : _darken(accent, 0.18); - static Color _strongen(Color color) { + /// 强调色上的文字 / 图标颜色,按对比度自动取深色或白色。 + static Color get onAccent { + final fill = accentFill; + // 阈值 0.42:粉紫色(低亮度)走白字,天蓝 / 薄荷(高亮度)走深字。 + return fill.computeLuminance() > 0.42 + ? const Color(0xFF0A1226) + : Colors.white; + } + + /// 强调色的淡底(选中项 / 标签背景)。用不透明混色,不用 withOpacity: + /// 半透明色叠在卡片上会让下层的圆角描边透出来,边缘发脏。 + static Color get accentSoft => + Color.lerp(surface, accent, _dark ? 0.16 : 0.12)!; + + static Color _darken(Color color, double amount) { final hsl = HSLColor.fromColor(color); - final lightness = _dark ? hsl.lightness - 0.10 : hsl.lightness - 0.22; return hsl - .withSaturation((hsl.saturation + 0.12).clamp(0.0, 1.0)) - .withLightness(lightness.clamp(0.0, 1.0)) + .withSaturation((hsl.saturation + amount * 0.35).clamp(0.0, 1.0)) + .withLightness((hsl.lightness - amount).clamp(0.0, 1.0)) .toColor(); } } /// 按指定亮度构建主题。 /// +/// [fontFamily] / [fontFamilyFallback] 默认取 [GcFonts] 的平台字体栈; +/// 截图 / 自动化测试需要换成自己加载的字体时,从这里传,才能连按钮、 +/// 输入框这些「主题内嵌样式」一起换掉。 +/// /// 注意:不要在这里改 [GcColors] 的全局状态 —— MaterialApp 会同时构建 /// theme 与 darkTheme,后构建的那个会把状态写脏。亮度绑定由 `main.dart` /// 的 builder 统一完成。 -ThemeData buildGcTheme(Brightness brightness) { +ThemeData buildGcTheme( + Brightness brightness, { + String? fontFamily, + List? fontFamilyFallback, +}) { + final family = fontFamily ?? GcFonts.family; + final fallback = fontFamilyFallback ?? GcFonts.fallback; final isDark = brightness == Brightness.dark; final base = isDark ? ThemeData.dark(useMaterial3: true) @@ -148,109 +263,458 @@ ThemeData buildGcTheme(Brightness brightness) { Color pick(int dark, int light) => Color(isDark ? dark : light); - final appBg = pick(0xFF0A1226, 0xFFF3F6FB); - final surface = pick(0xFF111C33, 0xFFFFFFFF); - final surfaceAlt = pick(0xFF16233C, 0xFFE9EFFA); - final line = pick(0xFF1B2740, 0xFFD8E2F2); - final ink = pick(0xFFF2F6FF, 0xFF0F1B2D); - final danger = pick(0xFFFF7A7A, 0xFFC0392B); + final appBg = pick(0xFF080B12, 0xFFF3F6FB); + final surface = pick(0xFF131B28, 0xFFFFFFFF); + final surfaceAlt = pick(0xFF1A2434, 0xFFEDF2F9); + final surfaceHover = pick(0xFF202B3D, 0xFFE2EAF5); + final line = pick(0xFF243044, 0xFFDEE6F1); + final lineStrong = pick(0xFF33425A, 0xFFC4D1E3); + final ink = pick(0xFFEAF0FA, 0xFF0E1522); + final muted = pick(0xFFA7B4C8, 0xFF48566B); + final faint = pick(0xFF7E8CA3, 0xFF69788E); + final danger = pick(0xFFF08A8A, 0xFFB3261E); final accent = GcPalette.accent.value; - final hsl = HSLColor.fromColor(accent); - final accentStrong = hsl - .withSaturation((hsl.saturation + 0.12).clamp(0.0, 1.0)) - .withLightness((hsl.lightness - (isDark ? 0.10 : 0.22)).clamp(0.0, 1.0)) - .toColor(); + final accentFill = isDark ? accent : _darkenTheme(accent, 0.18); + final accentSoft = Color.lerp(surface, accent, isDark ? 0.16 : 0.12)!; + final onAccent = accentFill.computeLuminance() > 0.42 + ? const Color(0xFF0A1226) + : Colors.white; + + // 字号 / 行高在这里定义;字体族必须最后统一 apply —— + // 下面每个 TextStyle 都是新建对象,不会继承前面的 fontFamily, + // 漏掉就会回退到系统默认字体(中文尤其糊)。 + final textTheme = base.textTheme + .copyWith( + // 页面主标题 + displaySmall: TextStyle( + fontSize: 28, + height: 1.24, + fontWeight: FontWeight.w600, + letterSpacing: -0.2, + color: ink, + ), + headlineMedium: TextStyle( + fontSize: 24, + height: 1.28, + fontWeight: FontWeight.w600, + letterSpacing: -0.2, + color: ink, + ), + headlineSmall: TextStyle( + fontSize: 20, + height: 1.32, + fontWeight: FontWeight.w600, + color: ink, + ), + // 分区标题 + titleLarge: TextStyle( + fontSize: 16, + height: 1.4, + fontWeight: FontWeight.w600, + color: ink, + ), + titleMedium: TextStyle( + fontSize: 14, + height: 1.45, + fontWeight: FontWeight.w600, + color: ink, + ), + titleSmall: TextStyle( + fontSize: 13, + height: 1.45, + fontWeight: FontWeight.w600, + color: ink, + ), + // 正文 + bodyLarge: TextStyle(fontSize: 14, height: 1.6, color: ink), + bodyMedium: TextStyle(fontSize: 13, height: 1.6, color: muted), + bodySmall: TextStyle(fontSize: 12, height: 1.55, color: faint), + // 按钮 / 标签 + labelLarge: const TextStyle( + fontSize: 13, + height: 1.2, + fontWeight: FontWeight.w600, + letterSpacing: 0, + ), + labelMedium: TextStyle( + fontSize: 12, + height: 1.2, + fontWeight: FontWeight.w600, + color: muted, + ), + labelSmall: TextStyle( + fontSize: 11, + height: 1.2, + fontWeight: FontWeight.w600, + letterSpacing: 0.6, + color: faint, + ), + ) + // 只统一字体族,不动上面各自设置的字号与颜色。 + .apply( + fontFamily: family, + fontFamilyFallback: fallback, + ); + + final buttonShape = RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + ); + + ButtonStyle buttonStyle({ + required Color background, + required Color foreground, + Color? border, + bool transparent = false, + }) { + Color blend(Color base, double v) => + Color.lerp(base, isDark ? Colors.white : Colors.black, v)!; + final Color normal = transparent ? Colors.transparent : background; + final Color hover = transparent ? surfaceAlt : blend(background, 0.07); + final Color pressed = transparent ? surfaceHover : blend(background, 0.14); + return ButtonStyle( + minimumSize: const WidgetStatePropertyAll(Size(0, GcSize.control)), + padding: const WidgetStatePropertyAll( + EdgeInsets.symmetric(horizontal: 18), + ), + shape: WidgetStatePropertyAll(buttonShape), + textStyle: WidgetStatePropertyAll(textTheme.labelLarge!), + elevation: const WidgetStatePropertyAll(0), + backgroundColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) { + return transparent ? Colors.transparent : blend(background, 0.04); + } + if (states.contains(WidgetState.pressed)) return pressed; + if (states.contains(WidgetState.hovered) || + states.contains(WidgetState.focused)) { + return hover; + } + return normal; + }), + foregroundColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) return faint; + return foreground; + }), + overlayColor: const WidgetStatePropertyAll(Colors.transparent), + side: border == null + ? null + : WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) { + return BorderSide(color: line); + } + if (states.contains(WidgetState.hovered)) { + return BorderSide(color: lineStrong); + } + return BorderSide(color: border); + }), + ); + } return base.copyWith( scaffoldBackgroundColor: appBg, colorScheme: base.colorScheme.copyWith( brightness: brightness, - primary: accentStrong, + primary: accentFill, + onPrimary: onAccent, secondary: accent, + onSecondary: onAccent, surface: surface, + onSurface: ink, error: danger, + outline: lineStrong, + outlineVariant: line, + surfaceContainerHighest: surfaceAlt, ), - textTheme: base.textTheme.apply( - bodyColor: ink, - displayColor: ink, - ), + textTheme: textTheme, dividerColor: line, + dividerTheme: DividerThemeData(color: line, thickness: 1, space: 1), cardTheme: CardTheme( color: surface, elevation: 0, margin: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.card), + side: BorderSide(color: line), + ), + ), + filledButtonTheme: FilledButtonThemeData( + style: buttonStyle( + background: accentFill, + foreground: onAccent, + border: accentFill, + ), + ), + outlinedButtonTheme: OutlinedButtonThemeData( + style: buttonStyle( + background: Colors.transparent, + foreground: ink, + border: lineStrong, + transparent: true, + ), + ), + textButtonTheme: TextButtonThemeData( + style: TextButton.styleFrom( + minimumSize: const Size(0, GcSize.controlSmall), + padding: const EdgeInsets.symmetric(horizontal: 12), + foregroundColor: muted, + textStyle: textTheme.labelLarge, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + ), + ).copyWith( + foregroundColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) return faint; + if (states.contains(WidgetState.hovered)) return ink; + return muted; + }), + backgroundColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.hovered)) return surfaceAlt; + return Colors.transparent; + }), + overlayColor: const WidgetStatePropertyAll(Colors.transparent), + ), + ), + iconButtonTheme: IconButtonThemeData( + style: IconButton.styleFrom( + minimumSize: const Size(32, 32), + foregroundColor: muted, + highlightColor: Colors.transparent, + hoverColor: surfaceAlt, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + ), + ), ), sliderTheme: base.sliderTheme.copyWith( - activeTrackColor: accentStrong, + activeTrackColor: accent, thumbColor: accent, inactiveTrackColor: line, + trackHeight: 4, + overlayShape: const RoundSliderOverlayShape(overlayRadius: 16), + thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 7), ), switchTheme: SwitchThemeData( thumbColor: WidgetStateProperty.resolveWith( - (states) => states.contains(WidgetState.selected) ? accent : GcColors.faint, + (states) => states.contains(WidgetState.selected) ? onAccent : faint, ), - trackColor: WidgetStateProperty.resolveWith( - (states) => states.contains(WidgetState.selected) - ? accentStrong.withOpacity(0.45) - : line, + trackColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.selected)) return accentFill; + return isDark ? surfaceAlt : line; + }), + trackOutlineColor: WidgetStateProperty.resolveWith( + (states) => + states.contains(WidgetState.selected) ? accentFill : lineStrong, ), ), progressIndicatorTheme: ProgressIndicatorThemeData( color: accent, - linearTrackColor: line, + linearTrackColor: isDark ? surfaceAlt : line, + linearMinHeight: 4, + circularTrackColor: Colors.transparent, ), tooltipTheme: TooltipThemeData( + waitDuration: const Duration(milliseconds: 500), decoration: BoxDecoration( - color: surfaceAlt, - borderRadius: const BorderRadius.all(Radius.circular(6)), + color: isDark ? const Color(0xFF1D2739) : const Color(0xFF0E1522), + borderRadius: BorderRadius.circular(6), + ), + textStyle: TextStyle( + color: isDark ? ink : Colors.white, + fontSize: 12, + height: 1.4, ), - textStyle: TextStyle(color: ink, fontSize: 12), ), + dialogTheme: DialogTheme( + backgroundColor: surface, + surfaceTintColor: Colors.transparent, + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.panel), + side: BorderSide(color: line), + ), + titleTextStyle: textTheme.titleLarge, + contentTextStyle: textTheme.bodyMedium?.copyWith(color: muted), + ), + snackBarTheme: SnackBarThemeData( + backgroundColor: + isDark ? const Color(0xFF1D2739) : const Color(0xFF0E1522), + contentTextStyle: + TextStyle(color: isDark ? ink : Colors.white, fontSize: 13), + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), + elevation: 0, + ), + dropdownMenuTheme: DropdownMenuThemeData( + menuStyle: MenuStyle( + backgroundColor: WidgetStatePropertyAll(surfaceAlt), + surfaceTintColor: + const WidgetStatePropertyAll(Colors.transparent), + shape: WidgetStatePropertyAll( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + side: BorderSide(color: line), + ), + ), + ), + textStyle: textTheme.bodyLarge, + ), + popupMenuTheme: PopupMenuThemeData( + color: surfaceAlt, + surfaceTintColor: Colors.transparent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + side: BorderSide(color: line), + ), + textStyle: textTheme.bodyMedium?.copyWith(color: ink), + ), + segmentedButtonTheme: SegmentedButtonThemeData( + style: ButtonStyle( + minimumSize: const WidgetStatePropertyAll(Size(0, 36)), + padding: const WidgetStatePropertyAll( + EdgeInsets.symmetric(horizontal: 14), + ), + textStyle: WidgetStatePropertyAll(textTheme.labelLarge!), + backgroundColor: WidgetStateProperty.resolveWith((states) { + return states.contains(WidgetState.selected) + ? accentSoft + : Colors.transparent; + }), + foregroundColor: WidgetStateProperty.resolveWith((states) { + return states.contains(WidgetState.selected) ? ink : muted; + }), + side: WidgetStatePropertyAll(BorderSide(color: lineStrong)), + shape: WidgetStatePropertyAll( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(GcRadius.control)), + ), + ), + ), + inputDecorationTheme: InputDecorationTheme( + filled: true, + fillColor: surfaceAlt, + isDense: true, + contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), + hintStyle: TextStyle(color: faint, fontSize: 13), + helperStyle: TextStyle(color: faint, fontSize: 12), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + borderSide: BorderSide(color: line), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + borderSide: BorderSide(color: line), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(GcRadius.control), + borderSide: BorderSide(color: accent, width: 1.4), + ), + ), + scrollbarTheme: ScrollbarThemeData( + thickness: const WidgetStatePropertyAll(8), + radius: const Radius.circular(4), + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.hovered) || + states.contains(WidgetState.dragged)) { + return faint; + } + return lineStrong; + }), + crossAxisMargin: 2, + mainAxisMargin: 2, + ), + splashFactory: NoSplash.splashFactory, + highlightColor: Colors.transparent, ); } -/// 通用卡片容器。 +Color _darkenTheme(Color color, double amount) { + final hsl = HSLColor.fromColor(color); + return hsl + .withSaturation((hsl.saturation + amount * 0.4).clamp(0.0, 1.0)) + .withLightness((hsl.lightness - amount).clamp(0.0, 1.0)) + .toColor(); +} + +// --------------------------------------------------------------------------- +// 通用组件 +// --------------------------------------------------------------------------- + +/// 通用卡片容器:一层描边 + 极浅投影,不用半透明叠色。 class GcCard extends StatelessWidget { - const GcCard({super.key, required this.child, this.padding, this.width}); + const GcCard({ + super.key, + required this.child, + this.padding, + this.width, + this.radius, + this.color, + this.borderColor, + this.clip = false, + }); final Widget child; final EdgeInsetsGeometry? padding; final double? width; + final double? radius; + final Color? color; + final Color? borderColor; + final bool clip; @override Widget build(BuildContext context) { + final r = radius ?? GcRadius.card; return Container( width: width, - padding: padding ?? const EdgeInsets.all(18), + padding: padding ?? const EdgeInsets.all(GcSpace.xl), + clipBehavior: clip ? Clip.antiAlias : Clip.none, decoration: BoxDecoration( - color: GcColors.surface, - borderRadius: BorderRadius.circular(14), - border: Border.all(color: GcColors.line), + color: color ?? GcColors.surface, + borderRadius: BorderRadius.circular(r), + border: Border.all(color: borderColor ?? GcColors.line), ), child: child, ); } } -/// 小标题。 +/// 分区标题:左侧标题 + 右侧操作。 class GcSectionTitle extends StatelessWidget { - const GcSectionTitle(this.text, {super.key, this.trailing}); + const GcSectionTitle(this.text, {super.key, this.trailing, this.subtitle}); final String text; final Widget? trailing; + final String? subtitle; @override Widget build(BuildContext context) { return Row( + crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - child: Text( - text, - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w600, - color: GcColors.ink, - ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + text, + style: TextStyle( + fontSize: 15, + height: 1.4, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + if (subtitle != null) ...[ + const SizedBox(height: GcSpace.xs), + Text( + subtitle!, + style: TextStyle( + fontSize: 12, + height: 1.5, + color: GcColors.faint, + ), + ), + ], + ], ), ), if (trailing != null) trailing!, @@ -261,13 +725,325 @@ class GcSectionTitle extends StatelessWidget { /// 说明文字。 class GcHint extends StatelessWidget { - const GcHint(this.text, {super.key}); + const GcHint(this.text, {super.key, this.maxLines, this.align}); final String text; + final int? maxLines; + final TextAlign? align; @override Widget build(BuildContext context) => Text( text, - style: TextStyle(fontSize: 12, color: GcColors.faint, height: 1.5), + maxLines: maxLines, + textAlign: align, + overflow: maxLines == null ? null : TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12, + height: 1.6, + color: GcColors.faint, + ), + ); +} + +/// 页面标题区:大标题 + 一句说明 + 右侧操作。 +class GcPageHeader extends StatelessWidget { + const GcPageHeader({ + super.key, + required this.title, + this.subtitle, + this.trailing, + }); + + final String title; + final String? subtitle; + final Widget? trailing; + + @override + Widget build(BuildContext context) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + title, + style: TextStyle( + fontSize: 22, + height: 1.3, + fontWeight: FontWeight.w600, + letterSpacing: -0.1, + color: GcColors.ink, + ), + ), + if (subtitle != null && subtitle!.isNotEmpty) ...[ + const SizedBox(height: GcSpace.xs + 2), + Text( + subtitle!, + style: TextStyle( + fontSize: 13, + height: 1.6, + color: GcColors.muted, + ), + ), + ], + ], + ), + ), + if (trailing != null) ...[ + const SizedBox(width: GcSpace.lg), + Padding( + padding: const EdgeInsets.only(top: 2), + child: trailing!, + ), + ], + ], + ); + } +} + +/// 小胶囊标签(版本 / 标签 / 状态)。 +class GcPill extends StatelessWidget { + const GcPill( + this.text, { + super.key, + this.color, + this.subtle = false, + this.icon, + }); + + final String text; + final Color? color; + final bool subtle; + final IconData? icon; + + @override + Widget build(BuildContext context) { + final tint = color ?? GcColors.muted; + final background = subtle + ? GcColors.surfaceAlt + : Color.alphaBlend(tint.withOpacity(0.16), GcColors.surface); + return Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3), + decoration: BoxDecoration( + color: background, + borderRadius: BorderRadius.circular(GcRadius.pill), + border: Border.all( + color: subtle + ? GcColors.line + : Color.alphaBlend(tint.withOpacity(0.34), GcColors.surface), + ), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (icon != null) ...[ + Icon(icon, size: 11, color: subtle ? GcColors.faint : tint), + const SizedBox(width: 4), + ], + Text( + text, + style: TextStyle( + fontSize: 11, + height: 1.25, + fontWeight: FontWeight.w600, + color: subtle ? GcColors.faint : tint, + ), + ), + ], + ), + ); + } +} + +/// 数字指标块(首页 / 关于页用)。 +class GcMetric extends StatelessWidget { + const GcMetric({ + super.key, + required this.value, + required this.label, + this.valueColor, + }); + + final String value; + final String label; + final Color? valueColor; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + value, + style: TextStyle( + fontSize: 20, + height: 1.2, + fontWeight: FontWeight.w600, + letterSpacing: -0.2, + color: valueColor ?? GcColors.ink, + ), + ), + const SizedBox(height: GcSpace.xs), + Text( + label, + style: TextStyle( + fontSize: 12, + height: 1.4, + color: GcColors.faint, + ), + ), + ], + ); + } +} + +/// 统一的空状态 / 错误提示块。 +class GcMessage extends StatelessWidget { + const GcMessage({ + super.key, + required this.title, + this.message, + this.icon, + this.color, + this.action, + }); + + final String title; + final String? message; + final IconData? icon; + final Color? color; + final Widget? action; + + @override + Widget build(BuildContext context) { + final tint = color ?? GcColors.faint; + return GcCard( + padding: const EdgeInsets.symmetric( + horizontal: GcSpace.xxl, + vertical: GcSpace.xl, + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (icon != null) ...[ + Container( + width: 34, + height: 34, + decoration: BoxDecoration( + color: GcColors.surfaceAlt, + borderRadius: BorderRadius.circular(GcRadius.control), + ), + alignment: Alignment.center, + child: Icon(icon, size: 18, color: tint), + ), + const SizedBox(width: GcSpace.md), + ], + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + title, + style: TextStyle( + fontSize: 14, + height: 1.45, + fontWeight: FontWeight.w600, + color: GcColors.ink, + ), + ), + if (message != null && message!.isNotEmpty) ...[ + const SizedBox(height: GcSpace.xs + 2), + Text( + message!, + style: TextStyle( + fontSize: 12, + height: 1.6, + color: GcColors.faint, + ), + ), + ], + if (action != null) ...[ + const SizedBox(height: GcSpace.md), + action!, + ], + ], + ), + ), + ], + ), + ); + } +} + +/// 设置页 / 关于页的「标签 + 值」行。 +class GcFieldRow extends StatelessWidget { + const GcFieldRow({ + super.key, + required this.label, + required this.value, + this.selectable = false, + this.valueColor, + this.trailing, + }); + + final String label; + final String value; + final bool selectable; + final Color? valueColor; + final Widget? trailing; + + @override + Widget build(BuildContext context) { + final style = TextStyle( + fontSize: 13, + height: 1.55, + color: valueColor ?? GcColors.ink, + ); + return Padding( + padding: const EdgeInsets.symmetric(vertical: 6), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 132, + child: Text( + label, + style: TextStyle( + fontSize: 13, + height: 1.55, + color: GcColors.muted, + ), + ), + ), + Expanded( + child: selectable + ? SelectableText(value, style: style) + : Text(value, style: style), + ), + if (trailing != null) ...[ + const SizedBox(width: GcSpace.sm), + trailing!, + ], + ], + ), + ); + } +} + +/// 细分割线。 +class GcDivider extends StatelessWidget { + const GcDivider({super.key, this.verticalPadding = GcSpace.md}); + + final double verticalPadding; + + @override + Widget build(BuildContext context) => Padding( + padding: EdgeInsets.symmetric(vertical: verticalPadding), + child: Container(height: 1, color: GcColors.line), ); } diff --git a/GC-UI/frontend/tool/render_shots_test.dart b/GC-UI/frontend/tool/render_shots_test.dart index 63c56d7..457eedd 100644 --- a/GC-UI/frontend/tool/render_shots_test.dart +++ b/GC-UI/frontend/tool/render_shots_test.dart @@ -21,9 +21,18 @@ import 'package:gc_ui/theme.dart'; /// flutter test tool/render_shots_test.dart void main() { setUpAll(() async { - HttpOverrides.global = null; - + // 不要设置 HttpOverrides.global = null:那会打开真实网络, + // flutter_test 的假时钟下 HTTP 定时器永远悬着,用例结束时 + // 会撞上「!timersPending」断言。保持 flutter_test 默认的 FakeHttpClient + // (所有请求立即返回 400),页面本身都用预置数据渲染,不需要后端。 + // 测试环境默认用 Ahem 占位字体(所有字都是方块),必须显式加载一套真字体: + // Linux CI 用 Noto CJK,Windows 本机用 Noto Sans SC / 微软雅黑,macOS 用苹方。 const candidates = [ + r'C:\Windows\Fonts\Deng.ttf', + r'C:\Windows\Fonts\NotoSansSC-VF.ttf', + r'C:\Windows\Fonts\msyh.ttc', + r'C:\Windows\Fonts\simhei.ttf', + '/System/Library/Fonts/PingFang.ttc', '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', '/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc', ]; @@ -36,6 +45,22 @@ void main() { await loader.load(); break; } + + // Material 图标字体:flutter_test 不会自动加载,不加载的话所有 Icon + // 都是方框,截图就没法检查图标。SDK 缓存里那份由 flutter test 通过 + // FLUTTER_ROOT 指过来。 + final flutterRoot = Platform.environment['FLUTTER_ROOT']; + if (flutterRoot != null) { + final icons = File( + '$flutterRoot/bin/cache/artifacts/material_fonts/materialicons-regular.otf', + ); + if (icons.existsSync()) { + final bytes = icons.readAsBytesSync(); + final loader = FontLoader('MaterialIcons') + ..addFont(Future.value(ByteData.view(bytes.buffer))); + await loader.load(); + } + } }); SettingsInfo sampleSettings() => SettingsInfo.fromJson({ @@ -123,9 +148,26 @@ void main() { 'uiAvailable': true, }); + /// 外壳用的 controller:bootstrap 直接返回,不去连后端。 + /// + /// 真 ShellPage 会在 initState 里 bootstrap,后端不在时会挂重试定时器, + /// 用例结束时报「!timersPending」。这里只把 bootstrap 换成空实现, + /// 页面里的数据请求仍会走 flutter_test 的假 HTTP(立即 400)。 + ShellController shellController() => _StubShellController() + ..settings = sampleSettings() + ..health = HealthInfo.fromJson({ + 'ok': true, + 'version': '1.0.7', + 'platform': 'osx-arm64', + 'uiAvailable': true, + }); + Future shoot(WidgetTester tester, String name, Widget page, - {Brightness brightness = Brightness.dark}) async { - tester.view.physicalSize = const Size(1280, 820); + {Brightness brightness = Brightness.dark, + Size size = const Size(1280, 860)}) async { + // 1280×860:与发布包窗口默认尺寸(1280×720)接近,再多留一点高度看得到 + // 底部状态条。像素比 1.0,方便逐像素检查描边和文字。 + tester.view.physicalSize = size; tester.view.devicePixelRatio = 1.0; addTearDown(tester.view.reset); @@ -136,10 +178,13 @@ void main() { await tester.pumpWidget( MaterialApp( debugShowCheckedModeBanner: false, - theme: buildGcTheme(brightness).copyWith( - textTheme: buildGcTheme(brightness).textTheme.apply( - fontFamily: 'Noto Sans CJK SC', - ), + // 四个页面都用预置数据渲染,不需要后端;字体统一换成测试里加载的 + // 那一套,并且清空 fallback —— 否则主题里的按钮 / 输入框样式会去 + // 找系统字体(测试环境没有),缺字处就画成方块。 + theme: buildGcTheme( + brightness, + fontFamily: 'Noto Sans CJK SC', + fontFamilyFallback: const [], ), home: RepaintBoundary( key: key, @@ -148,25 +193,27 @@ void main() { ), ); await tester.pump(const Duration(milliseconds: 200)); - // 页面里的数据来自真实后端(/api/about、/api/sources 等)。 - // flutter_test 默认用假时钟,真实 HTTP 永远不会完成,所以这里用 runAsync - // 让出真实时间,等请求回来后再 pump 出最终画面。 - await tester.runAsync(() async { - await Future.delayed(const Duration(milliseconds: 1200)); - }); - await tester.pump(const Duration(milliseconds: 300)); - await tester.runAsync(() async { - await Future.delayed(const Duration(milliseconds: 600)); - }); await tester.pump(const Duration(milliseconds: 300)); final boundary = key.currentContext!.findRenderObject()! as RenderRepaintBoundary; - final image = await boundary.toImage(pixelRatio: 1.0); - final bytes = await image.toByteData(format: ui.ImageByteFormat.png); + // toImage / toByteData 要走真实引擎的异步管线,必须放在 runAsync 里, + // 否则 fake async 时钟不会推进,Future 一直不完成(表现为每个用例卡 + // 满 10 分钟超时才返回)。 + final stopwatch = Stopwatch()..start(); + final image = await tester.runAsync( + () => boundary.toImage(pixelRatio: 1.0), + ); + final bytes = await tester.runAsync( + () => image!.toByteData(format: ui.ImageByteFormat.png), + ); final dir = Directory('test/shots')..createSync(recursive: true); File('${dir.path}/$name.png').writeAsBytesSync(bytes!.buffer.asUint8List()); + stopwatch.stop(); + // ignore: avoid_print + print( + '[shots] $name (${brightness.name}) 耗时 ${stopwatch.elapsedMilliseconds} ms'); } testWidgets('home', (tester) async { @@ -174,7 +221,8 @@ void main() { await shoot( tester, 'home', - HomePageView(controller: sampleController(), initialModels: sampleModels()), + HomePageView( + controller: sampleController(), initialModels: sampleModels()), ); }); @@ -261,7 +309,8 @@ void main() { testWidgets('settings', (tester) async { I18n.language.value = 'zh-CN'; - await shoot(tester, 'settings', SettingsPageView(controller: sampleController())); + await shoot( + tester, 'settings', SettingsPageView(controller: sampleController())); }); testWidgets('about', (tester) async { @@ -292,7 +341,77 @@ void main() { testWidgets('shell', (tester) async { I18n.language.value = 'zh-CN'; - await shoot(tester, 'shell', ShellPage(controller: sampleController())); + final controller = shellController() + ..setUpdateStatus( + visible: true, + busy: false, + progress: 1, + status: '已更新 2 个模型,立即生效', + detail: '模型与启动器均为最新版', + notice: '', + ); + await shoot(tester, 'shell', ShellPage(controller: controller)); + }); + + /// 小窗口回归:1024×680 下不应出现溢出条纹或卡片挤压。 + testWidgets('home-small', (tester) async { + I18n.language.value = 'zh-CN'; + await shoot( + tester, + 'home-small', + HomePageView( + controller: sampleController(), initialModels: sampleModels()), + size: const Size(1024, 680), + ); + }); + + testWidgets('download-small', (tester) async { + I18n.language.value = 'zh-CN'; + await shoot( + tester, + 'download-small', + DownloadPageView( + controller: sampleController(), + initialSources: [ + SourceInfo.fromJson({ + 'id': 'github', + 'name': 'GitHub', + 'url': 'https://github.com/Morris-GC/GC', + 'enabled': true, + 'builtIn': true, + 'host': 'github.com', + }), + ], + initialIndex: SourceIndexInfo.fromJson({ + 'sourceId': 'github', + 'root': 'https://github.com/Morris-GC/GC', + 'fromCache': false, + 'resolvedFrom': 'version.json', + 'models': [ + { + 'id': 'sun', + 'name': '太阳系', + 'description': '观察八大行星的公转轨道与相对大小。', + 'version': '1.2', + 'sizeText': '2.3 MB', + 'installed': true, + }, + ], + }), + initialJobs: const [], + ), + size: const Size(1024, 680), + ); + }); + + testWidgets('settings-small', (tester) async { + I18n.language.value = 'zh-CN'; + await shoot( + tester, + 'settings-small', + SettingsPageView(controller: sampleController()), + size: const Size(1024, 680), + ); }); testWidgets('home-light', (tester) async { @@ -300,7 +419,8 @@ void main() { await shoot( tester, 'home-light', - HomePageView(controller: sampleController(), initialModels: sampleModels()), + HomePageView( + controller: sampleController(), initialModels: sampleModels()), brightness: Brightness.light, ); }); @@ -315,3 +435,9 @@ void main() { ); }); } + +/// 只用于截图的 controller:不连后端,避免挂上重试定时器。 +class _StubShellController extends ShellController { + @override + Future bootstrap() async {} +} diff --git a/GC-UI/frontend/windows/runner/main.cpp b/GC-UI/frontend/windows/runner/main.cpp index 21e6874..473c57d 100644 --- a/GC-UI/frontend/windows/runner/main.cpp +++ b/GC-UI/frontend/windows/runner/main.cpp @@ -5,8 +5,81 @@ #include "flutter_window.h" #include "utils.h" +namespace { + +// Enable DPI awareness (Per-Monitor V2 when available). +// +// The runner.exe.manifest normally declares this, but the mingw/windres cross +// build does not embed the manifest the way the Visual Studio generator does. +// A DPI-unaware process gets bitmap-stretched by Windows on a 125% / 150% +// scaled display, which makes the whole UI (especially small CJK text) look +// blurry. Declaring it again before any window exists costs nothing and does +// not depend on the manifest being present. +// +// Every API is resolved through GetProcAddress: it keeps the binary working on +// older systems and does not require the current SDK / mingw headers to declare +// DPI_AWARENESS_CONTEXT. +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4191) // FARPROC to typed function pointer, on purpose +#endif + +BOOL TryPerMonitorV2() { + // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 == (HANDLE)-4 + using Fn = BOOL(WINAPI*)(HANDLE); + HMODULE user32 = ::GetModuleHandleW(L"user32.dll"); + if (user32 == nullptr) return FALSE; + auto set_context = reinterpret_cast( + ::GetProcAddress(user32, "SetProcessDpiAwarenessContext")); + if (set_context == nullptr) return FALSE; + // Cast through INT_PTR: plain -4 to pointer is C4312 at /W4. + return set_context(reinterpret_cast(static_cast(-4))); +} + +void TryPerMonitor() { + // Windows 8.1+: PROCESS_PER_MONITOR_DPI_AWARE == 2 + using Fn = HRESULT(WINAPI*)(int); + HMODULE shcore = ::LoadLibraryW(L"shcore.dll"); + if (shcore == nullptr) return; + auto set_awareness = + reinterpret_cast(::GetProcAddress(shcore, "SetProcessDpiAwareness")); + if (set_awareness != nullptr) { + // E_ACCESSDENIED means the manifest already set awareness: still fine. + set_awareness(2); + } + ::FreeLibrary(shcore); +} + +void TrySystemDpiAware() { + // Windows Vista+: system DPI awareness, better than nothing. + using Fn = BOOL(WINAPI*)(); + HMODULE user32 = ::GetModuleHandleW(L"user32.dll"); + if (user32 == nullptr) return; + auto set_aware = + reinterpret_cast(::GetProcAddress(user32, "SetProcessDPIAware")); + if (set_aware != nullptr) set_aware(); +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +void EnableDpiAwareness() { + // When the manifest already declared awareness, SetProcessDpiAwarenessContext + // returns FALSE; fall back to the 8.1 and Vista entry points. All three + // failing is harmless: the app still starts, it just scales blurrily. + if (TryPerMonitorV2()) return; + TryPerMonitor(); + TrySystemDpiAware(); +} + +} // namespace + int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + // Must run before the first window is created to take effect. + EnableDpiAwareness(); + // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { diff --git a/GC-UI/frontend/windows/runner/win32_window.cpp b/GC-UI/frontend/windows/runner/win32_window.cpp index 60608d0..2b76ac4 100644 --- a/GC-UI/frontend/windows/runner/win32_window.cpp +++ b/GC-UI/frontend/windows/runner/win32_window.cpp @@ -134,11 +134,27 @@ bool Win32Window::Create(const std::wstring& title, UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); double scale_factor = dpi / 96.0; + // Cap the initial size to the monitor work area. 1280x720 logical is + // 1920x1080 physical at 150% scaling, which no longer fits on a 1080p + // screen; clamping keeps the window usable instead of hanging off-screen. + int physical_width = Scale(size.width, scale_factor); + int physical_height = Scale(size.height, scale_factor); + MONITORINFO monitor_info{}; + monitor_info.cbSize = sizeof(MONITORINFO); + if (::GetMonitorInfoW(monitor, &monitor_info)) { + const int max_width = + (monitor_info.rcWork.right - monitor_info.rcWork.left) * 92 / 100; + const int max_height = + (monitor_info.rcWork.bottom - monitor_info.rcWork.top) * 92 / 100; + if (physical_width > max_width) physical_width = max_width; + if (physical_height > max_height) physical_height = max_height; + } + HWND window = CreateWindow( window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), - Scale(size.width, scale_factor), Scale(size.height, scale_factor), - nullptr, nullptr, GetModuleHandle(nullptr), this); + physical_width, physical_height, nullptr, nullptr, + GetModuleHandle(nullptr), this); if (!window) { return false; diff --git a/buildsh/cross/CMakeLists.txt b/buildsh/cross/CMakeLists.txt index b44e91c..4783d9b 100644 --- a/buildsh/cross/CMakeLists.txt +++ b/buildsh/cross/CMakeLists.txt @@ -44,6 +44,19 @@ string(REPLACE "#define VERSION_AS_STRING FLUTTER_VERSION" _rc_text "${_rc_text}") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/Runner.cross.rc" "${_rc_text}") +# ★ DPI 清单必须自己嵌进去。 +# +# windows/runner/CMakeLists.txt 把 runner.exe.manifest 当源文件列进 target, +# Visual Studio 生成器会把它交给链接器(/MANIFESTINPUT)自动嵌入; +# 但这里的交叉编译只用 windres 编 Runner.rc,CMake 不会做这一步, +# 编出来的 GC-UI.exe 就完全没有清单 —— Windows 当它「DPI 不感知」, +# 在 125% / 150% 缩放的屏幕上整体位图拉伸,界面全是糊的。 +# +# 因此把清单直接写成资源条目:id 1 = CREATEPROCESS_MANIFEST_RESOURCE_ID, +# type 24 = RT_MANIFEST。windres 不按相对路径解析,这里给绝对路径。 +file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/Runner.cross.rc" + "\n1 24 \"${RUN_DIR}/runner.exe.manifest\"\n") + add_executable(${BINARY_NAME} WIN32 "${RUN_DIR}/main.cpp" "${RUN_DIR}/flutter_window.cpp" -- 2.54.0