add Grid
This commit is contained in:
1 parent
467bedb656
commit
a0707147ae
20 files changed
+314
-24
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Col : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register(
|
||||
"Layout", typeof(ColLayout), typeof(Col), new PropertyMetadata(new ColLayout()));
|
||||
|
||||
public ColLayout Layout
|
||||
{
|
||||
get => (ColLayout)GetValue(LayoutProperty);
|
||||
set => SetValue(LayoutProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register(
|
||||
"Offset", typeof(int), typeof(Col), new PropertyMetadata(default(int)));
|
||||
|
||||
public int Offset
|
||||
{
|
||||
get => (int)GetValue(OffsetProperty);
|
||||
set => SetValue(OffsetProperty, value);
|
||||
}
|
||||
|
||||
internal int GetLayoutCellCount(ColLayoutStatus status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case ColLayoutStatus.Xs: return Layout.Xs;
|
||||
case ColLayoutStatus.Sm: return Layout.Sm;
|
||||
case ColLayoutStatus.Md: return Layout.Md;
|
||||
case ColLayoutStatus.Lg: return Layout.Lg;
|
||||
case ColLayoutStatus.Xl: return Layout.Xl;
|
||||
case ColLayoutStatus.Xxl: return Layout.Xxl;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using HandyControl.Tools.Extension;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Row : Panel
|
||||
{
|
||||
private ColLayoutStatus _layoutStatus;
|
||||
|
||||
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register(
|
||||
"Gutter", typeof(double), typeof(Row), new PropertyMetadata(default(double)));
|
||||
|
||||
public double Gutter
|
||||
{
|
||||
get => (double)GetValue(GutterProperty);
|
||||
set => SetValue(GutterProperty, value);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
var itemWidth = constraint.Width / ColLayout.ColMaxCellCount;
|
||||
var totalCellCount = 0;
|
||||
var totalRowCount = 1;
|
||||
var maxChildDesiredHeight = .0;
|
||||
|
||||
for (int i = 0, count = InternalChildren.Count; i < count; ++i)
|
||||
{
|
||||
var child = InternalChildren[i];
|
||||
|
||||
child.Measure(constraint);
|
||||
var childDesiredSize = child.DesiredSize;
|
||||
|
||||
if (maxChildDesiredHeight < childDesiredSize.Height)
|
||||
{
|
||||
maxChildDesiredHeight = childDesiredSize.Height;
|
||||
}
|
||||
}
|
||||
|
||||
var childBounds = new Rect(0, 0, 0, maxChildDesiredHeight);
|
||||
_layoutStatus = ColLayout.GetLayoutStatus(constraint.Width);
|
||||
|
||||
foreach (var child in InternalChildren.OfType<Col>())
|
||||
{
|
||||
var cellCount = child.GetLayoutCellCount(_layoutStatus);
|
||||
totalCellCount += cellCount;
|
||||
|
||||
if (totalCellCount > ColLayout.ColMaxCellCount)
|
||||
{
|
||||
childBounds.X = 0;
|
||||
childBounds.Y += maxChildDesiredHeight;
|
||||
totalCellCount = cellCount;
|
||||
totalRowCount++;
|
||||
}
|
||||
|
||||
var childWidth = cellCount * itemWidth;
|
||||
childBounds.Width = childWidth;
|
||||
child.Arrange(childBounds);
|
||||
childBounds.X += childWidth;
|
||||
}
|
||||
|
||||
return new Size(constraint.Width, maxChildDesiredHeight * totalRowCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Col : Panel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Row : Panel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum ColLayoutStatus
|
||||
{
|
||||
Xs,
|
||||
Sm,
|
||||
Md,
|
||||
Lg,
|
||||
Xl,
|
||||
Xxl,
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverView\CoverView.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverView\CoverViewContent.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverView\CoverViewItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Grid\Col.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Grid\Row.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\GifImage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageViewer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Input\ComboBox.cs" />
|
||||
@@ -72,8 +74,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Shield.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\TransitioningContentControl.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\CirclePanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\Col.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\Row.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\SimplePanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\WaterfallPanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\ProgressBar\CircleProgressBar.cs" />
|
||||
@@ -114,6 +114,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\BadgeStatus.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ChatMessageType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ChatRoleType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ColLayoutStatus.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ExpandMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\InfoType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\IpType.cs" />
|
||||
@@ -219,6 +220,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\String2VisibilityConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\String2VisibilityReConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\TreeViewItemMarginConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\ColLayout.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\ColorExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\DialogExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\EnumerableExtension.cs" />
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Windows.Markup;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Tools.Extension
|
||||
{
|
||||
public class ColLayout : MarkupExtension
|
||||
{
|
||||
public static readonly int ColMaxCellCount = 24;
|
||||
|
||||
public static readonly int XsMaxWidth = 768;
|
||||
|
||||
public static readonly int SmMaxWidth = 992;
|
||||
|
||||
public static readonly int MdMaxWidth = 1200;
|
||||
|
||||
public static readonly int LgMaxWidth = 1920;
|
||||
|
||||
public static readonly int XlMaxWidth = 2560;
|
||||
|
||||
public int Xs { get; set; } = 24;
|
||||
|
||||
public int Sm { get; set; } = 12;
|
||||
|
||||
public int Md { get; set; } = 8;
|
||||
|
||||
public int Lg { get; set; } = 6;
|
||||
|
||||
public int Xl { get; set; } = 4;
|
||||
|
||||
public int Xxl { get; set; } = 2;
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ColLayout
|
||||
{
|
||||
Xs = Xs,
|
||||
Sm = Sm,
|
||||
Md = Md,
|
||||
Lg = Lg,
|
||||
Xl = Xl,
|
||||
Xxl = Xxl
|
||||
};
|
||||
}
|
||||
|
||||
public static ColLayoutStatus GetLayoutStatus(double width)
|
||||
{
|
||||
if (width < MdMaxWidth)
|
||||
{
|
||||
if (width < SmMaxWidth)
|
||||
{
|
||||
if (width < XsMaxWidth)
|
||||
{
|
||||
return ColLayoutStatus.Xs;
|
||||
}
|
||||
return ColLayoutStatus.Sm;
|
||||
}
|
||||
return ColLayoutStatus.Md;
|
||||
}
|
||||
if (width < XlMaxWidth)
|
||||
{
|
||||
if (width < LgMaxWidth)
|
||||
{
|
||||
return ColLayoutStatus.Lg;
|
||||
}
|
||||
return ColLayoutStatus.Xl;
|
||||
}
|
||||
return ColLayoutStatus.Xxl;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user