public TreeNode(ThemeConfig theme, bool useIcon = true, TreeNode nodeParent = null) : base(FlowDirection.TopToBottom) { this.HAnchor = HAnchor.Fit | HAnchor.Left; this.VAnchor = VAnchor.Fit; this.NodeParent = nodeParent; this.TitleBar = new FlowLayoutWidget(); this.TitleBar.Click += (s, e) => { if (TreeView != null) { TreeView.SelectedNode = this; } this.TreeView.NotifyItemClicked(this.TitleBar, e); }; this.TitleBar.MouseDown += (s, e) => { if (TreeView != null && e.Button == MouseButtons.Left && e.Clicks == 2) { TreeView.SelectedNode = this; this.TreeView.NotifyItemDoubleClicked(this.TitleBar, e); } }; this.AddChild(this.TitleBar); // add a check box expandWidget = new TreeExpandWidget(theme) { Expandable = GetNodeCount(false) != 0, VAnchor = VAnchor.Fit | VAnchor.Center, Height = 16, Width = 16 }; expandWidget.Click += (s, e) => { this.Expanded = !this.Expanded; expandWidget.Expanded = this.Expanded; }; this.TitleBar.AddChild(expandWidget); this.HighlightRegion = new FlowLayoutWidget() { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Fit, Padding = useIcon ? new BorderDouble(2) : new BorderDouble(4, 2), Selectable = false }; this.TitleBar.AddChild(this.HighlightRegion); // add a check box if (useIcon) { _image = new ImageBuffer(16, 16); this.HighlightRegion.AddChild(imageWidget = new ImageWidget(this.Image, listenForImageChanged: false) { VAnchor = VAnchor.Center, Margin = new BorderDouble(right: 4), Selectable = false }); } this.HighlightRegion.AddChild(textWidget = new TextWidget(this.Text, pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { Selectable = false, AutoExpandBoundsToText = true, VAnchor = VAnchor.Center }); content = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Fit | HAnchor.Left, Visible = false, // content starts out not visible Name = "content", Margin = new BorderDouble(12, 3), }; this.AddChild(content); // Register listeners this.Nodes.CollectionChanged += this.Nodes_CollectionChanged; }
public TreeNode(ThemeConfig theme, bool useIcon = true) : base(FlowDirection.TopToBottom) { this.HAnchor = HAnchor.Fit | HAnchor.Left; this.VAnchor = VAnchor.Fit; this.TitleBar = new FlowLayoutWidget(); this.TitleBar.Click += (s, e) => { if (TreeView != null) { TreeView.SelectedNode = this; } this.TreeView.NotifyItemClicked(this.TitleBar, e); }; this.AddChild(this.TitleBar); // add a check box expandWidget = new TreeExpandWidget(theme) { Expandable = GetNodeCount(false) != 0, VAnchor = VAnchor.Fit, Height = 16, Width = 16 }; var expandCheckBox = new CheckBox(expandWidget) { Checked = this.Expanded, VAnchor = VAnchor.Center, }; this.ExpandedChanged += (s, e) => { expandWidget.Expanded = this.Expanded; expandCheckBox.Checked = this.Expanded; }; expandCheckBox.CheckedStateChanged += (s, e) => { Expanded = expandCheckBox.Checked; }; this.TitleBar.AddChild(expandCheckBox); this.HighlightRegion = new FlowLayoutWidget() { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Fit, Padding = useIcon ? 0 : new BorderDouble(4, 2), Selectable = false }; this.TitleBar.AddChild(this.HighlightRegion); // add a check box if (useIcon) { _image = new ImageBuffer(16, 16); this.HighlightRegion.AddChild(imageWidget = new ImageWidget(this.Image) { VAnchor = VAnchor.Center, BackgroundColor = new Color(theme.Colors.PrimaryTextColor, 12), Margin = 2, Selectable = false }); } ; this.HighlightRegion.AddChild(textWidget = new TextWidget(this.Text, pointSize: theme.DefaultFontSize, textColor: theme.Colors.PrimaryTextColor) { Selectable = false, AutoExpandBoundsToText = true, VAnchor = VAnchor.Center }); content = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Fit | HAnchor.Left, Visible = false, // content starts out not visible Name = "content", Margin = new BorderDouble(12, 3), }; AddChild(content); Nodes.CollectionChanged += (s, e) => isDirty = true; }