mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-25 12:41:34 +03:00
Can now resize dock regions
This commit is contained in:
parent
d266fbea86
commit
12f227f542
@ -108,6 +108,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Docking\Items\DarkDockSplitter.cs" />
|
<Compile Include="Docking\Items\DarkDockSplitter.cs" />
|
||||||
<Compile Include="Extensions\BitmapExtensions.cs" />
|
<Compile Include="Extensions\BitmapExtensions.cs" />
|
||||||
|
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||||
<Compile Include="Forms\DarkDialog.cs">
|
<Compile Include="Forms\DarkDialog.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -86,7 +86,6 @@ namespace DarkUI
|
|||||||
var newGroup = new DarkDockGroup(DockPanel, this);
|
var newGroup = new DarkDockGroup(DockPanel, this);
|
||||||
_groups.Add(newGroup);
|
_groups.Add(newGroup);
|
||||||
Controls.Add(newGroup);
|
Controls.Add(newGroup);
|
||||||
newGroup.BringToFront();
|
|
||||||
|
|
||||||
PositionGroups();
|
PositionGroups();
|
||||||
|
|
||||||
@ -121,10 +120,21 @@ namespace DarkUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_groups.Count == 1)
|
if (_groups.Count == 1)
|
||||||
|
{
|
||||||
_groups[0].Dock = DockStyle.Fill;
|
_groups[0].Dock = DockStyle.Fill;
|
||||||
|
}
|
||||||
else if (_groups.Count > 1)
|
else if (_groups.Count > 1)
|
||||||
|
{
|
||||||
foreach (var group in _groups)
|
foreach (var group in _groups)
|
||||||
group.Dock = dockStyle;
|
{
|
||||||
|
group.SendToBack();
|
||||||
|
|
||||||
|
if (_groups.IsLast(group))
|
||||||
|
group.Dock = dockStyle;
|
||||||
|
else
|
||||||
|
group.Dock = DockStyle.Fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildProperties()
|
private void BuildProperties()
|
||||||
|
@ -44,6 +44,25 @@ namespace DarkUI
|
|||||||
|
|
||||||
#region Method Region
|
#region Method Region
|
||||||
|
|
||||||
|
public void Move(Point difference)
|
||||||
|
{
|
||||||
|
switch (_splitterType)
|
||||||
|
{
|
||||||
|
case DarkSplitterType.Left:
|
||||||
|
_control.Width += difference.X;
|
||||||
|
break;
|
||||||
|
case DarkSplitterType.Right:
|
||||||
|
_control.Width -= difference.X;
|
||||||
|
break;
|
||||||
|
case DarkSplitterType.Top:
|
||||||
|
_control.Height += difference.Y;
|
||||||
|
break;
|
||||||
|
case DarkSplitterType.Bottom:
|
||||||
|
_control.Height -= difference.Y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateBounds()
|
public void UpdateBounds()
|
||||||
{
|
{
|
||||||
switch (_splitterType)
|
switch (_splitterType)
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace DarkUI
|
namespace DarkUI
|
||||||
{
|
{
|
||||||
public static class BitmapExtensions
|
internal static class BitmapExtensions
|
||||||
{
|
{
|
||||||
public static Bitmap SetColor(this Bitmap bitmap, Color color)
|
internal static Bitmap SetColor(this Bitmap bitmap, Color color)
|
||||||
{
|
{
|
||||||
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
|
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
|
||||||
for (int i = 0; i < bitmap.Width; i++)
|
for (int i = 0; i < bitmap.Width; i++)
|
||||||
@ -19,7 +19,7 @@ namespace DarkUI
|
|||||||
return newBitmap;
|
return newBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
|
internal static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
|
||||||
{
|
{
|
||||||
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
|
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
|
||||||
for (int i = 0; i < bitmap.Width; i++)
|
for (int i = 0; i < bitmap.Width; i++)
|
||||||
|
31
DarkUI/Extensions/IEnumerableExtensions.cs
Normal file
31
DarkUI/Extensions/IEnumerableExtensions.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DarkUI
|
||||||
|
{
|
||||||
|
internal static class IEnumerableExtensions
|
||||||
|
{
|
||||||
|
internal static bool IsLast<T>(this IEnumerable<T> items, T item)
|
||||||
|
{
|
||||||
|
var last = items.LastOrDefault();
|
||||||
|
if (last == null)
|
||||||
|
return false;
|
||||||
|
return item.Equals(last); // OR Object.ReferenceEquals(last, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsFirst<T>(this IEnumerable<T> items, T item)
|
||||||
|
{
|
||||||
|
var first = items.FirstOrDefault();
|
||||||
|
if (first == null)
|
||||||
|
return false;
|
||||||
|
return item.Equals(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsFirstOrLast<T>(this IEnumerable<T> items, T item)
|
||||||
|
{
|
||||||
|
return items.IsFirst(item) || items.IsLast(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DarkUI
|
namespace DarkUI
|
||||||
@ -10,6 +11,7 @@ namespace DarkUI
|
|||||||
private DarkDockPanel _dockPanel;
|
private DarkDockPanel _dockPanel;
|
||||||
|
|
||||||
private bool _isDragging;
|
private bool _isDragging;
|
||||||
|
private Point _initialContact;
|
||||||
private DarkDockSplitter _activeSplitter;
|
private DarkDockSplitter _activeSplitter;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -33,16 +35,13 @@ namespace DarkUI
|
|||||||
m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK))
|
m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Exit out early if we're simply releasing a drag over the area
|
// Exit out early if we're simply releasing a non-splitter drag over the area
|
||||||
if (m.Msg == (int)WM.LBUTTONUP && !_isDragging)
|
if (m.Msg == (int)WM.LBUTTONUP && !_isDragging)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Force cursor if already dragging.
|
// Force cursor if already dragging.
|
||||||
ForceDraggingCursor();
|
|
||||||
|
|
||||||
// Stop all events from going through if we're dragging a splitter.
|
|
||||||
if (_isDragging)
|
if (_isDragging)
|
||||||
return true;
|
Cursor.Current = _activeSplitter.ResizeCursor;
|
||||||
|
|
||||||
// Return out early if we're dragging something that's not a splitter.
|
// Return out early if we're dragging something that's not a splitter.
|
||||||
if (m.Msg == (int)WM.MOUSEMOVE && !_isDragging && _dockPanel.MouseButtonState != MouseButtons.None)
|
if (m.Msg == (int)WM.MOUSEMOVE && !_isDragging && _dockPanel.MouseButtonState != MouseButtons.None)
|
||||||
@ -65,17 +64,26 @@ namespace DarkUI
|
|||||||
// Start drag.
|
// Start drag.
|
||||||
if (m.Msg == (int)WM.LBUTTONDOWN)
|
if (m.Msg == (int)WM.LBUTTONDOWN)
|
||||||
{
|
{
|
||||||
|
foreach (var splitter in _dockPanel.Splitters)
|
||||||
|
{
|
||||||
|
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
|
||||||
|
{
|
||||||
|
StartDrag(splitter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop drag.
|
// Stop drag.
|
||||||
if (m.Msg == (int)WM.LBUTTONUP)
|
if (m.Msg == (int)WM.LBUTTONUP)
|
||||||
{
|
{
|
||||||
|
if (_isDragging)
|
||||||
|
{
|
||||||
|
StopDrag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop events passing through if we just started to drag something
|
|
||||||
if (_isDragging)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Stop events passing through if we're hovering over a splitter
|
// Stop events passing through if we're hovering over a splitter
|
||||||
foreach (var splitter in _dockPanel.Splitters)
|
foreach (var splitter in _dockPanel.Splitters)
|
||||||
{
|
{
|
||||||
@ -83,6 +91,10 @@ namespace DarkUI
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop all events from going through if we're dragging a splitter.
|
||||||
|
if (_isDragging)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,19 +102,25 @@ namespace DarkUI
|
|||||||
|
|
||||||
#region Method Region
|
#region Method Region
|
||||||
|
|
||||||
private void ForceDraggingCursor()
|
private void StartDrag(DarkDockSplitter splitter)
|
||||||
{
|
{
|
||||||
if (_isDragging)
|
Console.WriteLine("Start drag");
|
||||||
{
|
|
||||||
SetCursor(_activeSplitter.ResizeCursor);
|
_activeSplitter = splitter;
|
||||||
return;
|
Cursor.Current = _activeSplitter.ResizeCursor;
|
||||||
}
|
|
||||||
|
_initialContact = Cursor.Position;
|
||||||
|
_isDragging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetCursor()
|
private void StopDrag()
|
||||||
{
|
{
|
||||||
Cursor.Current = Cursors.Default;
|
Console.WriteLine("Stop drag");
|
||||||
CheckCursor();
|
|
||||||
|
var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y);
|
||||||
|
_activeSplitter.Move(difference);
|
||||||
|
|
||||||
|
_isDragging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckCursor()
|
private void CheckCursor()
|
||||||
@ -114,15 +132,16 @@ namespace DarkUI
|
|||||||
{
|
{
|
||||||
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
|
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
|
||||||
{
|
{
|
||||||
SetCursor(splitter.ResizeCursor);
|
Cursor.Current = splitter.ResizeCursor;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCursor(Cursor cursor)
|
private void ResetCursor()
|
||||||
{
|
{
|
||||||
Cursor.Current = cursor;
|
Cursor.Current = Cursors.Default;
|
||||||
|
CheckCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -43,6 +43,11 @@ namespace Example
|
|||||||
DockPanel.AddContent(_dockLayers);
|
DockPanel.AddContent(_dockLayers);
|
||||||
DockPanel.AddContent(_dockHistory);
|
DockPanel.AddContent(_dockHistory);
|
||||||
|
|
||||||
|
// Add 3 dummy documents to the main document area of the dock panel
|
||||||
|
DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
|
||||||
|
DockPanel.AddContent(new DockDocument { DockText = "Document 2" });
|
||||||
|
DockPanel.AddContent(new DockDocument { DockText = "Document 3" });
|
||||||
|
|
||||||
// Show the tool windows as visible in the 'Window' menu
|
// Show the tool windows as visible in the 'Window' menu
|
||||||
mnuProject.Checked = true;
|
mnuProject.Checked = true;
|
||||||
mnuProperties.Checked = true;
|
mnuProperties.Checked = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user