mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +01:00
Refactor zoom button
This commit is contained in:
parent
942f61d90d
commit
6a0374d6c0
5 changed files with 118 additions and 103 deletions
|
@ -9,8 +9,8 @@ import 'package:nc_photos/entity/file.dart';
|
|||
import 'package:nc_photos/pref.dart';
|
||||
import 'package:nc_photos/theme.dart';
|
||||
import 'package:nc_photos/widget/album_viewer_app_bar.dart';
|
||||
import 'package:nc_photos/widget/popup_menu_zoom.dart';
|
||||
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
||||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
|
||||
mixin AlbumViewerMixin<T extends StatefulWidget>
|
||||
on SelectableItemStreamListMixin<T> {
|
||||
|
@ -44,22 +44,16 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
|||
album: album,
|
||||
coverPreviewUrl: _coverPreviewUrl,
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.photo_size_select_large),
|
||||
tooltip: L10n.of(context).zoomTooltip,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuZoom(
|
||||
initialValue: _thumbZoomLevel,
|
||||
minValue: 0,
|
||||
maxValue: 2,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
ZoomMenuButton(
|
||||
initialZoom: _thumbZoomLevel,
|
||||
minZoom: 0,
|
||||
maxZoom: 2,
|
||||
onZoomChanged: (value) {
|
||||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
...(actions ?? []),
|
||||
PopupMenuButton<int>(
|
||||
|
|
|
@ -19,9 +19,9 @@ import 'package:nc_photos/snack_bar_manager.dart';
|
|||
import 'package:nc_photos/theme.dart';
|
||||
import 'package:nc_photos/use_case/update_property.dart';
|
||||
import 'package:nc_photos/widget/photo_list_item.dart';
|
||||
import 'package:nc_photos/widget/popup_menu_zoom.dart';
|
||||
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
||||
import 'package:nc_photos/widget/viewer.dart';
|
||||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
|
||||
class ArchiveViewerArguments {
|
||||
ArchiveViewerArguments(this.account);
|
||||
|
@ -168,22 +168,16 @@ class _ArchiveViewerState extends State<ArchiveViewer>
|
|||
title: Text(L10n.of(context).albumArchiveLabel),
|
||||
floating: true,
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.photo_size_select_large),
|
||||
tooltip: L10n.of(context).zoomTooltip,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuZoom(
|
||||
initialValue: _thumbZoomLevel,
|
||||
minValue: 0,
|
||||
maxValue: 2,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
ZoomMenuButton(
|
||||
initialZoom: _thumbZoomLevel,
|
||||
minZoom: 0,
|
||||
maxZoom: 2,
|
||||
onZoomChanged: (value) {
|
||||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
@ -35,9 +35,9 @@ import 'package:nc_photos/widget/home_app_bar.dart';
|
|||
import 'package:nc_photos/widget/measure.dart';
|
||||
import 'package:nc_photos/widget/page_visibility_mixin.dart';
|
||||
import 'package:nc_photos/widget/photo_list_item.dart';
|
||||
import 'package:nc_photos/widget/popup_menu_zoom.dart';
|
||||
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
||||
import 'package:nc_photos/widget/viewer.dart';
|
||||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
|
||||
class HomePhotos extends StatefulWidget {
|
||||
HomePhotos({
|
||||
|
@ -209,22 +209,16 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
child: HomeSliverAppBar(
|
||||
account: widget.account,
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.photo_size_select_large),
|
||||
tooltip: L10n.of(context).zoomTooltip,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuZoom(
|
||||
initialValue: _thumbZoomLevel,
|
||||
minValue: -1,
|
||||
maxValue: 2,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_setThumbZoomLevel(value.round());
|
||||
});
|
||||
Pref.inst().setHomePhotosZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
ZoomMenuButton(
|
||||
initialZoom: _thumbZoomLevel,
|
||||
minZoom: -1,
|
||||
maxZoom: 2,
|
||||
onZoomChanged: (value) {
|
||||
setState(() {
|
||||
_setThumbZoomLevel(value.round());
|
||||
});
|
||||
Pref.inst().setHomePhotosZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
menuActions: [
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
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 double minValue;
|
||||
final double maxValue;
|
||||
final void Function(double)? onChanged;
|
||||
}
|
||||
|
||||
class _PopupMenuZoomState extends State<PopupMenuZoom> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_value = widget.initialValue.toDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
build(BuildContext context) {
|
||||
return Slider(
|
||||
value: _value,
|
||||
min: widget.minValue,
|
||||
max: widget.maxValue,
|
||||
divisions: (widget.maxValue - widget.minValue).round(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_value = value;
|
||||
});
|
||||
widget.onChanged?.call(value);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
var _value = 0.0;
|
||||
}
|
85
lib/widget/zoom_menu_button.dart
Normal file
85
lib/widget/zoom_menu_button.dart
Normal file
|
@ -0,0 +1,85 @@
|
|||
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),
|
||||
tooltip: L10n.of(context).zoomTooltip,
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue