import 'dart:math' as math; import 'package:cutdex/l10n/l10n.dart'; import 'package:cutdex_sdk/editor.dart'; import 'package:cutdex_sdk/timeline/model.dart'; import 'package:cutdex_ui/icons.dart'; import 'package:cutdex_ui/widgets.dart'; import 'package:flutter/material.dart'; typedef PropertyKeyframeEdit = Future Function( List ids, { KeyframeAction? action, ParameterInterpolation? interpolation, }); /// Keyframe controls share channel state and intent callbacks across property fields. class PropertyKeyframeControls { const PropertyKeyframeControls({ required this.stack, required this.enabled, required this.onEdit, required this.onSeek, }); final ClipParameterAnimation stack; final bool enabled; final PropertyKeyframeEdit onEdit; final Future Function(int localTick) onSeek; Widget button( BuildContext context, List ids, String label, String id, ) => IconButton( key: ValueKey(id), tooltip: context.l10n.toggleKeyframe( stack.keyed(ids) ? context.l10n.delete : context.l10n.addKeyframeAction, label, ), isSelected: stack.keyed(ids), color: stack.animated(ids) ? Theme.of(context).colorScheme.primary : null, icon: Transform.rotate( angle: math.pi / 4, child: Icon( stack.keyed(ids) ? AppIcons.squareFilled : AppIcons.square, size: 12, ), ), onPressed: enabled && ids.isNotEmpty ? () => onEdit(ids) : null, ); Widget menu(BuildContext context, List ids, String label, String id) { final offsets = stack.keyOffsets(ids); final currentTick = stack.localTick; final previous = offsets.where((t) => t < currentTick).lastOrNull; final next = offsets.where((t) => t > currentTick).firstOrNull; return AppDropdownMenu( enabled: enabled, builder: (context, toggle, focus) => IconButton( key: ValueKey('$id-menu'), focusNode: focus, tooltip: context.l10n.keyframeSettings(label), onPressed: enabled ? toggle : null, icon: const Icon(AppIcons.more, size: 16), ), items: [ AppMenuItem( closeAncestors: false, label: context.l10n.previousKeyframe(label), onPressed: previous == null ? null : () => onSeek(previous), ), AppMenuItem( closeAncestors: false, label: context.l10n.nextKeyframe(label), onPressed: next == null ? null : () => onSeek(next), ), for (final (mode, text) in [ (ParameterInterpolation.linear, context.l10n.linear), (ParameterInterpolation.hold, context.l10n.hold), (ParameterInterpolation.easeIn, context.l10n.easeIn), (ParameterInterpolation.easeOut, context.l10n.easeOut), (ParameterInterpolation.easeInOut, context.l10n.easeInOut), ]) AppMenuItem( closeAncestors: false, label: text, onPressed: stack.keyed(ids) ? () => onEdit( ids, action: KeyframeAction.set, interpolation: mode, ) : null, ), AppMenuItem( closeAncestors: false, label: context.l10n.removeAllKeyframes, onPressed: stack.animated(ids) ? () => onEdit(ids, action: KeyframeAction.clear) : null, ), ], ); } }