Files
cutdex/packages/cutdex_preview/lib/src/preview_canvas.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

67 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
/// Fits the output canvas within the workspace; native rendering fits media
/// within this canvas using its own source geometry (including rotation).
class PreviewCanvas extends StatelessWidget {
const PreviewCanvas({
super.key,
required this.aspectRatio,
required this.child,
this.overlayBuilder,
this.horizontalPadding = 16,
this.alignment = Alignment.topCenter,
this.backgroundColor = Colors.black,
});
final double aspectRatio;
final double horizontalPadding;
final Alignment alignment;
final Color backgroundColor;
final Widget child;
final Widget Function(Rect canvasRect)? overlayBuilder;
@override
Widget build(BuildContext context) => RepaintBoundary(
child: ColoredBox(
key: const Key('preview-surface'),
color: Theme.of(context).colorScheme.surface,
child: LayoutBuilder(
builder: (context, constraints) {
final available = Size(
(constraints.maxWidth - horizontalPadding * 2).clamp(
0,
double.infinity,
),
constraints.maxHeight,
);
final fitted = applyBoxFit(
BoxFit.contain,
Size(aspectRatio, 1),
available,
).destination;
final rect = alignment.inscribe(
fitted,
Offset.zero & constraints.biggest,
);
return Stack(
fit: StackFit.expand,
clipBehavior: Clip.hardEdge,
children: [
Positioned.fromRect(
rect: rect,
child: ColoredBox(
key: const Key('preview-canvas'),
color: backgroundColor,
child: ClipRect(child: child),
),
),
if (overlayBuilder != null && rect.width > 0 && rect.height > 0)
Positioned.fill(child: overlayBuilder!(rect)),
],
);
},
),
),
);
}