Skip to content

Commit

Permalink
Add right click as alternative to long press
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 7, 2023
1 parent b6d382c commit 5d8fe40
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
3 changes: 3 additions & 0 deletions app/lib/views/edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class _EditToolbarState extends State<EditToolbar> {
: () => context
.read<CurrentIndexCubit>()
.insertSelection(e, true),
onSecondaryPressed: () => context
.read<CurrentIndexCubit>()
.changeSelection(e),
focussed: shortcuts.contains(i),
selected: selected,
highlighted: highlighted,
Expand Down
87 changes: 44 additions & 43 deletions app/lib/views/toolbar/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,52 +137,53 @@ class _ColorToolbarViewState extends State<ColorToolbarView> {
children: [
...List.generate(palette.colors.length, (index) {
final value = palette!.colors[index];
void changeColor() async {
var palette = pack?.getPalette(colorPalette!.name);
final settingsCubit = context.read<SettingsCubit>();
final response = await showDialog<
ColorPickerResponse<ColorPickerToolbarAction>>(
context: context,
builder: (context) =>
ColorPicker<ColorPickerToolbarAction>(
value: Color(value),
suggested: settingsCubit.state.recentColors
.map((e) => Color(e))
.toList(),
secondaryActions: (close) => [
OutlinedButton(
onPressed: () =>
close(ColorPickerToolbarAction.delete),
child:
Text(AppLocalizations.of(context).delete),
),
],
),
);
if (response == null) return;
if (response.action ==
ColorPickerToolbarAction.delete) {
palette = palette?.copyWith(
colors: List<int>.from(palette.colors)
..removeAt(index),
);
} else {
palette = palette?.copyWith(
colors: List<int>.from(palette.colors)
..[index] = response.color,
);
}
bloc.add(PackUpdated(
colorPalette!.pack, pack!.setPalette(palette!)));
widget.onChanged(response.color);
setState(() {});
}

return ColorButton(
color: Color(value),
selected: value == color,
onTap: () {
widget.onChanged(value);
},
onLongPress: () async {
var palette = pack?.getPalette(colorPalette!.name);
final settingsCubit = context.read<SettingsCubit>();
final response = await showDialog<
ColorPickerResponse<ColorPickerToolbarAction>>(
context: context,
builder: (context) =>
ColorPicker<ColorPickerToolbarAction>(
value: Color(value),
suggested: settingsCubit.state.recentColors
.map((e) => Color(e))
.toList(),
secondaryActions: (close) => [
OutlinedButton(
onPressed: () =>
close(ColorPickerToolbarAction.delete),
child:
Text(AppLocalizations.of(context).delete),
),
],
),
);
if (response == null) return;
if (response.action ==
ColorPickerToolbarAction.delete) {
palette = palette?.copyWith(
colors: List<int>.from(palette.colors)
..removeAt(index),
);
} else {
palette = palette?.copyWith(
colors: List<int>.from(palette.colors)
..[index] = response.color,
);
}
bloc.add(PackUpdated(
colorPalette!.pack, pack!.setPalette(palette!)));
widget.onChanged(response.color);
setState(() {});
},
onTap: () => widget.onChanged(value),
onSecondaryTap: changeColor,
onLongPress: changeColor,
);
}),
Padding(
Expand Down
4 changes: 3 additions & 1 deletion app/lib/widgets/option_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:phosphor_flutter/phosphor_flutter.dart';
class OptionButton extends StatefulWidget {
final Widget icon;
final Widget? selectedIcon;
final VoidCallback? onPressed, onLongPressed;
final VoidCallback? onPressed, onSecondaryPressed, onLongPressed;
final bool selected, highlighted, focussed;
final String tooltip;

Expand All @@ -14,6 +14,7 @@ class OptionButton extends StatefulWidget {
required this.icon,
this.selectedIcon,
this.onPressed,
this.onSecondaryPressed,
this.onLongPressed,
this.selected = false,
this.highlighted = false,
Expand Down Expand Up @@ -72,6 +73,7 @@ class _OptionButtonState extends State<OptionButton>
radius: 12,
borderRadius: BorderRadius.circular(12),
onTap: widget.onPressed,
onSecondaryTap: widget.onSecondaryPressed,
onLongPress: widget.onLongPressed == null
? null
: () {
Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ packages:
dependency: "direct main"
description:
path: "packages/material_leap"
ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81"
resolved-ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81"
ref: "7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e"
resolved-ref: "7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e"
url: "https://github.com/LinwoodDev/dart_pkgs.git"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies:
material_leap:
git:
url: https://github.com/LinwoodDev/dart_pkgs.git
ref: 75b5ec0e51096ae169df3cd4f02c9f6affe22a81
ref: 7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e
path: packages/material_leap
lw_sysinfo:
git:
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/82.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Add right click as alternative to long press
* Change default scale of label to 5
* Improve documentation of shortcuts ([#534](https://github.com/LinwoodDev/Butterfly/issues/534))
* Fix closing of settings on click on mobile ([#537](https://github.com/LinwoodDev/Butterfly/issues/537))
Expand Down

0 comments on commit 5d8fe40

Please sign in to comment.