1 module rpui.widgets.tree_list.widget; 2 3 import rpui.primitives; 4 import rpui.math; 5 import rpui.widget; 6 import rpui.events; 7 import rpui.widgets.tree_list_node.widget; 8 9 class TreeList : Widget { 10 private TreeListNode selectedNode_ = null; 11 @property TreeListNode selected() { return selectedNode_; } 12 13 @field bool drawLines = true; 14 15 struct Measure { 16 float computedWrapHeight = 0; 17 float nodeLeftOffset; 18 } 19 20 Measure measure; 21 22 this(in string style = "TreeList") { 23 super(style); 24 } 25 26 override void onCreate() { 27 super.onCreate(); 28 29 with (view.theme.tree) { 30 measure.nodeLeftOffset = data.getNumber(style ~ ".nodeLeftOffset.0"); 31 } 32 } 33 34 override void onProgress(in ProgressEvent event) { 35 super.onProgress(event); 36 } 37 38 override void updateSize() { 39 super.updateSize(); 40 41 if (heightType == SizeType.wrapContent) { 42 measure.computedWrapHeight = 0; 43 computeWrapHeight(this); 44 size.y = measure.computedWrapHeight; 45 } 46 } 47 48 private void computeWrapHeight(Widget root) { 49 foreach (Widget widget; root.children) { 50 TreeListNode node = cast(TreeListNode) widget; 51 52 if (node !is null) { 53 measure.computedWrapHeight += widget.size.y; 54 55 if (node.isOpen) { 56 computeWrapHeight(widget); 57 } 58 } else { 59 measure.computedWrapHeight += widget.size.y; 60 computeWrapHeight(widget); 61 } 62 } 63 } 64 }