Skip to content

Commit fe53834

Browse files
committed
VerticalGrid
1 parent 6232f6c commit fe53834

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed
File renamed without changes.

DWBox/Controls/VerticalGrid.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
5+
namespace DWBox
6+
{
7+
// basically uniform grid, but adding columns only on full rows
8+
// prefers vertical arrangement, not really uniform
9+
public class VerticalGrid : Panel
10+
{
11+
protected override Size MeasureOverride(Size constraint)
12+
{
13+
UpdateComputedValues();
14+
15+
Size childConstraint = new Size(constraint.Width / _columns, constraint.Height / _rows);
16+
double maxChildDesiredWidth = 0.0;
17+
double maxChildDesiredHeight = 0.0;
18+
19+
for (int i = 0, count = InternalChildren.Count; i < count; ++i)
20+
{
21+
UIElement child = InternalChildren[i];
22+
child.Measure(childConstraint);
23+
Size childDesiredSize = child.DesiredSize;
24+
25+
if (maxChildDesiredWidth < childDesiredSize.Width)
26+
maxChildDesiredWidth = childDesiredSize.Width;
27+
28+
if (maxChildDesiredHeight < childDesiredSize.Height)
29+
maxChildDesiredHeight = childDesiredSize.Height;
30+
}
31+
32+
return new Size((maxChildDesiredWidth * _columns), (maxChildDesiredHeight * _rows));
33+
}
34+
35+
protected override Size ArrangeOverride(Size arrangeSize)
36+
{
37+
Rect childBounds = new Rect(0, 0, arrangeSize.Width / _columns, arrangeSize.Height / _rows);
38+
double xStep = childBounds.Width;
39+
double xBound = arrangeSize.Width - 1.0;
40+
41+
foreach (UIElement child in InternalChildren)
42+
{
43+
child.Arrange(childBounds);
44+
45+
if (child.Visibility != Visibility.Collapsed)
46+
{
47+
childBounds.X += xStep;
48+
if (childBounds.X >= xBound)
49+
{
50+
childBounds.Y += childBounds.Height;
51+
childBounds.X = 0;
52+
}
53+
}
54+
}
55+
56+
return arrangeSize;
57+
}
58+
59+
private void UpdateComputedValues()
60+
{
61+
int nonCollapsedCount = 0;
62+
63+
for (int i = 0, count = InternalChildren.Count; i < count; ++i)
64+
{
65+
UIElement child = InternalChildren[i];
66+
if (child.Visibility != Visibility.Collapsed)
67+
nonCollapsedCount++;
68+
}
69+
70+
if (nonCollapsedCount == 0)
71+
nonCollapsedCount = 1;
72+
73+
_columns = (int)Math.Sqrt(nonCollapsedCount);
74+
_rows = nonCollapsedCount / _columns;
75+
if ((_rows * _columns) < nonCollapsedCount)
76+
_rows++;
77+
}
78+
79+
private int _rows;
80+
private int _columns;
81+
}
82+
}

DWBox/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<local:RenderingsLayoutViewModel Name="Uniform grid" Icon="{StaticResource GridPane}">
150150
<local:RenderingsLayoutViewModel.ItemsPanelTemplate>
151151
<ItemsPanelTemplate>
152-
<UniformGrid />
152+
<local:VerticalGrid />
153153
</ItemsPanelTemplate>
154154
</local:RenderingsLayoutViewModel.ItemsPanelTemplate>
155155
</local:RenderingsLayoutViewModel>

DWBox/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
[assembly: AssemblyVersion("2.3.0.0")]
5353
[assembly: AssemblyFileVersion("2.3.0.0")]
5454

55-
// 2.3.0.0 layout options, text alignment, paragraph alignment, word wrapping, remember last added font, antialiasing mode, locale list, Alt+X, add one per family font
55+
// 2.3.0.0 layout options, text alignment, paragraph alignment, word wrapping, remember last added font, antialiasing mode, locale list, Alt+X, add one per family font, less uniform grid
5656
// 2.2.0.0 copy image/box/name to clipboard, DirectWriteElement measuring, bitmap AV fix, empty GlyphRun analysis fix, remove all but this font, save settings on drop, \u U+ and acronyms decoding, core switch
5757
// 2.1.0.0 refactor DWrite into namespace & struct with properties, text analysis, remove filter, set size, font face strings, add all progress, remember last input
5858
// 2.0.0.1 instance brush

0 commit comments

Comments
 (0)