mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-23 12:11:32 +03:00
Improved docking
Added dock order. Made groups size properly to the containing region. Added DarkDockTab.
This commit is contained in:
parent
99b88d0991
commit
46ac401542
@ -107,6 +107,7 @@
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Docking\Items\DarkDockSplitter.cs" />
|
||||
<Compile Include="Docking\Items\DarkDockTab.cs" />
|
||||
<Compile Include="Extensions\BitmapExtensions.cs" />
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Forms\DarkDialog.cs">
|
||||
|
@ -1,7 +1,6 @@
|
||||
using DarkUI.Config;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DarkUI.Docking
|
||||
@ -23,25 +22,25 @@ namespace DarkUI.Docking
|
||||
|
||||
public DarkDockArea DockArea { get; private set; }
|
||||
|
||||
public int ContentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _contents.Count;
|
||||
}
|
||||
}
|
||||
public DarkDockContent VisibleContent { get; private set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public int ContentCount { get { return _contents.Count; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor Region
|
||||
|
||||
public DarkDockGroup(DarkDockPanel dockPanel, DarkDockRegion dockRegion)
|
||||
public DarkDockGroup(DarkDockPanel dockPanel, DarkDockRegion dockRegion, int order)
|
||||
{
|
||||
_contents = new List<DarkDockContent>();
|
||||
|
||||
DockPanel = dockPanel;
|
||||
DockRegion = dockRegion;
|
||||
DockArea = dockRegion.DockArea;
|
||||
|
||||
Order = order;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -55,6 +54,9 @@ namespace DarkUI.Docking
|
||||
|
||||
_contents.Add(dockContent);
|
||||
Controls.Add(dockContent);
|
||||
|
||||
if (VisibleContent == null)
|
||||
VisibleContent = dockContent;
|
||||
}
|
||||
|
||||
public void RemoveContent(DarkDockContent dockContent)
|
||||
@ -63,6 +65,15 @@ namespace DarkUI.Docking
|
||||
|
||||
_contents.Remove(dockContent);
|
||||
Controls.Remove(dockContent);
|
||||
|
||||
if (VisibleContent == dockContent)
|
||||
{
|
||||
VisibleContent = null;
|
||||
|
||||
// todo: order?
|
||||
foreach (var content in _contents)
|
||||
VisibleContent = content;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DarkUI.Docking
|
||||
@ -68,6 +69,8 @@ namespace DarkUI.Docking
|
||||
// Show the region if it was previously hidden
|
||||
if (!Visible)
|
||||
Visible = true;
|
||||
|
||||
PositionGroups();
|
||||
}
|
||||
|
||||
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 (_groups.Count == 0 && DockArea != DarkDockArea.Document)
|
||||
Visible = false;
|
||||
|
||||
PositionGroups();
|
||||
}
|
||||
|
||||
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);
|
||||
Controls.Add(newGroup);
|
||||
|
||||
PositionGroups();
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
private void RemoveGroup(DarkDockGroup group)
|
||||
{
|
||||
var lastOrder = group.Order;
|
||||
|
||||
_groups.Remove(group);
|
||||
Controls.Remove(group);
|
||||
|
||||
PositionGroups();
|
||||
foreach (var otherGroup in _groups)
|
||||
{
|
||||
if (otherGroup.Order > lastOrder)
|
||||
otherGroup.Order--;
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionGroups()
|
||||
@ -127,21 +148,52 @@ namespace DarkUI.Docking
|
||||
if (_groups.Count == 1)
|
||||
{
|
||||
_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();
|
||||
|
||||
if (_groups.IsFirst(group))
|
||||
if (group.Order == lastGroup.Order)
|
||||
group.Dock = DockStyle.Fill;
|
||||
else
|
||||
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()
|
||||
{
|
||||
MinimumSize = new Size(50, 50);
|
||||
@ -205,6 +257,8 @@ namespace DarkUI.Docking
|
||||
|
||||
private void ParentForm_ResizeEnd(object sender, EventArgs e)
|
||||
{
|
||||
SizeGroups();
|
||||
|
||||
if (_splitter != null)
|
||||
_splitter.UpdateBounds();
|
||||
}
|
||||
@ -213,6 +267,8 @@ namespace DarkUI.Docking
|
||||
{
|
||||
base.OnLayout(e);
|
||||
|
||||
SizeGroups();
|
||||
|
||||
if (_splitter != null)
|
||||
_splitter.UpdateBounds();
|
||||
}
|
||||
|
46
DarkUI/Docking/Items/DarkDockTab.cs
Normal file
46
DarkUI/Docking/Items/DarkDockTab.cs
Normal 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
|
||||
}
|
||||
}
|
4
Example/Forms/Docking/DockHistory.Designer.cs
generated
4
Example/Forms/Docking/DockHistory.Designer.cs
generated
@ -31,7 +31,7 @@ namespace Example
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.lstHistory = new DarkListView();
|
||||
this.lstHistory = new DarkUI.Controls.DarkListView();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lstHistory
|
||||
@ -48,7 +48,7 @@ namespace Example
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.lstHistory);
|
||||
this.DockArea = DarkDockArea.Bottom;
|
||||
this.DockArea = DarkUI.Config.DarkDockArea.Right;
|
||||
this.DockText = "History";
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user