Skip to content

Commit

Permalink
Improve slider and double input list tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jan 5, 2025
1 parent 692dfed commit 6eaec38
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 323 deletions.
2 changes: 1 addition & 1 deletion app/lib/actions/svg_export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SvgExportAction extends Action<SvgExportIntent> {
builder: (context) => BlocProvider.value(
value: bloc,
child: GeneralExportDialog(
preset: ExportTransformPreset.page,
preset: ExportTransformPreset.view,
options: getDefaultSvgExportOptions(
context,
transform: transform,
Expand Down
2 changes: 0 additions & 2 deletions app/lib/dialogs/background/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:material_leap/material_leap.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

import '../../selections/selection.dart';

part 'general.dart';
part 'properties/texture.dart';
part 'properties/image.dart';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/dialogs/background/properties/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class _ImageBackgroundPropertiesView extends StatelessWidget {
Widget build(BuildContext context) {
return ListView(
children: [
OffsetPropertyView(
OffsetListTile(
title: Text(AppLocalizations.of(context).scale),
value: Offset(value.scaleX, value.scaleY),
onChanged: (value) => onChanged(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/dialogs/background/properties/svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class _SvgBackgroundPropertiesView extends StatelessWidget {
Widget build(BuildContext context) {
return ListView(
children: [
OffsetPropertyView(
OffsetListTile(
title: Text(AppLocalizations.of(context).scale),
value: Offset(value.scaleX, value.scaleY),
onChanged: (value) => onChanged(
Expand Down
172 changes: 52 additions & 120 deletions app/lib/dialogs/export/general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ class GeneralExportDialog extends StatefulWidget {
}

class _GeneralExportDialogState extends State<GeneralExportDialog> {
final TextEditingController _xController = TextEditingController(text: '0');

final TextEditingController _yController = TextEditingController(text: '0');

final TextEditingController _widthController =
TextEditingController(text: '1000');

final TextEditingController _heightController =
TextEditingController(text: '1000');

ExportTransformPreset? _preset;

late ExportOptions _options;
Expand All @@ -73,29 +63,12 @@ class _GeneralExportDialogState extends State<GeneralExportDialog> {
@override
void initState() {
_preset = widget.preset;
_applyOptions(widget.options);
_options = widget.options;
_regeneratePreviewImage();

super.initState();
}

@override
void dispose() {
super.dispose();
_xController.dispose();
_yController.dispose();
_widthController.dispose();
_heightController.dispose();
}

void _applyOptions(ExportOptions options) {
_options = options;
_xController.text = _options.x.toString();
_yController.text = _options.y.toString();
_widthController.text = _options.width.toString();
_heightController.text = _options.height.toString();
}

Future<void> _regeneratePreviewImage() async {
if (_regeneratingFuture != null) return;
var imageFuture = generateImage();
Expand Down Expand Up @@ -250,14 +223,18 @@ class _GeneralExportDialogState extends State<GeneralExportDialog> {
?.state
.transformCubit
.state;
_applyOptions(switch (_options) {
ImageExportOptions _ => getDefaultImageExportOptions(
context,
transform: transform),
SvgExportOptions _ => getDefaultSvgExportOptions(context,
transform: transform),

setState(() {
_preset = ExportTransformPreset.view;
_options = (switch (_options) {
ImageExportOptions _ => getDefaultImageExportOptions(
context,
transform: transform),
SvgExportOptions _ => getDefaultSvgExportOptions(
context,
transform: transform),
});
});
setState(() => _preset = ExportTransformPreset.view);
_regeneratePreviewImage();
},
icon: const PhosphorIcon(PhosphorIconsLight.userRectangle),
Expand All @@ -272,22 +249,24 @@ class _GeneralExportDialogState extends State<GeneralExportDialog> {
context.read<DocumentBloc>().state.currentIndexCubit;
if (cubit == null) return;
final rect = cubit.getPageRect();
_applyOptions(switch (_options) {
ImageExportOptions e => e.copyWith(
width: rect.width,
height: rect.height,
x: rect.left,
y: rect.top,
scale: 1,
),
SvgExportOptions e => e.copyWith(
width: rect.width,
height: rect.height,
x: rect.left,
y: rect.top,
),
setState(() {
_preset = ExportTransformPreset.page;
_options = (switch (_options) {
ImageExportOptions e => e.copyWith(
width: rect.width,
height: rect.height,
x: rect.left,
y: rect.top,
scale: 1,
),
SvgExportOptions e => e.copyWith(
width: rect.width,
height: rect.height,
x: rect.left,
y: rect.top,
),
});
});
setState(() => _preset = ExportTransformPreset.page);
_regeneratePreviewImage();
},
icon: const PhosphorIcon(PhosphorIconsLight.file),
Expand Down Expand Up @@ -328,76 +307,30 @@ class _GeneralExportDialogState extends State<GeneralExportDialog> {

Widget _buildProperties() =>
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
AppLocalizations.of(context).position,
style: Theme.of(context).textTheme.titleMedium,
),
Row(
children: [
Expanded(
child: TextField(
controller: _xController,
decoration: const InputDecoration(labelText: 'X', filled: true),
onChanged: (value) {
_options = _options.copyWith(
x: double.tryParse(value) ?? _options.x);
setState(() => _preset = null);
},
onSubmitted: (value) => _regeneratePreviewImage(),
),
),
const SizedBox(width: 16),
Expanded(
child: TextField(
controller: _yController,
decoration: const InputDecoration(labelText: 'Y', filled: true),
onChanged: (value) {
_options = _options.copyWith(
y: double.tryParse(value) ?? _options.y);
setState(() => _preset = null);
},
onSubmitted: (value) => _regeneratePreviewImage(),
),
),
],
),
const SizedBox(height: 16),
Text(
AppLocalizations.of(context).size,
style: Theme.of(context).textTheme.titleMedium,
OffsetListTile(
value: Offset(_options.x, _options.y),
title: Text(AppLocalizations.of(context).position),
onChanged: (value) {
setState(
() => _options = _options.copyWith(x: value.dx, y: value.dy));
setState(() => _preset = null);
_regeneratePreviewImage();
},
),
Row(
children: [
Expanded(
child: TextField(
controller: _widthController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).width,
filled: true),
onChanged: (value) {
_options = _options.copyWith(
width: double.tryParse(value) ?? _options.width);
setState(() => _preset = null);
},
onSubmitted: (value) => _regeneratePreviewImage(),
),
),
const SizedBox(width: 16),
Expanded(
child: TextField(
controller: _heightController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).height,
filled: true),
onChanged: (value) {
_options = _options.copyWith(
height: double.tryParse(value) ?? _options.height);
setState(() => _preset = null);
},
onSubmitted: (value) => _regeneratePreviewImage(),
),
),
],
const SizedBox(height: 8),
OffsetListTile(
value: Offset(_options.width, _options.height),
title: Text(AppLocalizations.of(context).size),
xLabel: AppLocalizations.of(context).width,
yLabel: AppLocalizations.of(context).height,
onChanged: (value) {
setState(() => _options = _options.copyWith(
width: value.dx,
height: value.dy,
));
setState(() => _preset = null);
_regeneratePreviewImage();
},
),
if (_options is ImageExportOptions)
..._getImageOptions(_options as ImageExportOptions),
Expand All @@ -415,7 +348,6 @@ class _GeneralExportDialogState extends State<GeneralExportDialog> {

List<Widget> _getImageOptions(ImageExportOptions options) {
return [
const SizedBox(height: 8),
ExactSlider(
header: Text(AppLocalizations.of(context).scale),
min: 0.1,
Expand Down
1 change: 0 additions & 1 deletion app/lib/dialogs/export/pdf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ class _AreaPreview extends StatelessWidget {
const SizedBox(height: 8),
Text(area.name),
Text(page, style: Theme.of(context).textTheme.bodySmall),
const SizedBox(height: 16),
ExactSlider(
value: quality,
min: 1,
Expand Down
52 changes: 24 additions & 28 deletions app/lib/dialogs/packs/styles/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class _TextStyleViewState extends State<TextStyleView> {
onChangeEnd: (spacing) => widget.onChanged(
widget.value.copyWith(letterSpacing: spacing),
)),
const SizedBox(height: 16),
ListTile(
title: Text(AppLocalizations.of(context).fontWeight),
trailing: DropdownMenu<FontWeight?>(
Expand Down Expand Up @@ -212,33 +211,30 @@ class _TextStyleViewState extends State<TextStyleView> {
defaultColor: null,
onChanged: (color) => widget.onChanged(
widget.value.copyWith(decorationColor: color))),
Padding(
padding: const EdgeInsets.all(16.0),
child: ExactSlider(
header:
Text(AppLocalizations.of(context).thickness),
defaultValue: 1,
value: widget.value.decorationThickness,
bottom: widget.value.decorationThickness == null
? Text(AppLocalizations.of(context).notSet)
: null,
leading: widget.value.decorationThickness == null
? null
: IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.eraser),
tooltip:
AppLocalizations.of(context).remove,
onPressed: () => widget.onChanged(widget
.value
.copyWith(decorationThickness: null)),
),
min: 0.1,
max: 4,
onChangeEnd: (thickness) => widget.onChanged(
widget.value.copyWith(
decorationThickness: thickness))),
),
ExactSlider(
header:
Text(AppLocalizations.of(context).thickness),
defaultValue: 1,
value: widget.value.decorationThickness,
bottom: widget.value.decorationThickness == null
? Text(AppLocalizations.of(context).notSet)
: null,
leading: widget.value.decorationThickness == null
? null
: IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.eraser),
tooltip:
AppLocalizations.of(context).remove,
onPressed: () => widget.onChanged(widget
.value
.copyWith(decorationThickness: null)),
),
min: 0.1,
max: 4,
onChangeEnd: (thickness) => widget.onChanged(widget
.value
.copyWith(decorationThickness: thickness))),
]))
],
)),
Expand Down
Loading

0 comments on commit 6eaec38

Please sign in to comment.