mind_map_theme.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import 'dart:ui' as ui;
  2. import 'package:flutter/painting.dart';
  3. import 'package:o2_flutter/common/models/mindmap/mind_node.dart';
  4. enum ElementType {
  5. text,
  6. image,
  7. rect,
  8. rrect,
  9. circle,
  10. line
  11. }
  12. ///
  13. /// 画笔样式
  14. /// 每个对象的画笔样式 就是画笔的一些属性 比如color style strokeWidth等等
  15. ///
  16. class PaintStyle {
  17. static const double defaultStrokeWidth = 2.0;
  18. final ui.Color color;
  19. final ui.PaintingStyle style;
  20. final double strokeWidth;
  21. PaintStyle({ required this.color, required this.style, this.strokeWidth = defaultStrokeWidth });
  22. }
  23. ///
  24. /// 需要画出来的元素
  25. ///
  26. class PaintElement {
  27. final ElementType type;
  28. PaintElement(this.type);
  29. }
  30. ///
  31. /// 文字对象
  32. ///
  33. class TextPaintElement extends PaintElement {
  34. TextPainter painter;
  35. Offset? offset;
  36. TextPaintElement(this.painter): super(ElementType.text);
  37. }
  38. ///
  39. /// 图片对象
  40. ///
  41. class ImagePaintElement extends PaintElement {
  42. ui.Rect rect;
  43. PaintStyle style;
  44. ui.Image? image;
  45. ImagePaintElement(this.rect, this.style): super(ElementType.image);
  46. }
  47. ///
  48. /// 方块对象
  49. ///
  50. class RectPaintElement extends PaintElement {
  51. ui.Rect rect;
  52. PaintStyle style;
  53. RectPaintElement(this.rect, this.style): super(ElementType.rect);
  54. }
  55. ///
  56. /// 圆角方块对象
  57. ///
  58. class RRectPaintElement extends PaintElement {
  59. ui.RRect rrect;
  60. PaintStyle style;
  61. RRectPaintElement(this.rrect, this.style): super(ElementType.rrect);
  62. }
  63. ///
  64. /// 圆对象
  65. ///
  66. class CirclePaintElement extends PaintElement {
  67. ui.Offset center;
  68. double radius;
  69. PaintStyle style;
  70. CirclePaintElement(this.center, this.radius, this.style): super(ElementType.circle);
  71. }
  72. ///
  73. /// 线条对象
  74. ///
  75. class LinePaintElement extends PaintElement {
  76. List<NodeConnectLine> lines;
  77. PaintStyle style;
  78. LinePaintElement(this.lines, this.style): super(ElementType.line);
  79. }
  80. ///
  81. /// 节点绘画对象
  82. ///
  83. class NodePaintElement {
  84. static const rootParent ='-1';
  85. static const rootId = 'root';
  86. static const rootLevel = 0;
  87. int level;
  88. NodeData data;
  89. Map<NodeElement, PaintElement> paintElements;
  90. Size nodeSize; // 节点本身大小
  91. Offset? offset;// 节点offset
  92. Size? childrenSize; // 所有子节点占的大小范围 这个需要在模版中计算
  93. List<NodePaintElement>? children;
  94. NodePaintElement({required this.level, required this.data, required this.paintElements, required this.nodeSize});
  95. Map<String, dynamic> toJson() {
  96. var map = Map<String, dynamic>();
  97. if(children!=null && children?.isNotEmpty == true) {
  98. var jsonChildren = <Map<String, dynamic>>[];
  99. for(var i=0;i<children!.length;i++) {
  100. jsonChildren.add(children![i].toJson());
  101. }
  102. map['children'] = jsonChildren;
  103. }
  104. map['data'] = data.toJson();
  105. return map;
  106. }
  107. }
  108. ///
  109. /// 节点连接线
  110. ///
  111. class NodeConnectLine {
  112. final Offset start;
  113. final Offset end;
  114. NodeConnectLine(this.start, this.end);
  115. }
  116. abstract class BaseTheme {
  117. final String name;
  118. final double nodeVerticalSpace;
  119. final double nodeHorizontalSpace;
  120. double lineWidth = 2.0; //默认线条宽度
  121. double elementGap = 5.0;// 节点内部元素的间距
  122. double linkIconSize = 20.0; // 超链接图标
  123. double progressIconSize = 20.0; //进度图片大小
  124. double priorityIconSize = 20.0;// 优先级图片大小
  125. double rootRectPadding = 20.0;
  126. // 中心节点字体大小
  127. double rootFontSize = 22.0;
  128. // 二级节点
  129. double secondRectPadding = 10.0;
  130. // 二级节点文字大小
  131. double secondFontSize = 18.0;
  132. // 三级以及后面的节点
  133. double nodeRectPadding = 5.0;
  134. // 节点文字大小
  135. double nodeFontSize = 14.0;
  136. ///color
  137. // 画布背景色
  138. Color canvasBackgroundColor = const Color.fromARGB(255, 255, 255, 255); //默认白色背景
  139. // 线条颜色 二级节点边框线颜色
  140. Color lineColor = const Color.fromARGB(255, 115, 161, 191);
  141. BaseTheme(this.name, this.nodeVerticalSpace, this.nodeHorizontalSpace);
  142. NodePaintElement calElementSize(Node root);
  143. NodePaintElement sizeNode(NodeData data, int level);
  144. }