Show widget tree, directly handle draw, revise size & position
This commit is contained in:
parent
a686e0ae2d
commit
dccc9c8624
3 changed files with 93 additions and 27 deletions
|
|
@ -769,6 +769,8 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
// Otherwise open
|
||||
inspectForm = new InspectForm(this);
|
||||
inspectForm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||
inspectForm.Location = new System.Drawing.Point(0, 0);
|
||||
inspectForm.FormClosed += (s, e2) =>
|
||||
{
|
||||
inspectForm = null;
|
||||
|
|
|
|||
10
Utilities/InspectForm.Designer.cs
generated
10
Utilities/InspectForm.Designer.cs
generated
|
|
@ -58,8 +58,8 @@
|
|||
this.splitContainer1.Panel2.Controls.Add(this.toolStrip1);
|
||||
this.splitContainer1.Panel2.Controls.Add(this.propertyGrid1);
|
||||
this.splitContainer1.Panel2.Padding = new System.Windows.Forms.Padding(0, 27, 0, 0);
|
||||
this.splitContainer1.Size = new System.Drawing.Size(951, 632);
|
||||
this.splitContainer1.SplitterDistance = 589;
|
||||
this.splitContainer1.Size = new System.Drawing.Size(440, 632);
|
||||
this.splitContainer1.SplitterDistance = 169;
|
||||
this.splitContainer1.SplitterWidth = 3;
|
||||
this.splitContainer1.TabIndex = 0;
|
||||
//
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
this.treeView1.Location = new System.Drawing.Point(0, 0);
|
||||
this.treeView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.treeView1.Name = "treeView1";
|
||||
this.treeView1.Size = new System.Drawing.Size(589, 632);
|
||||
this.treeView1.Size = new System.Drawing.Size(169, 632);
|
||||
this.treeView1.TabIndex = 0;
|
||||
this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);
|
||||
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
|
||||
|
|
@ -119,7 +119,7 @@
|
|||
this.propertyGrid1.Location = new System.Drawing.Point(0, 27);
|
||||
this.propertyGrid1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.propertyGrid1.Name = "propertyGrid1";
|
||||
this.propertyGrid1.Size = new System.Drawing.Size(359, 605);
|
||||
this.propertyGrid1.Size = new System.Drawing.Size(268, 605);
|
||||
this.propertyGrid1.TabIndex = 0;
|
||||
this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged);
|
||||
//
|
||||
|
|
@ -127,7 +127,7 @@
|
|||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(951, 632);
|
||||
this.ClientSize = new System.Drawing.Size(440, 632);
|
||||
this.Controls.Add(this.splitContainer1);
|
||||
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.Name = "InspectForm";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using MatterHackers.Agg;
|
||||
|
|
@ -27,6 +28,10 @@ namespace MatterHackers.MatterControl
|
|||
inspectedSystemWindow.MouseMove += systemWindow_MouseMove;
|
||||
inspectedSystemWindow.AfterDraw += systemWindow_AfterDraw;
|
||||
inspectedSystemWindow.Invalidate();
|
||||
|
||||
treeView1.SuspendLayout();
|
||||
this.AddTree(inspectedSystemWindow, null, "SystemWindow");
|
||||
treeView1.ResumeLayout();
|
||||
}
|
||||
|
||||
public bool Inspecting { get; set; } = true;
|
||||
|
|
@ -49,6 +54,8 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
private HashSet<GuiWidget> ancestryTree = new HashSet<GuiWidget>();
|
||||
|
||||
private GuiWidget _inspectedWidget;
|
||||
private GuiWidget InspectedWidget
|
||||
{
|
||||
|
|
@ -74,6 +81,9 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
if (_inspectedWidget != null)
|
||||
{
|
||||
ancestryTree = new HashSet<GuiWidget>(_inspectedWidget.Parents<GuiWidget>());
|
||||
ancestryTree.Add(_inspectedWidget);
|
||||
|
||||
propertyGrid1.SelectedObject = _inspectedWidget;
|
||||
|
||||
_inspectedWidget.DebugShowBounds = true;
|
||||
|
|
@ -100,27 +110,30 @@ namespace MatterHackers.MatterControl
|
|||
if (treeNodes.TryGetValue(_inspectedWidget, out TreeNode treeNode))
|
||||
{
|
||||
treeView1.SelectedNode = treeNode;
|
||||
|
||||
treeNode.EnsureVisible();
|
||||
activeTreeNode = treeNode;
|
||||
activeTreeNode.Checked = true;
|
||||
treeView1.Invalidate();
|
||||
}
|
||||
|
||||
_inspectedWidget.Invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Font boldFont;
|
||||
|
||||
private void inspectedWidget_MouseUp(object sender, Agg.UI.MouseEventArgs e)
|
||||
{
|
||||
// Stop listing on click
|
||||
this.Inspecting = false;
|
||||
}
|
||||
|
||||
private void AddItem(GuiWidget widget, string text = null, TreeNode childNode = null)
|
||||
private void AddItem(GuiWidget widget, string text = null, TreeNode childNode = null, bool showAllParents = true)
|
||||
{
|
||||
|
||||
if (text == null)
|
||||
{
|
||||
text = BuildName(widget);
|
||||
text = BuildDefaultName(widget);
|
||||
}
|
||||
|
||||
if (treeNodes.TryGetValue(widget, out TreeNode existingNode))
|
||||
|
|
@ -138,6 +151,11 @@ namespace MatterHackers.MatterControl
|
|||
Tag = widget
|
||||
};
|
||||
|
||||
if (boldFont == null)
|
||||
{
|
||||
boldFont = new Font(node.NodeFont, FontStyle.Bold);
|
||||
}
|
||||
|
||||
if (childNode != null)
|
||||
{
|
||||
node.Nodes.Add(childNode);
|
||||
|
|
@ -145,35 +163,56 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
treeNodes.Add(widget, node);
|
||||
|
||||
var parent = widget.Parent;
|
||||
if (parent == null)
|
||||
if (showAllParents)
|
||||
{
|
||||
treeView1.Nodes.Add(node);
|
||||
var parent = widget.Parent;
|
||||
if (parent == null)
|
||||
{
|
||||
treeView1.Nodes.Add(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddItem(parent, parent.Text, node);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddItem(parent, parent.Text, node);
|
||||
treeView1.Nodes.Add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RebuildUI(List<GuiWidget.WidgetAndPosition> namedChildren)
|
||||
private TreeNode AddItem(GuiWidget widget, TreeNode parentNode, string overrideText = null)
|
||||
{
|
||||
treeView1.Nodes.Clear();
|
||||
treeNodes.Clear();
|
||||
|
||||
treeView1.SuspendLayout();
|
||||
|
||||
for (int i = 0; i < namedChildren.Count; i++)
|
||||
var node = new TreeNode(overrideText ?? BuildDefaultName(widget))
|
||||
{
|
||||
var child = namedChildren[i];
|
||||
AddItem(child.widget);
|
||||
Tag = widget
|
||||
};
|
||||
treeNodes.Add(widget, node);
|
||||
|
||||
if (parentNode == null)
|
||||
{
|
||||
treeView1.Nodes.Add(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
parentNode.Nodes.Add(node);
|
||||
}
|
||||
|
||||
treeView1.ResumeLayout();
|
||||
return node;
|
||||
}
|
||||
|
||||
private string BuildName(GuiWidget widget)
|
||||
private void AddTree(GuiWidget widget, TreeNode parent, string text = null, TreeNode childNode = null)
|
||||
{
|
||||
var node = AddItem(widget, parent);
|
||||
|
||||
foreach(var child in widget.Children)
|
||||
{
|
||||
AddTree(child, node);
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildDefaultName(GuiWidget widget)
|
||||
{
|
||||
string nameToWrite = _inspectedWidget == widget ? "* " : "";
|
||||
if (!string.IsNullOrEmpty(widget.Name))
|
||||
|
|
@ -240,8 +279,6 @@ namespace MatterHackers.MatterControl
|
|||
if (namedChildren.LastOrDefault()?.widget is GuiWidget firstUnderMouse
|
||||
&& firstUnderMouse != this.InspectedWidget)
|
||||
{
|
||||
RebuildUI(namedChildren);
|
||||
|
||||
this.InspectedWidget = firstUnderMouse;
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +320,34 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
|
||||
{
|
||||
e.DrawDefault = true;
|
||||
var node = e.Node;
|
||||
|
||||
if (node.IsVisible)
|
||||
{
|
||||
Brush brush;
|
||||
if (node == activeTreeNode)
|
||||
{
|
||||
brush = SystemBrushes.Highlight;
|
||||
}
|
||||
else if (ancestryTree.Contains(node.Tag as GuiWidget))
|
||||
{
|
||||
brush = Brushes.LightBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
brush = Brushes.Transparent;
|
||||
}
|
||||
|
||||
e.Graphics.FillRectangle(brush, e.Node.Bounds);
|
||||
|
||||
TextRenderer.DrawText(
|
||||
e.Graphics,
|
||||
node.Text,
|
||||
node == activeTreeNode ? boldFont : node.NodeFont,
|
||||
new Point(node.Bounds.Left, node.Bounds.Top),
|
||||
Color.Black,
|
||||
Color.Transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue