From 52df1380a7dfd0b7fe8e15c7be4dd744fe371685 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 12 Sep 2020 08:53:40 -0700 Subject: [PATCH] Making the scene tree view a bit better --- .../PartPreviewWindow/Object3DTreeBuilder.cs | 2 +- .../PartPreviewWindow/View3D/View3DWidget.cs | 29 +++++++++++++++---- .../Themes/System/Classic/Classic-Dark.json | 2 +- .../Themes/System/Classic/Classic-Light.json | 2 +- .../Themes/System/Light/Light-White.json | 2 +- .../Themes/System/Menus/White-Menu.json | 2 +- .../System/Modern/Modern-Dark-Menu.json | 2 +- .../Themes/System/Modern/Modern-Dark.json | 2 +- .../System/Solarized/Solarized-Dark.json | 2 +- .../Solarized/Solarized-Light-Menu.json | 2 +- .../System/Solarized/Solarized-Light.json | 2 +- 11 files changed, 34 insertions(+), 15 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs b/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs index 5925ebbf2..1d3234c22 100644 --- a/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs +++ b/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs @@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow if (componentObject3D?.Finalized == false || !hideChildren) { - foreach (var child in item.Children) + foreach (var child in item.Children.OrderBy(i => i.Name)) { if (child != null && !child.GetType().GetCustomAttributes(typeof(HideFromTreeViewAttribute), true).Any()) diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index d1f08198a..9b35a9726 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -29,7 +29,6 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading; @@ -58,9 +57,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { private bool deferEditorTillMouseUp = false; - public readonly int EditButtonHeight = 44; + public int EditButtonHeight { get; set; } = 44; - private Color[] SelectionColors = new Color[] { new Color(131, 4, 66), new Color(227, 31, 61), new Color(255, 148, 1), new Color(247, 224, 23), new Color(143, 212, 1) }; + private Color[] selectionColors = new Color[] { new Color(131, 4, 66), new Color(227, 31, 61), new Color(255, 148, 1), new Color(247, 224, 23), new Color(143, 212, 1) }; private Stopwatch timeSinceLastSpin = new Stopwatch(); private Stopwatch timeSinceReported = new Stopwatch(); @@ -415,17 +414,33 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private Dictionary treeNodesByObject = new Dictionary(); + private bool watingToScroll = false; + private void RebuildTree() { rebuildTreePending = false; workspaceName.Text = sceneContext.Scene.Name ?? ""; + if (!watingToScroll) + { + // This is a mess. The goal is that the tree view will not scroll as we add and remove items. + // This is better than always reseting to the top, but only a little. + watingToScroll = true; + beforeReubildScrollPosition = treeView.TopLeftOffset; + + UiThread.RunOnIdle(() => + { + treeView.TopLeftOffset = beforeReubildScrollPosition; + watingToScroll = false; + }, .5); + } + // Top level selection only - rebuild tree treeNodeContainer.CloseAllChildren(); treeNodesByObject.Clear(); - foreach (var child in sceneContext.Scene.Children) + foreach (var child in sceneContext.Scene.Children.OrderBy(i => i.Name)) { if (child.GetType().GetCustomAttributes(typeof(HideFromTreeViewAttribute), true).Any()) { @@ -445,6 +460,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow treeView.SelectedNode = treeNode; } + treeView.TopLeftOffset = beforeReubildScrollPosition; + Invalidate(); } @@ -1577,7 +1594,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private void Scene_Invalidated(object sender, InvalidateArgs e) { - if (Scene.Descendants().Count() != lastSceneDescendantsCount) + if (Scene.Descendants().Count() != lastSceneDescendantsCount + && !rebuildTreePending) { rebuildTreePending = true; UiThread.RunOnIdle(this.RebuildTree); @@ -1675,6 +1693,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private InlineStringEdit workspaceName; private int lastSceneDescendantsCount; + private Vector2 beforeReubildScrollPosition; public InteractiveScene Scene => sceneContext.Scene; diff --git a/StaticData/Themes/System/Classic/Classic-Dark.json b/StaticData/Themes/System/Classic/Classic-Dark.json index 1bd1326d2..78a9f7b4f 100644 --- a/StaticData/Themes/System/Classic/Classic-Dark.json +++ b/StaticData/Themes/System/Classic/Classic-Dark.json @@ -14,7 +14,7 @@ "BackgroundColor": "#404040", "TabBarBackground": "#363636", "InactiveTabColor": "#4E4E4E", - "InteractionLayerOverlayColor": "#404040F0", + "Object3DControlLayerOverlayColor": "#404040F0", "SplitterBackground": "#383838", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Classic/Classic-Light.json b/StaticData/Themes/System/Classic/Classic-Light.json index ddcb28500..d4d502b61 100644 --- a/StaticData/Themes/System/Classic/Classic-Light.json +++ b/StaticData/Themes/System/Classic/Classic-Light.json @@ -14,7 +14,7 @@ "BackgroundColor": "#C4C4C4", "TabBarBackground": "#A7A7A7", "InactiveTabColor": "#D1D1D1", - "InteractionLayerOverlayColor": "#C4C4C4F0", + "Object3DControlLayerOverlayColor": "#C4C4C4F0", "SplitterBackground": "#ABABAB", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Light/Light-White.json b/StaticData/Themes/System/Light/Light-White.json index e8b2ca9ee..e6ea7adc5 100644 --- a/StaticData/Themes/System/Light/Light-White.json +++ b/StaticData/Themes/System/Light/Light-White.json @@ -14,7 +14,7 @@ "BackgroundColor": "#fff", "TabBarBackground": "#F3F3F3", "InactiveTabColor": "#E6E6E6", - "InteractionLayerOverlayColor": "#ffffffF0", + "Object3DControlLayerOverlayColor": "#ffffffF0", "SplitterBackground": "#E1E1E1", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Menus/White-Menu.json b/StaticData/Themes/System/Menus/White-Menu.json index 23f9de62c..80f4e91c7 100644 --- a/StaticData/Themes/System/Menus/White-Menu.json +++ b/StaticData/Themes/System/Menus/White-Menu.json @@ -14,7 +14,7 @@ "BackgroundColor": "#F1F1F1", "TabBarBackground": "#A7A7A7", "InactiveTabColor": "#D1D1D1", - "InteractionLayerOverlayColor": "#C4C4C4F0", + "Object3DControlLayerOverlayColor": "#C4C4C4F0", "SplitterBackground": "#ABABAB", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Modern/Modern-Dark-Menu.json b/StaticData/Themes/System/Modern/Modern-Dark-Menu.json index d1e86f084..c930feebd 100644 --- a/StaticData/Themes/System/Modern/Modern-Dark-Menu.json +++ b/StaticData/Themes/System/Modern/Modern-Dark-Menu.json @@ -14,7 +14,7 @@ "BackgroundColor": "#404040", "TabBarBackground": "#B1B1B1", "InactiveTabColor": "#D0D0D0", - "InteractionLayerOverlayColor": "#D0D0D0F0", + "Object3DControlLayerOverlayColor": "#D0D0D0F0", "SplitterBackground": "#B5B5B5", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Modern/Modern-Dark.json b/StaticData/Themes/System/Modern/Modern-Dark.json index 97cc4a8bf..28f2ac1a3 100644 --- a/StaticData/Themes/System/Modern/Modern-Dark.json +++ b/StaticData/Themes/System/Modern/Modern-Dark.json @@ -14,7 +14,7 @@ "BackgroundColor": "#373737", "TabBarBackground": "#282828", "InactiveTabColor": "#404040", - "InteractionLayerOverlayColor": "#373737F0", + "Object3DControlLayerOverlayColor": "#373737F0", "SplitterBackground": "#2C2C2C", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Solarized/Solarized-Dark.json b/StaticData/Themes/System/Solarized/Solarized-Dark.json index c664666dd..4ecb6194e 100644 --- a/StaticData/Themes/System/Solarized/Solarized-Dark.json +++ b/StaticData/Themes/System/Solarized/Solarized-Dark.json @@ -14,7 +14,7 @@ "BackgroundColor": "#002B36", "TabBarBackground": "#001A20", "InactiveTabColor": "#073642", - "InteractionLayerOverlayColor": "#002B36F0", + "Object3DControlLayerOverlayColor": "#002B36F0", "SplitterBackground": "#073642", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Solarized/Solarized-Light-Menu.json b/StaticData/Themes/System/Solarized/Solarized-Light-Menu.json index 2e2b325af..a55ba2a92 100644 --- a/StaticData/Themes/System/Solarized/Solarized-Light-Menu.json +++ b/StaticData/Themes/System/Solarized/Solarized-Light-Menu.json @@ -14,7 +14,7 @@ "BackgroundColor": "#F1F1F1", "TabBarBackground": "#B1B1B1", "InactiveTabColor": "#D0D0D0", - "InteractionLayerOverlayColor": "#D0D0D0F0", + "Object3DControlLayerOverlayColor": "#D0D0D0F0", "SplitterBackground": "#B5B5B5", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000", diff --git a/StaticData/Themes/System/Solarized/Solarized-Light.json b/StaticData/Themes/System/Solarized/Solarized-Light.json index a61bd6977..710ee5793 100644 --- a/StaticData/Themes/System/Solarized/Solarized-Light.json +++ b/StaticData/Themes/System/Solarized/Solarized-Light.json @@ -14,7 +14,7 @@ "BackgroundColor": "#FDF6E3", "TabBarBackground": "#E4DDCC", "InactiveTabColor": "#EEE8D5", - "InteractionLayerOverlayColor": "#FDF6E3F0", + "Object3DControlLayerOverlayColor": "#FDF6E3F0", "SplitterBackground": "#EEE8D5", "TabBodyBackground": "#00000000", "ToolbarButtonBackground": "#00000000",