2021-07-25 10:52:24 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
|
|
|
|
|
|
|
class ZoomMenuButton extends StatelessWidget {
|
|
|
|
ZoomMenuButton({
|
|
|
|
Key? key,
|
|
|
|
required this.initialZoom,
|
|
|
|
required this.minZoom,
|
|
|
|
required this.maxZoom,
|
|
|
|
this.onZoomChanged,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return PopupMenuButton(
|
|
|
|
icon: const Icon(Icons.photo_size_select_large),
|
2021-08-29 13:51:43 +02:00
|
|
|
tooltip: L10n.global().zoomTooltip,
|
2021-07-25 10:52:24 +02:00
|
|
|
itemBuilder: (context) => [
|
|
|
|
_PopupMenuZoom(
|
|
|
|
initialValue: initialZoom,
|
|
|
|
minValue: minZoom,
|
|
|
|
maxValue: maxZoom,
|
|
|
|
onChanged: onZoomChanged,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final int initialZoom;
|
|
|
|
final int minZoom;
|
|
|
|
final int maxZoom;
|
|
|
|
final ValueChanged<int>? onZoomChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PopupMenuZoom extends PopupMenuEntry<void> {
|
|
|
|
_PopupMenuZoom({
|
|
|
|
Key? key,
|
|
|
|
required this.initialValue,
|
|
|
|
required this.minValue,
|
|
|
|
required this.maxValue,
|
|
|
|
this.onChanged,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
represents(void value) => false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
createState() => _PopupMenuZoomState();
|
|
|
|
|
|
|
|
@override
|
|
|
|
// this value doesn't seems to do anything?
|
|
|
|
final double height = 48.0;
|
|
|
|
|
|
|
|
final int initialValue;
|
|
|
|
final int minValue;
|
|
|
|
final int maxValue;
|
|
|
|
final ValueChanged<int>? onChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PopupMenuZoomState extends State<_PopupMenuZoom> {
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
|
|
|
_value = widget.initialValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return Slider(
|
|
|
|
value: _value.toDouble(),
|
|
|
|
min: widget.minValue.toDouble(),
|
|
|
|
max: widget.maxValue.toDouble(),
|
|
|
|
divisions: (widget.maxValue - widget.minValue).round(),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_value = value.round();
|
|
|
|
});
|
|
|
|
widget.onChanged?.call(_value);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
late int _value;
|
|
|
|
}
|