Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/LinwoodDev/Butterfly int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
CodeDoctorDE committed Jul 20, 2023
2 parents 01b4b87 + 8443cdc commit 40dbe91
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 308 deletions.
12 changes: 9 additions & 3 deletions app/lib/dialogs/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AddDialog extends StatelessWidget {
Wrap(
alignment: WrapAlignment.start,
children: ImportType.values
.where((e) => e.isAvailable())
.map(
(e) => BoxTile(
size: 128,
Expand All @@ -86,13 +87,18 @@ class AddDialog extends StatelessWidget {
IconButton(
onPressed: () =>
addPainter(Painter.asset(importType: e)),
icon:
const PhosphorIcon(PhosphorIconsLight.mapPin),
icon: const PhosphorIcon(
PhosphorIconsLight.pushPin),
),
],
),
icon: PhosphorIcon(e.icon(PhosphorIconsStyle.light)),
onTap: () => showImportAssetWizard(e, context),
onTap: () async {
await showImportAssetWizard(e, context);
if (context.mounted) {
Navigator.of(context).pop();
}
},
),
)
.toList(),
Expand Down
162 changes: 87 additions & 75 deletions app/lib/dialogs/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,81 +24,93 @@ class ElementsDialog extends StatelessWidget {
child: ListView(
shrinkWrap: true,
children: [
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.copySelection(context, true);
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.scissors),
child: Text(AppLocalizations.of(context).cut),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.copySelection(context, false);
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.copy),
child: Text(AppLocalizations.of(context).copy),
),
MenuItemButton(
leadingIcon: const PhosphorIcon(PhosphorIconsLight.copy),
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.transform(
context.read<DocumentBloc>(),
renderers
.map((e) => Renderer.fromInstance(e.element))
.toList(),
null,
true);
},
child: Text(AppLocalizations.of(context).duplicate),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context.read<DocumentBloc>().add(
ElementsRemoved(renderers.map((r) => r.element).toList()));
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.trash),
child: Text(AppLocalizations.of(context).delete),
),
SubmenuButton(
leadingIcon: const Icon(PhosphorIconsLight.layout),
menuStyle: const MenuStyle(alignment: Alignment.centerRight),
menuChildren: Arrangement.values
.map((e) => MenuItemButton(
leadingIcon: Icon(e.icon(PhosphorIconsStyle.light)),
child: Text(e.getLocalizedName(context)),
onPressed: () {
Navigator.of(context).pop(true);
context.read<DocumentBloc>().add(ElementsArranged(
renderers.map((r) => r.element).toList(), e));
},
))
.toList(),
child: Text(AppLocalizations.of(context).arrange),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
if (renderers.isEmpty) return;
final cubit = context.read<CurrentIndexCubit>();
cubit.changeSelection(renderers.first);
renderers.sublist(1).forEach((r) => cubit.insertSelection(r));
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.faders),
child: Text(AppLocalizations.of(context).properties),
),
if (renderers.isEmpty) ...[
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
Actions.invoke(
context, const PasteTextIntent(SelectionChangedCause.tap));
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.clipboard),
child: Text(AppLocalizations.of(context).paste),
),
] else ...[
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.copySelection(context, true);
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.scissors),
child: Text(AppLocalizations.of(context).cut),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.copySelection(context, false);
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.copy),
child: Text(AppLocalizations.of(context).copy),
),
MenuItemButton(
leadingIcon: const PhosphorIcon(PhosphorIconsLight.copy),
onPressed: () {
Navigator.of(context).pop(true);
context
.read<CurrentIndexCubit>()
.fetchHandler<HandHandler>()
?.transform(
context.read<DocumentBloc>(),
renderers
.map((e) => Renderer.fromInstance(e.element))
.toList(),
null,
true);
},
child: Text(AppLocalizations.of(context).duplicate),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
context.read<DocumentBloc>().add(
ElementsRemoved(renderers.map((r) => r.element).toList()));
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.trash),
child: Text(AppLocalizations.of(context).delete),
),
SubmenuButton(
leadingIcon: const Icon(PhosphorIconsLight.layout),
menuStyle: const MenuStyle(alignment: Alignment.centerRight),
menuChildren: Arrangement.values
.map((e) => MenuItemButton(
leadingIcon: Icon(e.icon(PhosphorIconsStyle.light)),
child: Text(e.getLocalizedName(context)),
onPressed: () {
Navigator.of(context).pop(true);
context.read<DocumentBloc>().add(ElementsArranged(
renderers.map((r) => r.element).toList(), e));
},
))
.toList(),
child: Text(AppLocalizations.of(context).arrange),
),
MenuItemButton(
onPressed: () {
Navigator.of(context).pop(true);
if (renderers.isEmpty) return;
final cubit = context.read<CurrentIndexCubit>();
cubit.changeSelection(renderers.first);
renderers.sublist(1).forEach((r) => cubit.insertSelection(r));
},
leadingIcon: const PhosphorIcon(PhosphorIconsLight.faders),
child: Text(AppLocalizations.of(context).properties),
),
],
],
))
]);
Expand Down
3 changes: 0 additions & 3 deletions app/lib/handlers/hand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,6 @@ class HandHandler extends Handler<HandPainter> {
}
context.refresh();
final buildContext = context.buildContext;
if (_selected.isEmpty && buildContext.mounted) {
return;
}
if (buildContext.mounted) {
final result = await showContextMenu<bool>(
context: buildContext,
Expand Down
3 changes: 2 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,6 @@
"rotate": "Rotate",
"spacer": "Spacer",
"navigationRail": "Navigation rail",
"cut": "Cut"
"cut": "Cut",
"paste": "Paste"
}
19 changes: 15 additions & 4 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,21 @@ class ButterflyApp extends StatelessWidget {
},
child: BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.nativeTitleBar != current.nativeTitleBar,
previous.nativeTitleBar != current.nativeTitleBar ||
previous.theme != current.theme,
builder: (context, settings) {
final mediaQuery = MediaQuery.of(context);
if (!kIsWeb && isWindow) {
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setTitleBarStyle(settings.nativeTitleBar
? TitleBarStyle.normal
: TitleBarStyle.hidden);
final brightness = switch (settings.theme) {
ThemeMode.light => Brightness.light,
ThemeMode.dark => Brightness.dark,
ThemeMode.system => mediaQuery.platformBrightness,
};
await windowManager.setBrightness(brightness);
await windowManager.show();
});
}
Expand All @@ -323,7 +331,8 @@ class ButterflyApp extends StatelessWidget {
buildWhen: (previous, current) =>
previous.theme != current.theme ||
previous.localeTag != current.localeTag ||
previous.design != current.design,
previous.design != current.design ||
previous.nativeTitleBar != current.nativeTitleBar,
builder: (context, state) => MaterialApp.router(
locale: state.locale,
title: applicationName,
Expand All @@ -336,8 +345,10 @@ class ButterflyApp extends StatelessWidget {
LeapLocalizations.delegate,
],
builder: (context, child) {
child = virtualWindowFrameBuilder(context, child);
return child;
if (!state.nativeTitleBar) {
child = virtualWindowFrameBuilder(context, child);
}
return child ?? Container();
},
supportedLocales: getLocales(),
themeMode: state.theme,
Expand Down
4 changes: 1 addition & 3 deletions app/lib/renderers/elements/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class ImageRenderer extends Renderer<ImageElement> {
double scaleY = 1,
}) {
return ImageRenderer(element.copyWith(
position: position == null
? element.position
: position.toPoint() - Point(rect.width / 2, rect.height / 2),
position: position?.toPoint() ?? element.position,
rotation: rotation ?? element.rotation,
constraints: element.constraints.scale(scaleX, scaleY),
));
Expand Down
15 changes: 15 additions & 0 deletions app/lib/renderers/elements/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ class MarkdownRenderer extends Renderer<MarkdownElement> {
_tp?.layout(maxWidth: rect.width);
_tp?.paint(canvas, element.getOffset(rect.height).toOffset());
}

@override
MarkdownRenderer _transform({
Offset? position,
double? rotation,
double scaleX = 1,
double scaleY = 1,
}) =>
MarkdownRenderer(
element.copyWith(
position:
element.position + (position?.toPoint() ?? const Point(0, 0)),
rotation: rotation ?? element.rotation,
),
context);
}
20 changes: 8 additions & 12 deletions app/lib/renderers/elements/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,14 @@ class TextRenderer extends Renderer<TextElement> {
double? rotation,
double scaleX = 1,
double scaleY = 1,
}) {
// final size = Size(rect.width * scaleX, rect.height * scaleY);
final next = position == null
? element.position + (position?.toPoint() ?? const Point(0, 0))
: position.toPoint();
return TextRenderer(
element.copyWith(
position: next,
rotation: rotation ?? element.rotation,
),
context);
}
}) =>
TextRenderer(
element.copyWith(
position:
element.position + (position?.toPoint() ?? const Point(0, 0)),
rotation: rotation ?? element.rotation,
),
context);

@override
void dispose() {
Expand Down
15 changes: 6 additions & 9 deletions app/lib/views/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,6 @@ class _MainBody extends StatelessWidget {
return Stack(
children: [
const MainViewViewport(),
if (!isMobile && constraints.maxHeight >= 500)
Positioned(
right: pos == ToolbarPosition.right ? 75 : 0,
top: 0,
child: const PropertyView()),
Row(
children: [
if (isLarge &&
Expand All @@ -438,10 +433,12 @@ class _MainBody extends StatelessWidget {
toolbar,
if (pos == ToolbarPosition.top || isMobile)
const ToolbarView(),
Expanded(
child: isMobile || constraints.maxHeight < 500
? const PropertyView()
: const SizedBox.shrink()),
const Expanded(
child: Align(
alignment: Alignment.topRight,
child: PropertyView(),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"@docusaurus/preset-classic": "2.4.1",
"@docusaurus/theme-common": "2.4.1",
"@mdx-js/react": "^1",
"@swc/core": "^1.3.68",
"@swc/core": "^1.3.69",
"animate.css": "^4.1.1",
"clsx": "^1.2.1",
"clsx": "^2.0.0",
"node-fetch": "^3.3.1",
"prism-react-renderer": "^2.0.6",
"react": "^18.2.0",
Expand Down

0 comments on commit 40dbe91

Please sign in to comment.