Add theme dependency to TreeView, use theme for selection color

This commit is contained in:
John Lewin 2018-05-22 07:00:00 -07:00
parent e3c1c4b61e
commit d0e490fe41
4 changed files with 25 additions and 19 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2016, Lars Brubaker, John Lewin
Copyright (c) 2018, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -27,14 +27,14 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.CustomWidgets.TreeView
{

View file

@ -44,22 +44,25 @@ namespace MatterHackers.MatterControl.CustomWidgets.TreeView
public class TreeView : ScrollableWidget
{
public TreeView(TopNode topNode)
: this(topNode, 0, 0)
private ThemeConfig theme;
public TreeView(TopNode topNode, ThemeConfig theme)
: this(topNode, 0, 0, theme)
{
}
public TreeView(TopNode topNode, int width, int height)
public TreeView(TopNode topNode, int width, int height, ThemeConfig theme)
: base(width, height)
{
AutoScroll = true;
this.theme = theme;
this.AutoScroll = true;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Stretch;
this.TopNode = topNode;
topNode.treeView = this;
TopNode = topNode;
HAnchor = HAnchor.Stretch;
VAnchor = VAnchor.Stretch;
AddChild(TopNode);
this.AddChild(TopNode);
}
#region Events
@ -200,7 +203,8 @@ namespace MatterHackers.MatterControl.CustomWidgets.TreeView
// Returns:
// The TreeNode that is currently selected in the tree view
// control.
TreeNode _selectedNode;
private TreeNode _selectedNode;
public TreeNode SelectedNode
{
get => _selectedNode; set
@ -208,12 +212,14 @@ namespace MatterHackers.MatterControl.CustomWidgets.TreeView
if (value != _selectedNode)
{
OnBeforeSelect(null);
foreach (var node in this.Descendants<TreeNode>().Where((c) => c != value))
{
node.TitleBar.BackgroundColor = Color.Transparent;
}
_selectedNode = value;
_selectedNode.TitleBar.BackgroundColor = Color.Red;
_selectedNode.TitleBar.BackgroundColor = theme.AccentMimimalOverlay;
OnAfterSelect(null);
}
}