Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ sealed class ButterflySettings with _$ButterflySettings, LeapSettings {
List<AssetLocation> history,
@Default(true) bool zoomEnabled,
@Default(ZoomPosition.bottomRight) ZoomPosition zoomPosition,
@Default(ZoomPosition.topRight) ZoomPosition propertyPosition,
String? lastVersion,
@Default([])
@JsonKey(includeFromJson: false, includeToJson: false)
Expand Down Expand Up @@ -577,6 +578,13 @@ sealed class ButterflySettings with _$ButterflySettings, LeapSettings {
ZoomPosition.bottomRight,
)
: ZoomPosition.bottomRight,
propertyPosition: prefs.containsKey('property_position')
? _enumByNameOr(
ZoomPosition.values,
prefs.getString('property_position'),
ZoomPosition.topRight,
)
: ZoomPosition.topRight,
lastVersion: prefs.getString('last_version'),
connections: connections,
defaultRemote: prefs.getString('default_remote') ?? '',
Expand Down Expand Up @@ -774,6 +782,7 @@ sealed class ButterflySettings with _$ButterflySettings, LeapSettings {
);
await prefs.setBool('zoom_enabled', zoomEnabled);
await prefs.setString('zoom_position', zoomPosition.name);
await prefs.setString('property_position', propertyPosition.name);
if (lastVersion == null && prefs.containsKey('last_version')) {
await prefs.remove('last_version');
} else if (lastVersion != null) {
Expand Down Expand Up @@ -954,6 +963,14 @@ class SettingsCubit extends Cubit<ButterflySettings>
Future<void> resetZoomPosition() =>
changeZoomPosition(ZoomPosition.bottomRight);

Future<void> changePropertyPosition(ZoomPosition position) {
emit(state.copyWith(propertyPosition: position));
return save();
}

Future<void> resetPropertyPosition() =>
changePropertyPosition(ZoomPosition.topRight);

void changeLocaleTemporarily(String locale) {
emit(state.copyWith(localeTag: locale));
}
Expand Down
31 changes: 17 additions & 14 deletions app/lib/cubits/settings.freezed.dart

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions app/lib/cubits/settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions app/lib/settings/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class ViewSettingsPage extends StatelessWidget {
.changeZoomEnabled(value),
onTap: () => _openZoomPositionModal(context),
),
ListTile(
leading: const PhosphorIcon(PhosphorIconsLight.sliders),
title: Text(AppLocalizations.of(context).properties),
subtitle: Text(
state.propertyPosition.getLocalizedName(context),
),
onTap: () => _openPropertyPositionModal(context),
),
ListTile(
leading: const PhosphorIcon(PhosphorIconsLight.toolbox),
title: Text(
Expand Down Expand Up @@ -222,6 +230,33 @@ class ViewSettingsPage extends StatelessWidget {
);
}

void _openPropertyPositionModal(BuildContext context) {
final cubit = context.read<SettingsCubit>();
var currentPos = cubit.state.propertyPosition;
showLeapBottomSheet(
context: context,
titleBuilder: (context) => Text(AppLocalizations.of(context).properties),
childrenBuilder: (context) => ZoomPosition.values
.map(
(e) => ListTile(
title: Text(e.getLocalizedName(context)),
selected: currentPos == e,
leading: Icon(switch (e) {
ZoomPosition.topRight => PhosphorIconsLight.arrowUpRight,
ZoomPosition.topLeft => PhosphorIconsLight.arrowUpLeft,
ZoomPosition.bottomRight => PhosphorIconsLight.arrowDownRight,
ZoomPosition.bottomLeft => PhosphorIconsLight.arrowDownLeft,
}, textDirection: TextDirection.ltr),
onTap: () {
cubit.changePropertyPosition(e);
Navigator.of(context).pop();
},
),
)
.toList(),
);
}

void _openToolbarPositionModal(BuildContext context) {
final cubit = context.read<SettingsCubit>();
var currentPos = cubit.state.toolbarPosition;
Expand Down
14 changes: 10 additions & 4 deletions app/lib/views/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ class _MainBody extends StatelessWidget {
current.navigatorPosition ||
previous.optionsPanelPosition !=
current.optionsPanelPosition ||
previous.zoomPosition != current.zoomPosition,
previous.zoomPosition != current.zoomPosition ||
previous.propertyPosition != current.propertyPosition,
builder: (context, settings) {
return LayoutBuilder(
builder: (context, constraints) => _buildLayout(
Expand Down Expand Up @@ -754,9 +755,14 @@ class _MainBody extends StatelessWidget {
child: Stack(
children: [
_buildZoomAndTools(context, settings, isMobile, currentIndex),
const Align(
alignment: Alignment.topRight,
child: PropertyView(),
Align(
alignment: switch (settings.propertyPosition) {
ZoomPosition.topRight => Alignment.topRight,
ZoomPosition.topLeft => Alignment.topLeft,
ZoomPosition.bottomRight => Alignment.bottomRight,
ZoomPosition.bottomLeft => Alignment.bottomLeft,
},
child: PropertyView(position: settings.propertyPosition),
),
],
),
Expand Down
19 changes: 14 additions & 5 deletions app/lib/views/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';
import 'package:butterfly/api/open.dart';
import 'package:butterfly/bloc/document_bloc.dart';
import 'package:butterfly/cubits/current_index.dart';
import 'package:butterfly/cubits/settings.dart';
import 'package:butterfly/widgets/editable_list_tile.dart';
import 'package:butterfly_api/butterfly_api.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,7 +16,9 @@ import '../selections/selection.dart';
import '../visualizer/icon.dart';

class PropertyView extends StatefulWidget {
const PropertyView({super.key});
final ZoomPosition position;

const PropertyView({super.key, required this.position});

@override
State<PropertyView> createState() => _PropertyViewState();
Expand All @@ -29,10 +32,6 @@ class _PropertyViewState extends State<PropertyView>
duration: const Duration(milliseconds: 200),
vsync: this,
);
late final Animation<Offset> _offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(1.5, 0.0),
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOutCubic));
late final Animation<double> _fadeAnimation = Tween<double>(
begin: 1.0,
end: 0.0,
Expand Down Expand Up @@ -103,6 +102,16 @@ class _PropertyViewState extends State<PropertyView>
void _closeView() {
context.read<CurrentIndexCubit>().resetSelection(force: true);
}

Animation<Offset> get _offsetAnimation => Tween<Offset>(
begin: Offset.zero,
end: switch (widget.position) {
ZoomPosition.topRight ||
ZoomPosition.bottomRight => const Offset(1.5, 0.0),
ZoomPosition.topLeft ||
ZoomPosition.bottomLeft => const Offset(-1.5, 0.0),
},
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOutCubic));
}

class _PropertyCard extends StatefulWidget {
Expand Down
Loading