Improved docking

Added dock order. Made groups size properly to the containing region.
Added DarkDockTab.
This commit is contained in:
Robin 2015-12-05 13:13:31 +00:00
parent 99b88d0991
commit 46ac401542
5 changed files with 132 additions and 18 deletions

View File

@ -107,6 +107,7 @@
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Docking\Items\DarkDockSplitter.cs" /> <Compile Include="Docking\Items\DarkDockSplitter.cs" />
<Compile Include="Docking\Items\DarkDockTab.cs" />
<Compile Include="Extensions\BitmapExtensions.cs" /> <Compile Include="Extensions\BitmapExtensions.cs" />
<Compile Include="Extensions\IEnumerableExtensions.cs" /> <Compile Include="Extensions\IEnumerableExtensions.cs" />
<Compile Include="Forms\DarkDialog.cs"> <Compile Include="Forms\DarkDialog.cs">

View File

@ -1,7 +1,6 @@
using DarkUI.Config; using DarkUI.Config;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace DarkUI.Docking namespace DarkUI.Docking
@ -23,25 +22,25 @@ namespace DarkUI.Docking
public DarkDockArea DockArea { get; private set; } public DarkDockArea DockArea { get; private set; }
public int ContentCount public DarkDockContent VisibleContent { get; private set; }
{
get public int Order { get; set; }
{
return _contents.Count; public int ContentCount { get { return _contents.Count; } }
}
}
#endregion #endregion
#region Constructor Region #region Constructor Region
public DarkDockGroup(DarkDockPanel dockPanel, DarkDockRegion dockRegion) public DarkDockGroup(DarkDockPanel dockPanel, DarkDockRegion dockRegion, int order)
{ {
_contents = new List<DarkDockContent>(); _contents = new List<DarkDockContent>();
DockPanel = dockPanel; DockPanel = dockPanel;
DockRegion = dockRegion; DockRegion = dockRegion;
DockArea = dockRegion.DockArea; DockArea = dockRegion.DockArea;
Order = order;
} }
#endregion #endregion
@ -55,6 +54,9 @@ namespace DarkUI.Docking
_contents.Add(dockContent); _contents.Add(dockContent);
Controls.Add(dockContent); Controls.Add(dockContent);
if (VisibleContent == null)
VisibleContent = dockContent;
} }
public void RemoveContent(DarkDockContent dockContent) public void RemoveContent(DarkDockContent dockContent)
@ -63,6 +65,15 @@ namespace DarkUI.Docking
_contents.Remove(dockContent); _contents.Remove(dockContent);
Controls.Remove(dockContent); Controls.Remove(dockContent);
if (VisibleContent == dockContent)
{
VisibleContent = null;
// todo: order?
foreach (var content in _contents)
VisibleContent = content;
}
} }
#endregion #endregion

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace DarkUI.Docking namespace DarkUI.Docking
@ -68,6 +69,8 @@ namespace DarkUI.Docking
// Show the region if it was previously hidden // Show the region if it was previously hidden
if (!Visible) if (!Visible)
Visible = true; Visible = true;
PositionGroups();
} }
public void RemoveContent(DarkDockContent dockContent) public void RemoveContent(DarkDockContent dockContent)
@ -84,25 +87,43 @@ namespace DarkUI.Docking
// If we just removed the final group, and this isn't the document region, then hide // If we just removed the final group, and this isn't the document region, then hide
if (_groups.Count == 0 && DockArea != DarkDockArea.Document) if (_groups.Count == 0 && DockArea != DarkDockArea.Document)
Visible = false; Visible = false;
PositionGroups();
} }
private DarkDockGroup CreateGroup() private DarkDockGroup CreateGroup()
{ {
var newGroup = new DarkDockGroup(DockPanel, this); var order = 0;
if (_groups.Count >= 1)
{
order = -1;
foreach (var group in _groups)
{
if (group.Order >= order)
order = group.Order + 1;
}
}
var newGroup = new DarkDockGroup(DockPanel, this, order);
_groups.Add(newGroup); _groups.Add(newGroup);
Controls.Add(newGroup); Controls.Add(newGroup);
PositionGroups();
return newGroup; return newGroup;
} }
private void RemoveGroup(DarkDockGroup group) private void RemoveGroup(DarkDockGroup group)
{ {
var lastOrder = group.Order;
_groups.Remove(group); _groups.Remove(group);
Controls.Remove(group); Controls.Remove(group);
PositionGroups(); foreach (var otherGroup in _groups)
{
if (otherGroup.Order > lastOrder)
otherGroup.Order--;
}
} }
private void PositionGroups() private void PositionGroups()
@ -127,21 +148,52 @@ namespace DarkUI.Docking
if (_groups.Count == 1) if (_groups.Count == 1)
{ {
_groups[0].Dock = DockStyle.Fill; _groups[0].Dock = DockStyle.Fill;
return;
} }
else if (_groups.Count > 1)
if (_groups.Count > 1)
{ {
foreach (var group in _groups) var lastGroup = _groups.OrderByDescending(g => g.Order).First();
foreach (var group in _groups.OrderByDescending(g => g.Order))
{ {
group.SendToBack(); group.SendToBack();
if (_groups.IsFirst(group)) if (group.Order == lastGroup.Order)
group.Dock = DockStyle.Fill; group.Dock = DockStyle.Fill;
else else
group.Dock = dockStyle; group.Dock = dockStyle;
} }
SizeGroups();
} }
} }
private void SizeGroups()
{
if (_groups.Count <= 1)
return;
var size = new Size(0, 0);
switch (DockArea)
{
default:
case DarkDockArea.Document:
return;
case DarkDockArea.Left:
case DarkDockArea.Right:
size = new Size(Width, Height / _groups.Count);
break;
case DarkDockArea.Bottom:
size = new Size(Width / _groups.Count, Height);
break;
}
foreach (var group in _groups)
group.Size = size;
}
private void BuildProperties() private void BuildProperties()
{ {
MinimumSize = new Size(50, 50); MinimumSize = new Size(50, 50);
@ -205,6 +257,8 @@ namespace DarkUI.Docking
private void ParentForm_ResizeEnd(object sender, EventArgs e) private void ParentForm_ResizeEnd(object sender, EventArgs e)
{ {
SizeGroups();
if (_splitter != null) if (_splitter != null)
_splitter.UpdateBounds(); _splitter.UpdateBounds();
} }
@ -213,6 +267,8 @@ namespace DarkUI.Docking
{ {
base.OnLayout(e); base.OnLayout(e);
SizeGroups();
if (_splitter != null) if (_splitter != null)
_splitter.UpdateBounds(); _splitter.UpdateBounds();
} }

View File

@ -0,0 +1,46 @@
using System.Drawing;
namespace DarkUI.Docking
{
internal class DarkDockTab
{
#region Property Region
public DarkDockContent DockContent { get; set; }
public Rectangle ClientRectangle { get; set; }
public Rectangle CloseButtonRectangle { get; set; }
public bool Hot { get; set; }
public bool Pressed { get; set; }
public bool CloseButtonHot { get; set; }
public bool ShowSeparator { get; set; }
#endregion
#region Constructor Region
public DarkDockTab(DarkDockContent content)
{
DockContent = content;
}
#endregion
#region Method Region
public int CalculateWidth(Graphics g, Font font)
{
var width = (int)g.MeasureString(DockContent.DockText, font).Width;
width += 10;
return width;
}
#endregion
}
}

View File

@ -31,7 +31,7 @@ namespace Example
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.lstHistory = new DarkListView(); this.lstHistory = new DarkUI.Controls.DarkListView();
this.SuspendLayout(); this.SuspendLayout();
// //
// lstHistory // lstHistory
@ -48,7 +48,7 @@ namespace Example
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lstHistory); this.Controls.Add(this.lstHistory);
this.DockArea = DarkDockArea.Bottom; this.DockArea = DarkUI.Config.DarkDockArea.Right;
this.DockText = "History"; this.DockText = "History";
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Icon = global::Example.Icons.RefactoringLog_12810; this.Icon = global::Example.Icons.RefactoringLog_12810;