87 lines
2.9 KiB
Dart
87 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../layout/layout_models.dart';
|
|
import '../routing/route_models.dart';
|
|
|
|
/// Centralized graph spacing, not component dimensions. Rank separation follows
|
|
/// actual native label measurements at any text scale.
|
|
GraphLayoutConfig graphCanvasLayoutConfig(Iterable<LabelExtent> labels) {
|
|
final widest = labels.fold<double>(
|
|
0,
|
|
(width, label) => label.width > width ? label.width : width,
|
|
);
|
|
final routing = graphCanvasRoutingConfig();
|
|
return GraphLayoutConfig(
|
|
columnGap: widest + 2 * (routing.nodeClearance + routing.labelGap) + 24,
|
|
rowGap: 24,
|
|
padding: 24,
|
|
);
|
|
}
|
|
|
|
RoutingConfig graphCanvasRoutingConfig() => RoutingConfig(
|
|
nodeClearance: 12,
|
|
laneSpacing: 28,
|
|
corridorSpacing: 20,
|
|
portSpacing: 12,
|
|
labelGap: 6,
|
|
boundsPadding: 12,
|
|
);
|
|
|
|
/// The native theme roles one definition graph canvas needs.
|
|
///
|
|
/// No palette, font family or size is defined here: every value comes from the
|
|
/// ambient Material or Cupertino theme, so light/dark and text scaling follow
|
|
/// the host exactly. Edge labels and diagnostics are metadata, so they use the
|
|
/// host's secondary-label role rather than the node's own label style.
|
|
class GraphCanvasStyle {
|
|
const GraphCanvasStyle({
|
|
required this.labelStyle,
|
|
required this.messageStyle,
|
|
required this.edgeColor,
|
|
required this.edgeWidth,
|
|
});
|
|
|
|
factory GraphCanvasStyle.of(BuildContext context) {
|
|
if (usesCupertinoHost(context)) {
|
|
final theme = CupertinoTheme.of(context);
|
|
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
|
return GraphCanvasStyle(
|
|
labelStyle: theme.textTheme.tabLabelTextStyle.copyWith(
|
|
color: secondary,
|
|
),
|
|
messageStyle: theme.textTheme.textStyle.copyWith(color: secondary),
|
|
edgeColor: CupertinoColors.separator.resolveFrom(context),
|
|
// Cupertino has no divider-thickness token; its separators are one
|
|
// logical pixel hairlines, so the stroke keeps that native default.
|
|
edgeWidth: 1,
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
final secondary = theme.colorScheme.onSurfaceVariant;
|
|
return GraphCanvasStyle(
|
|
labelStyle: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
|
|
color: secondary,
|
|
),
|
|
messageStyle: (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
|
|
color: secondary,
|
|
),
|
|
edgeColor: theme.colorScheme.outline,
|
|
edgeWidth: theme.dividerTheme.thickness ?? 1,
|
|
);
|
|
}
|
|
|
|
/// Style of one routed outcome label.
|
|
final TextStyle labelStyle;
|
|
|
|
/// Style of the empty-state and skipped-edge messages.
|
|
final TextStyle messageStyle;
|
|
|
|
/// Native outline/separator color for the routed edges.
|
|
final Color edgeColor;
|
|
|
|
/// Native hairline thickness for the routed edges and their arrows.
|
|
final double edgeWidth;
|
|
}
|