feat(ui): 预览卡缩小并可点击切换视图;导出只含时序图+标题

- 圆周/条形预览卡缩小(300->190,高度压缩),标题去掉「(实时联动)」,加切换箭头
- 点击预览卡直接切换条形/圆周视图;预览门槛降低,小窗口也可见
- 导出边界(PNG)只包含「时序图 + 标题」;图例/统计/编辑工具/预览/浮动条移出导出边界
- 重新构建 dist
This commit is contained in:
呆头鹅
2026-09-19 17:33:02 +08:00
parent a7de782349
commit f5412ee99d
2 changed files with 115 additions and 68 deletions
+12 -2
View File
@@ -236,6 +236,7 @@ class _AppShellState extends State<AppShell> {
// 画布舞台:可绘制区域,叠加画布视图与浮层。 // 画布舞台:可绘制区域,叠加画布视图与浮层。
child: Stack( child: Stack(
children: <Widget>[ children: <Widget>[
// 导出边界:仅包含「时序图 + 标题」,不含编辑辅助浮层。
Positioned.fill( Positioned.fill(
child: RepaintBoundary( child: RepaintBoundary(
key: _stageKey, key: _stageKey,
@@ -245,19 +246,28 @@ class _AppShellState extends State<AppShell> {
Positioned.fill( Positioned.fill(
child: Container(color: t.canvas2, child: CanvasView(controller: c)), child: Container(color: t.canvas2, child: CanvasView(controller: c)),
), ),
// 上层:信息浮层。 // 仅标题(参与导出)。
Positioned.fill( Positioned.fill(
child: CanvasOverlays( child: CanvasOverlays(
controller: c, controller: c,
// 侧栏收起时让浮层避开边缘把手。
leftInset: _leftRail ? 22 : 0, leftInset: _leftRail ? 22 : 0,
rightInset: _rightRail ? 22 : 0, rightInset: _rightRail ? 22 : 0,
showPanels: false,
), ),
), ),
], ],
), ),
), ),
), ),
// 编辑辅助浮层(图例 / 统计 / 工具 / 预览 / 浮动条):不参与导出。
Positioned.fill(
child: CanvasOverlays(
controller: c,
leftInset: _leftRail ? 22 : 0,
rightInset: _rightRail ? 22 : 0,
showTitle: false,
),
),
// 收起状态:贴边轨道(悬停可展开为悬浮面板)。 // 收起状态:贴边轨道(悬停可展开为悬浮面板)。
if (_leftRail) if (_leftRail)
Positioned(left: 0, top: 0, bottom: 0, child: _rail(t, true)), Positioned(left: 0, top: 0, bottom: 0, child: _rail(t, true)),
+80 -43
View File
@@ -27,6 +27,8 @@ class CanvasOverlays extends StatelessWidget {
required this.controller, required this.controller,
this.leftInset = 0, this.leftInset = 0,
this.rightInset = 0, this.rightInset = 0,
this.showTitle = true,
this.showPanels = true,
}); });
/// 全局应用控制器,提供项目数据与编辑动作。 /// 全局应用控制器,提供项目数据与编辑动作。
@@ -38,6 +40,14 @@ class CanvasOverlays extends StatelessWidget {
/// 右侧把手占用的宽度(0 表示无把手)。 /// 右侧把手占用的宽度(0 表示无把手)。
final double rightInset; final double rightInset;
/// 是否显示顶部标题(导出 PNG 时把标题纳入导出边界)。
final bool showTitle;
/// 是否显示其余面板(图例 / 统计 / 工具 / 预览 / 浮动工具条)。
///
/// 这些属于**编辑辅助元素,不参与导出**。
final bool showPanels;
/// 控制器快捷访问器。 /// 控制器快捷访问器。
AppController get c => controller; AppController get c => controller;
@@ -61,12 +71,13 @@ class CanvasOverlays extends StatelessWidget {
final bool showStats = !circular && w >= 820 && h >= 700; final bool showStats = !circular && w >= 820 && h >= 700;
// 编辑工具条:门槛最低,几乎始终显示。 // 编辑工具条:门槛最低,几乎始终显示。
final bool showTools = w >= 700; final bool showTools = w >= 700;
// 实时预览卡片:门槛放低,钉住侧栏后仍可见。 // 预览卡片(已缩小):门槛放低,钉住侧栏后仍可见。
final bool showPreview = w >= 1000 && h >= 680; final bool showPreview = w >= 720 && h >= 560;
// 浮层整体使用 Stack 叠加,各面板按断点条件选择性插入。 // 浮层整体使用 Stack 叠加,各面板按断点条件选择性插入。
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
// 顶部标题与副标题,横跨整个画布宽度,不拦截手势。 // 顶部标题与副标题,横跨整个画布宽度,不拦截手势。
if (showTitle)
Positioned( Positioned(
left: left, left: left,
top: 12, top: 12,
@@ -74,7 +85,7 @@ class CanvasOverlays extends StatelessWidget {
child: IgnorePointer(child: _Title(t: t, circular: circular, project: c.project)), child: IgnorePointer(child: _Title(t: t, circular: circular, project: c.project)),
), ),
// 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。 // 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。
if (showLeftColumn) if (showPanels && showLeftColumn)
Positioned( Positioned(
left: left, left: left,
top: 70, top: 70,
@@ -94,7 +105,7 @@ class CanvasOverlays extends StatelessWidget {
), ),
), ),
// 条形视图左下角:节拍统计 + 编辑工具。 // 条形视图左下角:节拍统计 + 编辑工具。
if (!circular && (showStats || showTools)) if (showPanels && !circular && (showStats || showTools))
Positioned( Positioned(
left: left, left: left,
bottom: 12, bottom: 12,
@@ -110,19 +121,17 @@ class CanvasOverlays extends StatelessWidget {
], ],
), ),
), ),
// 右下角实时预览:圆周视图显示条形缩略,反之亦然。 // 右下角预览:圆周视图显示条形缩略,反之亦然;点击可切换视图。
if (showPreview) if (showPanels && showPreview)
Positioned( Positioned(
right: right, right: right,
bottom: 12, bottom: 12,
child: IgnorePointer(
child: circular child: circular
? _BarPreviewCard(t: t, project: c.project) ? _BarPreviewCard(t: t, c: c)
: _CircularPreviewCard(t: t, project: c.project), : _CircularPreviewCard(t: t, c: c),
),
), ),
// 圆周视图右侧浮动工具栏(添加/编辑/复制/删除/改层/对齐)。 // 圆周视图右侧浮动工具栏(添加/编辑/复制/删除/改层/对齐)。
if (circular) if (showPanels && circular)
Positioned( Positioned(
right: right - 2, right: right - 2,
top: 120, top: 120,
@@ -737,29 +746,41 @@ class _FloatingToolbar extends StatelessWidget {
} }
} }
/// 条形节拍缩略预览卡(在圆周视图右下角显示)。 /// 条形节拍缩略预览卡(在圆周视图右下角显示);点击切换到条形视图。
class _BarPreviewCard extends StatelessWidget { class _BarPreviewCard extends StatelessWidget {
const _BarPreviewCard({required this.t, required this.project}); const _BarPreviewCard({required this.t, required this.c});
/// 主题令牌。 /// 主题令牌。
final Tokens t; final Tokens t;
/// 当前项目。 /// 全局应用控制器(用于切换视图)。
final Project project; final AppController c;
/// 渲染条形缩略预览。 /// 渲染紧凑的条形缩略预览,整卡可点击切换视图。
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _Card( final Project project = c.project;
return InkWell(
onTap: () => c.setViewMode(ViewMode.bar),
borderRadius: BorderRadius.circular(10),
child: _Card(
t: t, t: t,
width: 300, width: 190,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text('条形节拍预览(实时联动)', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)), Row(
const SizedBox(height: 10), children: <Widget>[
Icon(Icons.bar_chart, size: 13, color: t.accent),
const SizedBox(width: 5),
Text('条形预览', style: TextStyle(color: t.sub, fontSize: 10.5, fontWeight: FontWeight.w600)),
const Spacer(),
Icon(Icons.chevron_right, size: 14, color: t.dim),
],
),
const SizedBox(height: 6),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: project.actions.length * 22.0 + 18, height: project.actions.length * 12.0 + 14,
child: CustomPaint( child: CustomPaint(
size: Size.infinite, size: Size.infinite,
painter: _MiniBarPainter(project, t), painter: _MiniBarPainter(project, t),
@@ -767,6 +788,7 @@ class _BarPreviewCard extends StatelessWidget {
), ),
], ],
), ),
),
); );
} }
} }
@@ -783,37 +805,40 @@ class _MiniBarPainter extends CustomPainter {
/// 逐行绘制动作色条、跨圈尾段与底部刻度。 /// 逐行绘制动作色条、跨圈尾段与底部刻度。
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
final int n = project.actions.length;
final double w = size.width - 4; final double w = size.width - 4;
final double rh = 19; // 行高按可用高度自适应,保证小预览里也排得下。
for (int i = 0; i < project.actions.length; i++) { final double pitch = n == 0 ? 12 : math.min(12, (size.height - 16) / n);
final double rh = math.max(pitch - 3, 4);
for (int i = 0; i < n; i++) {
final Action a = project.actions[i]; final Action a = project.actions[i];
final double y = i * (rh + 3); final double y = i * pitch;
final double x1 = 2 + a.startAngle / 360 * w; final double x1 = 2 + a.startAngle / 360 * w;
final double x2 = 2 + math.min(a.endAngle, 360) / 360 * w; final double x2 = 2 + math.min(a.endAngle, 360) / 360 * w;
final RRect r = RRect.fromRectAndRadius( final RRect r = RRect.fromRectAndRadius(
Rect.fromLTWH(x1, y, math.max(x2 - x1, 2), rh - 4), Rect.fromLTWH(x1, y, math.max(x2 - x1, 2), rh),
const Radius.circular(3), const Radius.circular(2),
); );
canvas.drawRRect(r, Paint()..color = Color(a.color).withValues(alpha: 0.9)); canvas.drawRRect(r, Paint()..color = Color(a.color).withValues(alpha: 0.9));
if (a.wrap) { if (a.wrap) {
canvas.drawRRect( canvas.drawRRect(
RRect.fromRectAndRadius(Rect.fromLTWH(2, y, (a.endAngle - 360) / 360 * w, rh - 4), const Radius.circular(3)), RRect.fromRectAndRadius(Rect.fromLTWH(2, y, (a.endAngle - 360) / 360 * w, rh), const Radius.circular(2)),
Paint()..color = Color(a.color).withValues(alpha: t.tailOp), Paint()..color = Color(a.color).withValues(alpha: t.tailOp),
); );
} }
} }
final double baseY = project.actions.length * (rh + 3) + 4; final double baseY = n * pitch + 3;
canvas.drawLine(Offset(2, baseY), Offset(size.width - 2, baseY), Paint()..color = t.line2..strokeWidth = 1); canvas.drawLine(Offset(2, baseY), Offset(size.width - 2, baseY), Paint()..color = t.line2..strokeWidth = 1);
final TextPainter tp = TextPainter( final TextPainter tp = TextPainter(
text: TextSpan(text: '0.0 ${timeUnitLabel(project.units.timeUnit)}', style: TextStyle(color: t.dim, fontSize: 10)), text: TextSpan(text: '0.0 ${timeUnitLabel(project.units.timeUnit)}', style: TextStyle(color: t.dim, fontSize: 9)),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
)..layout(); )..layout();
tp.paint(canvas, Offset(2, baseY + 4)); tp.paint(canvas, Offset(2, baseY + 2));
final TextPainter tp2 = TextPainter( final TextPainter tp2 = TextPainter(
text: TextSpan(text: tfmt(project.cycle.durationMs, project.units), style: TextStyle(color: t.dim, fontSize: 10)), text: TextSpan(text: tfmt(project.cycle.durationMs, project.units), style: TextStyle(color: t.dim, fontSize: 9)),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
)..layout(); )..layout();
tp2.paint(canvas, Offset(size.width - 2 - tp2.width, baseY + 4)); tp2.paint(canvas, Offset(size.width - 2 - tp2.width, baseY + 2));
} }
/// 预览始终重绘(数据实时联动)。 /// 预览始终重绘(数据实时联动)。
@@ -821,37 +846,49 @@ class _MiniBarPainter extends CustomPainter {
bool shouldRepaint(covariant _MiniBarPainter old) => true; bool shouldRepaint(covariant _MiniBarPainter old) => true;
} }
/// 圆周节拍缩略预览卡(在条形视图右下角显示)。 /// 圆周节拍缩略预览卡(在条形视图右下角显示);点击切换到圆周视图。
class _CircularPreviewCard extends StatelessWidget { class _CircularPreviewCard extends StatelessWidget {
const _CircularPreviewCard({required this.t, required this.project}); const _CircularPreviewCard({required this.t, required this.c});
/// 主题令牌。 /// 主题令牌。
final Tokens t; final Tokens t;
/// 当前项目。 /// 全局应用控制器(用于切换视图)。
final Project project; final AppController c;
/// 渲染圆周缩略预览。 /// 渲染紧凑的圆周缩略预览,整卡可点击切换视图。
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _Card( final Project project = c.project;
return InkWell(
onTap: () => c.setViewMode(ViewMode.circular),
borderRadius: BorderRadius.circular(10),
child: _Card(
t: t, t: t,
width: 300, width: 190,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text('圆周节拍预览(实时联动)', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)), Row(
const SizedBox(height: 8), children: <Widget>[
Icon(Icons.donut_large, size: 13, color: t.accent),
const SizedBox(width: 5),
Text('圆周预览', style: TextStyle(color: t.sub, fontSize: 10.5, fontWeight: FontWeight.w600)),
const Spacer(),
Icon(Icons.chevron_right, size: 14, color: t.dim),
],
),
const SizedBox(height: 6),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: 250, height: 150,
child: CustomPaint( child: CustomPaint(
size: Size.infinite, size: Size.infinite,
painter: _MiniCircularPainter(project, t), painter: _MiniCircularPainter(project, t),
), ),
), ),
Text('12 点钟起始 · 顺时针 · 每层一环', style: TextStyle(color: t.dim, fontSize: 10)),
], ],
), ),
),
); );
} }
} }