fixed widget image sizing in some cases
This commit is contained in:
parent
baab89defc
commit
a05c8ad7d5
3 changed files with 30 additions and 6 deletions
|
@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file.
|
|||
- storage volume setup despite faulty volume on Android <11
|
||||
- storage volume setup when launched right after device boot
|
||||
- tiling PNG images
|
||||
- widget image sizing in some cases
|
||||
|
||||
## <a id="v1.6.11"></a>[v1.6.11] - 2022-07-26
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:aves/model/entry.dart';
|
||||
import 'package:aves/model/settings/enums/enums.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
@ -32,13 +33,29 @@ extension ExtraWidgetShape on WidgetShape {
|
|||
}
|
||||
}
|
||||
|
||||
Size size(Size widgetSize) {
|
||||
double extentPx(Size widgetSizePx, AvesEntry entry) {
|
||||
switch (this) {
|
||||
case WidgetShape.rrect:
|
||||
return widgetSize;
|
||||
final entryRatio = entry.displayAspectRatio;
|
||||
final widgetRatio = widgetSizePx.width / widgetSizePx.height;
|
||||
if (entryRatio > 1) {
|
||||
// landscape entry, must return thumbnail height as extent
|
||||
if (widgetRatio > entryRatio) {
|
||||
return widgetSizePx.width / entryRatio;
|
||||
} else {
|
||||
return widgetSizePx.height;
|
||||
}
|
||||
} else {
|
||||
// portrait entry, must return thumbnail width as extent
|
||||
if (widgetRatio > entryRatio) {
|
||||
return widgetSizePx.width;
|
||||
} else {
|
||||
return widgetSizePx.height * entryRatio;
|
||||
}
|
||||
}
|
||||
case WidgetShape.circle:
|
||||
case WidgetShape.heart:
|
||||
return Size.square(widgetSize.shortestSide);
|
||||
return widgetSizePx.shortestSide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,13 @@ class HomeWidgetPainter {
|
|||
ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba,
|
||||
}) async {
|
||||
final widgetSizePx = Size(widthPx.toDouble(), heightPx.toDouble());
|
||||
final entryImage = await _getEntryImage(entry, shape.size(widgetSizePx));
|
||||
late final ui.Image? entryImage;
|
||||
if (entry != null) {
|
||||
final extent = shape.extentPx(widgetSizePx, entry!) / devicePixelRatio;
|
||||
entryImage = await _getEntryImage(entry, extent);
|
||||
} else {
|
||||
entryImage = null;
|
||||
}
|
||||
|
||||
final recorder = ui.PictureRecorder();
|
||||
final rect = Rect.fromLTWH(0, 0, widgetSizePx.width, widgetSizePx.height);
|
||||
|
@ -63,10 +69,10 @@ class HomeWidgetPainter {
|
|||
..strokeCap = StrokeCap.round);
|
||||
}
|
||||
|
||||
FutureOr<ui.Image?> _getEntryImage(AvesEntry? entry, Size sizePx) async {
|
||||
FutureOr<ui.Image?> _getEntryImage(AvesEntry? entry, double extent) async {
|
||||
if (entry == null) return null;
|
||||
|
||||
final provider = entry.getThumbnail(extent: sizePx.longestSide / devicePixelRatio);
|
||||
final provider = entry.getThumbnail(extent: extent);
|
||||
|
||||
final imageInfoCompleter = Completer<ImageInfo?>();
|
||||
final imageStream = provider.resolve(ImageConfiguration.empty);
|
||||
|
|
Loading…
Reference in a new issue