From 7dc155080b122ee803fdab1add227ac7f1f2d20c Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sat, 11 May 2024 16:07:03 +0200 Subject: [PATCH] scale device frame (wip) --- screenshots/screenshot_config.dart | 32 ++++++++++++++++++++++++++++++ test_driver/screenshot_driver.dart | 22 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 screenshots/screenshot_config.dart diff --git a/screenshots/screenshot_config.dart b/screenshots/screenshot_config.dart new file mode 100644 index 0000000..7b4249c --- /dev/null +++ b/screenshots/screenshot_config.dart @@ -0,0 +1,32 @@ +import 'dart:convert'; + +class ScreenshotConfig { + final String title; + final String subtitle; + final String screenshotPath; + + const ScreenshotConfig({ + required this.title, + required this.subtitle, + required this.screenshotPath, + }); +} + +enum ScreenshotLayout { + iphone65inch( + size: (width: 1242, height: 2688), + contentPadding: (left: 150, top: 192, right: 150, bottom: 192), + ), + iphone55inch( + size: (width: 1242, height: 2208), + contentPadding: (left: 150, top: 192, right: 150, bottom: 192), + ); + + final ({int height, int width}) size; + final ({int left, int top, int right, int bottom}) contentPadding; + + const ScreenshotLayout({ + required this.size, + required this.contentPadding, + }); +} diff --git a/test_driver/screenshot_driver.dart b/test_driver/screenshot_driver.dart index 99e9685..fc6cf12 100644 --- a/test_driver/screenshot_driver.dart +++ b/test_driver/screenshot_driver.dart @@ -6,6 +6,7 @@ import 'package:integration_test/integration_test_driver_extended.dart'; import '../screenshots/devices_config.dart'; import '../screenshots/screenshot_args.dart'; +import '../screenshots/screenshot_config.dart'; import 'utils/grant_camera_permission.dart'; Future main() async { @@ -80,4 +81,25 @@ extension ScreenshotImage on Image { return compositeImage(expandedScreenshot, frame); } + + Image applyLayout(ScreenshotLayout layout) { + final scaledScreenshot = copyResize( + this, + width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right), + ); + + return copyExpandCanvas( + copyExpandCanvas( + scaledScreenshot, + newWidth: scaledScreenshot.width + layout.contentPadding.right, + newHeight: scaledScreenshot.height + layout.contentPadding.bottom, + position: ExpandCanvasPosition.topLeft, + backgroundColor: getPixel(0, 0), + ), + newWidth: layout.size.width, + newHeight: layout.size.height, + position: ExpandCanvasPosition.bottomRight, + backgroundColor: getPixel(0, 0), + ); + } }