calculateContentWidth<T> static method

double calculateContentWidth<T>({
  1. required List<Node<T>> nodes,
  2. required FolderViewTextTheme textTheme,
  3. double linePaintWidth = 20.0,
  4. double iconSize = 20.0,
  5. double spacing = 8.0,
  6. double leftPadding = 0.0,
  7. double rightPadding = 16.0,
  8. double maxWidth = double.infinity,
})

Calculate the total content width of all nodes

Implementation

static double calculateContentWidth<T>({
  required List<Node<T>> nodes,
  required FolderViewTextTheme textTheme,
  double linePaintWidth = 20.0,
  double iconSize = 20.0,
  double spacing = 8.0,
  double leftPadding = 0.0,
  double rightPadding = 16.0,
  double maxWidth = double.infinity,
}) {
  double maxNodeWidth = 0.0;

  for (var node in nodes) {
    final nodeWidth = _calculateNodeWidth(
      node: node,
      textTheme: textTheme,
      depth: 0,
      linePaintWidth: linePaintWidth,
      iconSize: iconSize,
      spacing: spacing,
      rightPadding: rightPadding,
    );
    if (nodeWidth > maxNodeWidth) {
      maxNodeWidth = nodeWidth;
    }

    // Recursively check children if expanded
    if (node.isExpanded && node.children.isNotEmpty) {
      final childrenWidth = calculateContentWidth(
        nodes: node.children,
        textTheme: textTheme,
        linePaintWidth: linePaintWidth,
        iconSize: iconSize,
        spacing: spacing,
        leftPadding: 0.0, // Children don't need extra left padding
        rightPadding: rightPadding,
        maxWidth: maxWidth,
      );
      // Add one level of indentation for children
      final adjustedChildWidth = childrenWidth + linePaintWidth;
      if (adjustedChildWidth > maxNodeWidth) {
        maxNodeWidth = adjustedChildWidth;
      }
    }
  }

  // Add left and right padding to the final width
  final totalWidth = leftPadding + maxNodeWidth;
  return totalWidth.clamp(0.0, maxWidth);
}