Skip to content

Commit

Permalink
Add scale to label toolbar and unify selection view
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 28, 2023
1 parent 24a1007 commit 264fc40
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 16 deletions.
9 changes: 4 additions & 5 deletions api/lib/src/models/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ abstract class PathElement {
PathProperty get property;
}

mixin LabelElement {
mixin LabelElement on PadElement {
@override
String get layer;
Point<double> get position;
double get scale;
Expand All @@ -62,17 +63,15 @@ mixin LabelElement {
int get foreground;

AreaProperty get areaProperty {
final element = this as PadElement;
return element.maybeMap(
return maybeMap(
markdown: (e) => e.areaProperty,
text: (e) => e.area.areaProperty,
orElse: () => throw UnimplementedError(),
);
}

String get text {
final element = this as PadElement;
return element.maybeMap(
return maybeMap(
markdown: (e) => e.text,
text: (e) => e.area.paragraph.text,
orElse: () => throw UnimplementedError(),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/handlers/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LabelHandler extends Handler<LabelTool>
} else {
final page = context.getPage();
if (page == null) return;
final index = page.content.indexOf(labelRenderer.element as PadElement);
final index = page.content.indexOf(labelRenderer.element);
context.getDocumentBloc().add(ElementsRemoved([index]));
_context = _createContext(document, element: labelRenderer.element);
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/selections/elements/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ElementSelection<T extends PadElement> extends Selection<Renderer<T>> {
return ImageElementSelection([selected as Renderer<ImageElement>])
as ElementSelection<T>;
}
if (selected is Renderer<TextElement>) {
return TextElementSelection([selected as Renderer<TextElement>])
if (selected is Renderer<LabelElement>) {
return LabelElementSelection([selected as Renderer<TextElement>])
as ElementSelection<T>;
}
if (selected is Renderer<PenElement>) {
Expand Down
33 changes: 27 additions & 6 deletions app/lib/selections/elements/text.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
part of '../selection.dart';

class TextElementSelection extends ElementSelection<TextElement> {
TextElementSelection(super.selected);
class LabelElementSelection extends ElementSelection<LabelElement> {
LabelElementSelection(super.selected);

@override
List<Widget> buildProperties(BuildContext context) {
final element = selected.first.element;
return [
...super.buildProperties(context),
ExactSlider(
header: Text(AppLocalizations.of(context).scale),
min: 0.1,
max: 15,
value: element.scale,
defaultValue: 5,
onChangeEnd: (value) => updateElements(
context,
elements
.map((e) => e.maybeMap(
text: (e) => e.copyWith(scale: value),
markdown: (e) => e.copyWith(scale: value),
orElse: () => e))
.toList()),
),
ConstraintView(
initialConstraint: element.constraint,
onChanged: (constraint) => updateElements(context,
elements.map((e) => e.copyWith(constraint: constraint)).toList()),
onChanged: (constraint) => updateElements(
context,
elements
.map((e) => e.maybeMap(
text: (e) => e.copyWith(constraint: constraint),
markdown: (e) => e.copyWith(constraint: constraint),
orElse: () => e))
.toList()),
),
];
}

@override
Selection insert(element) {
if (element is Renderer<TextElement>) {
return TextElementSelection([...selected, element]);
if (element is Renderer<LabelElement>) {
return LabelElementSelection([...selected, element]);
}
return super.insert(element);
}
Expand Down
45 changes: 43 additions & 2 deletions app/lib/views/toolbar/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class LabelToolbarView extends StatefulWidget implements PreferredSizeWidget {
class _LabelToolbarViewState extends State<LabelToolbarView> {
final ScrollController _scrollController = ScrollController();

final TextEditingController _sizeController = TextEditingController();
final TextEditingController _sizeController = TextEditingController(),
_scaleController = TextEditingController();

final GlobalKey _paragraphKey = GlobalKey(), _spanKey = GlobalKey();

Expand Down Expand Up @@ -88,6 +89,8 @@ class _LabelToolbarViewState extends State<LabelToolbarView> {
value.mapOrNull(text: (e) => e.getDefinedForcedSpanProperty(document));
final styleSheet = value.styleSheet;
final style = styleSheet.resolveStyle(document);
_scaleController.text =
(value.labelElement?.scale ?? value.tool.scale).toString();
_sizeController.text = span?.getSize(paragraph).toString() ?? '';
var paragraphSelection = paragraph.mapOrNull(named: (value) => value.name);
final paragraphSelections = [
Expand Down Expand Up @@ -254,8 +257,46 @@ class _LabelToolbarViewState extends State<LabelToolbarView> {
AppLocalizations.of(context).chooseLabelMode,
),
),
const SizedBox(width: 16),
SizedBox(
width: 100,
child: TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).scale,
filled: true,
floatingLabelAlignment:
FloatingLabelAlignment.center,
alignLabelWithHint: true,
),
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
controller: _scaleController,
onFieldSubmitted: (current) {
final newScale = double.tryParse(current);
if (newScale == null) return;
final element = value.element;
if (element == null) {
widget.onChanged(value.copyWith(
tool: value.tool.copyWith(
scale: newScale,
),
));
return;
}
widget.onChanged(
value.map(
text: (e) => e.copyWith(
element: e.element!
.copyWith(scale: newScale)),
markdown: (e) => e.copyWith(
element: e.element!
.copyWith(scale: newScale))),
);
},
),
),
if (value is TextContext) ...[
const SizedBox(width: 16),
const SizedBox(width: 8),
IconButton(
icon:
const PhosphorIcon(PhosphorIconsLight.article),
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/86.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Add support for multi character input languages ([#539](https://github.com/LinwoodDev/Butterfly/issues/539))
* Add scale to label toolbar
* Add scale to label selection view
* Add markdown element selection view
* Fix moving data directory ([#562](https://github.com/LinwoodDev/Butterfly/issues/562))
* Fix various issues with the label tool

0 comments on commit 264fc40

Please sign in to comment.