dark_theme.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:flutter/painting.dart';
  2. import '../../../style/index.dart';
  3. import '../index.dart';
  4. ///
  5. /// 黑暗主题
  6. ///
  7. class DarkTheme extends BaseTheme {
  8. DarkTheme(): super('dark-theme', 66.0, 44.0) {
  9. //暗黑背景色
  10. canvasBackgroundColor = AppColor.o2Dark;
  11. // 线条颜色
  12. lineColor = const Color.fromARGB(255, 217, 217, 217);
  13. //文字样式
  14. rootTextStyle = TextStyle(
  15. color: rootTextColor,
  16. fontSize: rootFontSize,
  17. fontWeight: FontWeight.bold,
  18. );
  19. secondTextStyle = TextStyle(
  20. color: secondTextColor,
  21. fontSize: secondFontSize
  22. );
  23. nodeTextStyle = TextStyle(
  24. color: nodeTextColor,
  25. fontSize: nodeFontSize
  26. );
  27. }
  28. final scale = 1.0;
  29. // 中心节点
  30. final _rectCircularBase = 5.0;//圆角
  31. double get rectCircular => _rectCircularBase * scale;//圆角
  32. // 中心节点填充颜色
  33. Color rootRectColor = const Color.fromARGB(255, 89, 149, 247);
  34. // 中心节点文字颜色
  35. Color rootTextColor = const Color(0xFFFFFFFF);
  36. // 中心节点文字样式
  37. late TextStyle rootTextStyle;
  38. // 二级节点填充颜色
  39. Color secondRectColor = const Color.fromARGB(255, 255, 255, 255);
  40. // 二级节点文字颜色
  41. Color secondTextColor = const Color.fromARGB(255, 68, 68, 68);
  42. // 节点文字样式
  43. late TextStyle secondTextStyle;
  44. // 节点文字颜色
  45. Color nodeTextColor = const Color.fromARGB(255, 251, 251, 251);
  46. // 节点文字样式
  47. late TextStyle nodeTextStyle;
  48. @override
  49. NodePaintElement calElementSize(Node root) {
  50. var data = root.data;
  51. NodePaintElement rootPaint = sizeNode(data, NodePaintElement.rootLevel);
  52. var children = root.children;
  53. var list = <NodePaintElement>[];
  54. for(var node in children) {
  55. var child = recursiveNode(node, NodePaintElement.rootLevel + 1);
  56. list.add(child);
  57. }
  58. rootPaint.children = list;
  59. return rootPaint;
  60. }
  61. ///
  62. /// 递归Node
  63. ///
  64. NodePaintElement recursiveNode(Node node, int level) {
  65. var data = node.data;
  66. NodePaintElement nodePaint = sizeNode(data, level);
  67. var children = node.children;
  68. if(children.isNotEmpty) {
  69. var list = <NodePaintElement>[];
  70. for(var child in children) {
  71. var ret = (recursiveNode(child, level + 1)); // children
  72. list.add(ret);
  73. }
  74. nodePaint.children = list;
  75. }
  76. return nodePaint;
  77. }
  78. ///
  79. /// Node内部元素 计算
  80. ///
  81. @override
  82. NodePaintElement sizeNode(NodeData data, int level) {
  83. var elements = Map<NodeElement, PaintElement>();
  84. var nodeWidth = 0.0;
  85. var nodeHeight = 0.0;
  86. ///文字
  87. ///
  88. if (level == 0) { //root
  89. var textPainter = TextPainter(
  90. text: TextSpan(style: rootTextStyle, text: data.text),
  91. textDirection: TextDirection.ltr,
  92. textAlign: TextAlign.center)
  93. ..layout();
  94. elements[NodeElement.text] = TextPaintElement(textPainter);
  95. nodeHeight += textPainter.height;
  96. nodeWidth += textPainter.width;
  97. }else if (level == 1) { //
  98. var textPainter = TextPainter(
  99. text: TextSpan(style: secondTextStyle, text: data.text),
  100. textDirection: TextDirection.ltr,
  101. textAlign: TextAlign.center)
  102. ..layout();
  103. elements[NodeElement.text] = TextPaintElement(textPainter);
  104. nodeHeight += textPainter.height;
  105. nodeWidth += textPainter.width;
  106. }else {
  107. var textPainter = TextPainter(
  108. text: TextSpan(style: nodeTextStyle, text: data.text),
  109. textDirection: TextDirection.ltr,
  110. textAlign: TextAlign.center)
  111. ..layout();
  112. elements[NodeElement.text] = TextPaintElement(textPainter);
  113. nodeHeight += textPainter.height;
  114. nodeWidth += textPainter.width;
  115. }
  116. ///
  117. /// 进度
  118. ///
  119. if(data.progress != null && data.progress! > 0) {
  120. Rect rect = Rect.fromLTWH(0.0, 0.0, progressIconSize, progressIconSize);
  121. PaintStyle style = PaintStyle(color: rootTextColor, style: PaintingStyle.fill);
  122. elements[NodeElement.progress] = ImagePaintElement(rect, style);
  123. nodeHeight = nodeHeight > progressIconSize ? nodeHeight : progressIconSize;
  124. nodeWidth += progressIconSize + elementGap;
  125. }
  126. ///
  127. /// 优先级
  128. ///
  129. if(data.priority != null && data.priority! > 0) {
  130. Rect rect = Rect.fromLTWH(0.0, 0.0, priorityIconSize, priorityIconSize);
  131. PaintStyle style = PaintStyle(color: rootTextColor, style: PaintingStyle.fill);
  132. elements[NodeElement.priority] = ImagePaintElement(rect, style);
  133. nodeHeight = nodeHeight > priorityIconSize ? nodeHeight : priorityIconSize;
  134. nodeWidth += priorityIconSize + elementGap;
  135. }
  136. ///
  137. /// 超链接
  138. ///
  139. if(data.hyperlink != null ) {
  140. Rect rect = Rect.fromLTWH(0.0, 0.0, linkIconSize, linkIconSize);
  141. PaintStyle style = PaintStyle(color: rootTextColor, style: PaintingStyle.fill);
  142. elements[NodeElement.hyperlink] = ImagePaintElement(rect, style);
  143. nodeHeight = nodeHeight > linkIconSize ? nodeHeight : linkIconSize;
  144. nodeWidth += linkIconSize + elementGap;
  145. }
  146. ///
  147. /// 图片
  148. ///
  149. if( (data.image != null && data.image!.isNotEmpty) || (data.imageId != null && data.imageId!.isNotEmpty)) {
  150. var size = data.imageSize ?? ImageSize(width: 40, height: 40);
  151. Rect rect = Rect.fromLTWH(0.0, 0.0, size.width.toDouble(), size.height.toDouble());
  152. PaintStyle style = PaintStyle(color: rootTextColor, style: PaintingStyle.fill);
  153. elements[NodeElement.image] = ImagePaintElement(rect, style);
  154. nodeHeight += size.height.toDouble() + elementGap;
  155. nodeWidth = size.width > nodeWidth ? size.width.toDouble() : nodeWidth;
  156. }
  157. ///
  158. /// 节点外框
  159. ///
  160. if (level == 0) { // root没有设置id
  161. data.id = NodePaintElement.rootId;
  162. nodeWidth += rootRectPadding*2;
  163. nodeHeight += rootRectPadding*2;
  164. Rect rect = Rect.fromLTWH(0.0, 0.0, nodeWidth, nodeHeight);
  165. PaintStyle style = PaintStyle(color: rootRectColor, style: PaintingStyle.fill);
  166. elements[NodeElement.background] = RRectPaintElement(RRect.fromRectAndRadius(rect, Radius.circular(rectCircular)), style);
  167. }else if(level == 1) { // 二级
  168. nodeWidth += secondRectPadding*2;
  169. nodeHeight += secondRectPadding*2;
  170. Rect rect = Rect.fromLTWH(0.0, 0.0, nodeWidth, nodeHeight);
  171. PaintStyle style = PaintStyle(color: secondRectColor, style: PaintingStyle.fill);
  172. elements[NodeElement.background] = RRectPaintElement(RRect.fromRectAndRadius(rect, Radius.circular(rectCircular)), style);
  173. }else {
  174. nodeWidth += nodeRectPadding*2;
  175. nodeHeight += nodeRectPadding*2;
  176. }
  177. return NodePaintElement(
  178. level: level,
  179. data:data,
  180. paintElements:elements,
  181. nodeSize:Size(nodeWidth, nodeHeight)
  182. );
  183. }
  184. }