fixed tile extent clamping
This commit is contained in:
parent
75143cf56b
commit
0755c632d6
2 changed files with 13 additions and 21 deletions
|
@ -9,7 +9,6 @@ import 'package:aves/widgets/common/data_providers/media_query_data_provider.dar
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class GridScaleGestureDetector extends StatefulWidget {
|
||||
final GlobalKey scrollableKey;
|
||||
|
@ -31,8 +30,7 @@ class GridScaleGestureDetector extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _GridScaleGestureDetectorState extends State<GridScaleGestureDetector> {
|
||||
Tuple2<double, double> _extentMinMax;
|
||||
double _startExtent;
|
||||
double _startExtent, _extentMin, _extentMax;
|
||||
ValueNotifier<double> _scaledExtentNotifier;
|
||||
OverlayEntry _overlayEntry;
|
||||
ThumbnailMetadata _metadata;
|
||||
|
@ -41,12 +39,6 @@ class _GridScaleGestureDetectorState extends State<GridScaleGestureDetector> {
|
|||
|
||||
ValueNotifier<double> get tileExtentNotifier => widget.extentNotifier;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_extentMinMax = TileExtentManager.extentBoundsForSize(widget.mqSize);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
|
@ -69,6 +61,8 @@ class _GridScaleGestureDetectorState extends State<GridScaleGestureDetector> {
|
|||
|
||||
// not the same as `MediaQuery.size.width`, because of screen insets/padding
|
||||
final gridWidth = scrollableBox.size.width;
|
||||
_extentMin = gridWidth / (gridWidth / TileExtentManager.tileExtentMin).round();
|
||||
_extentMax = gridWidth / (gridWidth / TileExtentManager.extentMaxForSize(widget.mqSize)).round();
|
||||
final halfExtent = _startExtent / 2;
|
||||
final thumbnailCenter = renderMetaData.localToGlobal(Offset(halfExtent, halfExtent));
|
||||
_overlayEntry = OverlayEntry(
|
||||
|
@ -86,7 +80,7 @@ class _GridScaleGestureDetectorState extends State<GridScaleGestureDetector> {
|
|||
onScaleUpdate: (details) {
|
||||
if (_scaledExtentNotifier == null) return;
|
||||
final s = details.scale;
|
||||
_scaledExtentNotifier.value = (_startExtent * s).clamp(_extentMinMax.item1, _extentMinMax.item2);
|
||||
_scaledExtentNotifier.value = (_startExtent * s).clamp(_extentMin, _extentMax);
|
||||
},
|
||||
onScaleEnd: (details) {
|
||||
if (_overlayEntry != null) {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:aves/model/settings.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class TileExtentManager {
|
||||
static const columnCountMin = 2;
|
||||
static const columnCountDefault = 4;
|
||||
static const columnCountMax = 8;
|
||||
static const int columnCountMin = 2;
|
||||
static const int columnCountDefault = 4;
|
||||
static const double tileExtentMin = 46.0;
|
||||
|
||||
static double applyTileExtent(Size mqSize, EdgeInsets mqPadding, ValueNotifier<double> extentNotifier, {double newExtent}) {
|
||||
final availableWidth = mqSize.width - mqPadding.horizontal;
|
||||
|
@ -19,9 +20,8 @@ class TileExtentManager {
|
|||
if ((newExtent ?? 0) == 0) {
|
||||
numColumns = columnCountDefault;
|
||||
} else {
|
||||
final minMax = extentBoundsForSize(mqSize);
|
||||
newExtent = newExtent.clamp(minMax.item1, minMax.item2);
|
||||
numColumns = (availableWidth / newExtent).round().clamp(columnCountMin, columnCountMax);
|
||||
newExtent = newExtent.clamp(tileExtentMin, extentMaxForSize(mqSize));
|
||||
numColumns = max(columnCountMin, (availableWidth / newExtent).round());
|
||||
}
|
||||
newExtent = availableWidth / numColumns;
|
||||
if (extentNotifier.value != newExtent) {
|
||||
|
@ -31,9 +31,7 @@ class TileExtentManager {
|
|||
return newExtent;
|
||||
}
|
||||
|
||||
static Tuple2<double, double> extentBoundsForSize(Size mqSize) {
|
||||
final min = mqSize.shortestSide / columnCountMax;
|
||||
final max = mqSize.shortestSide / columnCountMin;
|
||||
return Tuple2(min, max);
|
||||
static double extentMaxForSize(Size mqSize) {
|
||||
return mqSize.shortestSide / columnCountMin;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue