Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
289 lines
10 KiB
Dart
289 lines
10 KiB
Dart
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:cutdex_ui/icons.dart';
|
|
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
class PropertyLayerRow extends StatefulWidget {
|
|
const PropertyLayerRow({
|
|
super.key,
|
|
required this.id,
|
|
required this.prefix,
|
|
required this.index,
|
|
required this.enabled,
|
|
required this.visible,
|
|
required this.label,
|
|
required this.tooltip,
|
|
required this.onVisibility,
|
|
required this.onRemove,
|
|
required this.menuItems,
|
|
required this.editor,
|
|
this.leading,
|
|
this.editorLabel,
|
|
});
|
|
final String id, prefix, label, tooltip;
|
|
final int index;
|
|
final bool enabled, visible;
|
|
final VoidCallback onVisibility, onRemove;
|
|
final List<AppMenuItem> menuItems;
|
|
final Widget editor;
|
|
final Widget? leading;
|
|
final String? editorLabel;
|
|
|
|
@override
|
|
State<PropertyLayerRow> createState() => _PropertyLayerRowState();
|
|
}
|
|
|
|
class _PropertyLayerRowState extends State<PropertyLayerRow> {
|
|
final _menu = MenuController();
|
|
final _focus = FocusNode();
|
|
bool _hovered = false;
|
|
|
|
@override
|
|
void dispose() {
|
|
_focus.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final colors = theme.colorScheme;
|
|
return MenuAnchor(
|
|
controller: _menu,
|
|
childFocusNode: _focus,
|
|
clipBehavior: Clip.none,
|
|
// Place the editor beside the inspector, as in Figma's effects panel.
|
|
alignmentOffset: Offset(
|
|
-240 - 8 - AppTheme.propertySectionPadding(context).left,
|
|
0,
|
|
),
|
|
style: const MenuStyle(
|
|
alignment: AlignmentDirectional.topStart,
|
|
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
|
backgroundColor: WidgetStatePropertyAll(Colors.transparent),
|
|
surfaceTintColor: WidgetStatePropertyAll(Colors.transparent),
|
|
elevation: WidgetStatePropertyAll(0),
|
|
side: WidgetStatePropertyAll(BorderSide.none),
|
|
shape: WidgetStatePropertyAll(
|
|
RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
),
|
|
),
|
|
),
|
|
onOpen: () => setState(() {}),
|
|
onClose: () => setState(() {}),
|
|
menuChildren: [
|
|
SizedBox(
|
|
key: ValueKey('${widget.prefix}-editor-${widget.id}'),
|
|
width: 240,
|
|
child: Material(
|
|
color: colors.surfaceContainerLow,
|
|
surfaceTintColor: Colors.transparent,
|
|
elevation: 8,
|
|
shadowColor: colors.shadow.withValues(alpha: .25),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
side: BorderSide(color: colors.outlineVariant),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Focus(
|
|
autofocus: true,
|
|
onKeyEvent: (_, event) {
|
|
if (event is KeyDownEvent &&
|
|
event.logicalKey == LogicalKeyboardKey.escape) {
|
|
_menu.close();
|
|
return KeyEventResult.handled;
|
|
}
|
|
return KeyEventResult.ignored;
|
|
},
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(
|
|
height: 40,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 16, right: 8),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
widget.editorLabel ?? widget.label,
|
|
style: AppTheme.propertySectionTitleStyle(
|
|
context,
|
|
),
|
|
),
|
|
),
|
|
AppDropdownMenu(
|
|
builder: (context, toggle, focus) => IconButton(
|
|
focusNode: focus,
|
|
tooltip: widget.tooltip,
|
|
icon: const Icon(AppIcons.more, size: 16),
|
|
onPressed: toggle,
|
|
),
|
|
items: widget.menuItems,
|
|
),
|
|
IconButton(
|
|
key: ValueKey(
|
|
'${widget.prefix}-editor-close-${widget.id}',
|
|
),
|
|
tooltip: context.l10n.close,
|
|
icon: const Icon(AppIcons.close, size: 16),
|
|
onPressed: _menu.close,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Divider(height: 1, color: theme.dividerColor),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxHeight: (MediaQuery.sizeOf(context).height - 120)
|
|
.clamp(80, 600),
|
|
),
|
|
child: SingleChildScrollView(
|
|
primary: false,
|
|
child: widget.editor,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
builder: (context, controller, child) => MouseRegion(
|
|
onEnter: (_) => setState(() => _hovered = true),
|
|
onExit: (_) => setState(() => _hovered = false),
|
|
child: SizedBox(
|
|
height: AppInspectorMetrics.row,
|
|
child: Row(
|
|
children: [
|
|
ReorderableDragStartListener(
|
|
key: ValueKey('${widget.prefix}-drag-${widget.id}'),
|
|
index: widget.index,
|
|
enabled: widget.enabled,
|
|
child: MouseRegion(
|
|
cursor: widget.enabled
|
|
? SystemMouseCursors.grab
|
|
: SystemMouseCursors.basic,
|
|
child: SizedBox(
|
|
width: 16,
|
|
child: Icon(
|
|
AppIcons.dragHandle,
|
|
size: 12,
|
|
color: _hovered
|
|
? colors.onSurfaceVariant
|
|
: Colors.transparent,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextButton(
|
|
key: ValueKey('${widget.prefix}-settings-${widget.id}'),
|
|
focusNode: _focus,
|
|
style: TextButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
minimumSize: const Size(0, 24),
|
|
maximumSize: const Size(double.infinity, 24),
|
|
backgroundColor: controller.isOpen
|
|
? theme.inputDecorationTheme.fillColor
|
|
: null,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
),
|
|
foregroundColor: widget.visible
|
|
? colors.onSurface
|
|
: colors.onSurfaceVariant,
|
|
textStyle: AppTheme.inputTextStyle(context),
|
|
),
|
|
onPressed: () => controller.isOpen
|
|
? controller.close()
|
|
: controller.open(),
|
|
child: Row(
|
|
children: [
|
|
widget.leading ??
|
|
const Icon(PhosphorIconsRegular.sun, size: 16),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
widget.label,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
key: ValueKey('${widget.prefix}-enabled-${widget.id}'),
|
|
tooltip: widget.visible
|
|
? context.l10n.disable
|
|
: context.l10n.enable,
|
|
icon: Icon(
|
|
widget.visible
|
|
? Icons.visibility_outlined
|
|
: Icons.visibility_off_outlined,
|
|
size: 16,
|
|
),
|
|
onPressed: widget.enabled ? widget.onVisibility : null,
|
|
),
|
|
IconButton(
|
|
key: ValueKey('${widget.prefix}-remove-${widget.id}'),
|
|
tooltip: context.l10n.delete,
|
|
icon: const Icon(AppIcons.remove, size: 16),
|
|
onPressed: widget.enabled ? widget.onRemove : null,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@Preview(name: 'Effect row / desktop', size: Size(560, 480))
|
|
Widget effectRowPreview() => MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
theme: AppTheme.propertiesPanelTheme(
|
|
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
|
),
|
|
home: Scaffold(
|
|
body: Align(
|
|
alignment: Alignment.topRight,
|
|
child: SizedBox(
|
|
width: 240,
|
|
child: ReorderableListView(
|
|
shrinkWrap: true,
|
|
onReorderItem: (_, _) {},
|
|
buildDefaultDragHandles: false,
|
|
children: [
|
|
PropertyLayerRow(
|
|
key: const ValueKey('preview-effect'),
|
|
id: 'preview',
|
|
prefix: 'effect',
|
|
index: 0,
|
|
enabled: true,
|
|
visible: true,
|
|
label: 'Drop shadow',
|
|
tooltip: 'Effects',
|
|
onVisibility: () {},
|
|
onRemove: () {},
|
|
menuItems: const [],
|
|
editor: const Text('X 0 Y 4 Blur 8'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|