mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-05 00:19:27 +03:00
Content now has a defined order.
This commit is contained in:
parent
f9a67a31ad
commit
421ae32072
@ -78,6 +78,10 @@ namespace DarkUI.Docking
|
|||||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
public DarkDockArea DockArea { get; set; }
|
public DarkDockArea DockArea { get; set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
|
public int Order { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor Region
|
#region Constructor Region
|
||||||
|
@ -65,6 +65,20 @@ namespace DarkUI.Docking
|
|||||||
dockContent.DockGroup = this;
|
dockContent.DockGroup = this;
|
||||||
dockContent.Dock = DockStyle.Fill;
|
dockContent.Dock = DockStyle.Fill;
|
||||||
|
|
||||||
|
dockContent.Order = 0;
|
||||||
|
|
||||||
|
if (_contents.Count > 0)
|
||||||
|
{
|
||||||
|
var order = -1;
|
||||||
|
foreach (var otherContent in _contents)
|
||||||
|
{
|
||||||
|
if (otherContent.Order >= order)
|
||||||
|
order = otherContent.Order + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dockContent.Order = order;
|
||||||
|
}
|
||||||
|
|
||||||
_contents.Add(dockContent);
|
_contents.Add(dockContent);
|
||||||
Controls.Add(dockContent);
|
Controls.Add(dockContent);
|
||||||
|
|
||||||
@ -95,9 +109,17 @@ namespace DarkUI.Docking
|
|||||||
{
|
{
|
||||||
dockContent.DockGroup = null;
|
dockContent.DockGroup = null;
|
||||||
|
|
||||||
|
var order = dockContent.Order;
|
||||||
|
|
||||||
_contents.Remove(dockContent);
|
_contents.Remove(dockContent);
|
||||||
Controls.Remove(dockContent);
|
Controls.Remove(dockContent);
|
||||||
|
|
||||||
|
foreach (var otherContent in _contents)
|
||||||
|
{
|
||||||
|
if (otherContent.Order > order)
|
||||||
|
otherContent.Order--;
|
||||||
|
}
|
||||||
|
|
||||||
dockContent.DockTextChanged -= DockContent_DockTextChanged;
|
dockContent.DockTextChanged -= DockContent_DockTextChanged;
|
||||||
|
|
||||||
if (_tabs.ContainsKey(dockContent))
|
if (_tabs.ContainsKey(dockContent))
|
||||||
@ -137,7 +159,7 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
public List<DarkDockContent> GetContents()
|
public List<DarkDockContent> GetContents()
|
||||||
{
|
{
|
||||||
return _contents.ToList();
|
return _contents.OrderBy(c => c.Order).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTabArea()
|
private void UpdateTabArea()
|
||||||
@ -192,10 +214,14 @@ namespace DarkUI.Docking
|
|||||||
// Calculate areas of all tabs
|
// Calculate areas of all tabs
|
||||||
var totalSize = 0;
|
var totalSize = 0;
|
||||||
|
|
||||||
foreach (var tab in _tabs.Values)
|
var orderedContent = _contents.OrderBy(c => c.Order);
|
||||||
|
|
||||||
|
foreach (var content in orderedContent)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
|
var tab = _tabs[content];
|
||||||
|
|
||||||
using (var g = CreateGraphics())
|
using (var g = CreateGraphics())
|
||||||
{
|
{
|
||||||
width = tab.CalculateWidth(g, Font);
|
width = tab.CalculateWidth(g, Font);
|
||||||
@ -232,7 +258,7 @@ namespace DarkUI.Docking
|
|||||||
var difference = totalSize - _tabArea.ClientRectangle.Width;
|
var difference = totalSize - _tabArea.ClientRectangle.Width;
|
||||||
|
|
||||||
// No matter what, we want to slice off the 1 pixel separator from the final tab.
|
// No matter what, we want to slice off the 1 pixel separator from the final tab.
|
||||||
var lastTab = _tabs.Values.Last();
|
var lastTab = _tabs[orderedContent.Last()];
|
||||||
var tabRect = lastTab.ClientRectangle;
|
var tabRect = lastTab.ClientRectangle;
|
||||||
lastTab.ClientRectangle = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Width - 1, tabRect.Height);
|
lastTab.ClientRectangle = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Width - 1, tabRect.Height);
|
||||||
lastTab.ShowSeparator = false;
|
lastTab.ShowSeparator = false;
|
||||||
@ -246,8 +272,10 @@ namespace DarkUI.Docking
|
|||||||
.First()
|
.First()
|
||||||
.ClientRectangle.Width;
|
.ClientRectangle.Width;
|
||||||
|
|
||||||
foreach (var tab in _tabs.Values)
|
foreach (var content in orderedContent)
|
||||||
{
|
{
|
||||||
|
var tab = _tabs[content];
|
||||||
|
|
||||||
// Check if previous iteration of loop met the difference
|
// Check if previous iteration of loop met the difference
|
||||||
if (differenceMadeUp >= difference)
|
if (differenceMadeUp >= difference)
|
||||||
break;
|
break;
|
||||||
@ -263,8 +291,10 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
// After resizing the tabs reposition them accordingly.
|
// After resizing the tabs reposition them accordingly.
|
||||||
var xOffset = 0;
|
var xOffset = 0;
|
||||||
foreach (var tab in _tabs.Values)
|
foreach (var content in orderedContent)
|
||||||
{
|
{
|
||||||
|
var tab = _tabs[content];
|
||||||
|
|
||||||
var rect = tab.ClientRectangle;
|
var rect = tab.ClientRectangle;
|
||||||
tab.ClientRectangle = new Rectangle(_tabArea.ClientRectangle.Left + xOffset, rect.Top, rect.Width, rect.Height);
|
tab.ClientRectangle = new Rectangle(_tabArea.ClientRectangle.Left + xOffset, rect.Top, rect.Width, rect.Height);
|
||||||
|
|
||||||
@ -276,8 +306,9 @@ namespace DarkUI.Docking
|
|||||||
// Build close button rectangles
|
// Build close button rectangles
|
||||||
if (DockArea == DarkDockArea.Document)
|
if (DockArea == DarkDockArea.Document)
|
||||||
{
|
{
|
||||||
foreach (var tab in _tabs.Values)
|
foreach (var content in orderedContent)
|
||||||
{
|
{
|
||||||
|
var tab = _tabs[content];
|
||||||
var closeRect = new Rectangle(tab.ClientRectangle.Right - 7 - closeButtonSize - 1,
|
var closeRect = new Rectangle(tab.ClientRectangle.Right - 7 - closeButtonSize - 1,
|
||||||
tab.ClientRectangle.Top + (tab.ClientRectangle.Height / 2) - (closeButtonSize / 2) - 1,
|
tab.ClientRectangle.Top + (tab.ClientRectangle.Height / 2) - (closeButtonSize / 2) - 1,
|
||||||
closeButtonSize, closeButtonSize);
|
closeButtonSize, closeButtonSize);
|
||||||
@ -287,8 +318,12 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
// Update the tab area with the new total tab width
|
// Update the tab area with the new total tab width
|
||||||
totalSize = 0;
|
totalSize = 0;
|
||||||
foreach (var tab in _tabs.Values)
|
foreach (var content in orderedContent)
|
||||||
|
{
|
||||||
|
var tab = _tabs[content];
|
||||||
totalSize += tab.ClientRectangle.Width;
|
totalSize += tab.ClientRectangle.Width;
|
||||||
|
}
|
||||||
|
|
||||||
_tabArea.TotalTabSize = totalSize;
|
_tabArea.TotalTabSize = totalSize;
|
||||||
|
|
||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
@ -322,7 +357,8 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
if (_tabArea.TotalTabSize > offsetArea.Width)
|
if (_tabArea.TotalTabSize > offsetArea.Width)
|
||||||
{
|
{
|
||||||
var lastTab = _tabs.Values.Last();
|
var orderedContent = _contents.OrderBy(x => x.Order);
|
||||||
|
var lastTab = _tabs[orderedContent.Last()];
|
||||||
if (lastTab != null)
|
if (lastTab != null)
|
||||||
{
|
{
|
||||||
if (RectangleToTabArea(lastTab.ClientRectangle).Right < offsetArea.Right)
|
if (RectangleToTabArea(lastTab.ClientRectangle).Right < offsetArea.Right)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user