Class GridLayout

GoDiagram®
v10.0.12
by Northwoods Software®

This simple layout places all of the Parts in a grid-like arrangement, ordered, spaced apart, and wrapping as needed. It ignores any Links connecting the Nodes being laid out.

Inheritance
GridLayout
Namespace: Northwoods.Go.Layouts
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
public class GridLayout : Layout
Remarks

There are many samples that use GridLayout. Every Palette uses a GridLayout by default.

If you want to experiment interactively with most of the properties, try the Grid Layout sample. See samples that make use of GridLayout in the samples index.

By default this layout will sort all of the Parts alphabetically (comparing Text values, respecting case) and position them left-to-right, separated by Spacing.Width, until they do not fit in the current row. At that time it starts a new row, separated from the previous row by Spacing.Height. There is a uniform cell size equal to the maximum Part width (plus spacing width) and the maximum part height (plus spacing height). At least one part is placed in each row, even if the part by itself is wider than the wrapping width.

You can specify values for the CellSize Width and Height. If a part is wider than the cell size, it spans more than one cell in the row. You can also specify a value for the WrappingWidth, which will be used instead of the diagram's viewport width, to control when each row is considered "full". The value of IsViewportSized will be true when the value of WrappingWidth is NaN. This causes the layout to be performed again automatically as the viewport changes size.

You can also set WrappingColumn to limit the double of items in each row. Both the WrappingWidth and the WrappingColumn are respected when deciding when to wrap to the next row.

This layout is sufficiently simple that it does not extend NetworkLayout<N, V, E, Y>.

Constructors

GridLayout()

Constructs a GridLayout with no owning Diagram.

Declaration
public GridLayout()

Fields

SmartComparer

This static comparer is used to compare the Text values of the argument Parts. If the text ends in a number, the values are compared as numbers rather than lexicographically.

Declaration
public static readonly Comparison<Part> SmartComparer
Field Value
Type Description
Comparison<Part>
Remarks

Alternatively you may wish to use StandardComparer or write your own comparison function.

StandardComparer

This static comparer is used to compare the Text values of the argument Parts. This just does a simple case-sensitive string comparison.

Declaration
public static readonly Comparison<Part> StandardComparer
Field Value
Type Description
Comparison<Part>
Remarks

Alternatively you may wish to use SmartComparer or write your own comparison function.

Properties

Alignment

Gets or sets whether the Location or the position should be used to arrange each part.

Declaration
public GridAlignment Alignment { get; set; }
Property Value
Type Description
GridAlignment
Remarks

The default value is Location -- the Locations will be aligned in a grid.

Arrangement

Gets or sets how to arrange the parts.

Declaration
public GridArrangement Arrangement { get; set; }
Property Value
Type Description
GridArrangement
Remarks

The default value is LeftToRight.

CellSize

Gets or sets the minimum part size by which each part is positioned in the grid.

Declaration
public Size CellSize { get; set; }
Property Value
Type Description
Size
Remarks

The default value is NaN x NaN. The units are in document coordinates.

When the cell size is smaller than a part, the part will occupy more than one cell. This allows parts to be positioned closer to each other, but then variations in part sizes may cause them not to be aligned in perfect rows or columns.

Comparer

Gets or sets the comparison function used to sort the parts.

Declaration
public Comparison<Part> Comparer { get; set; }
Property Value
Type Description
Comparison<Part>
Remarks

The default value is a case-insensitive alphabetic comparison using the Text property of each part.

new GridLayout {
  Sorting = GridSorting.Ascending,
  Comparer = (pa, pb) => {
    var da = pa.Data as NodeData;
    var db = pb.Data as NodeData;
    if (da.SomeProperty < db.SomeProperty) return -1;
    if (da.SomeProperty > db.SomeProperty) return 1;
    return 0;
  }
}

Sorting

Gets or sets what order to place the parts.

Declaration
public GridSorting Sorting { get; set; }
Property Value
Type Description
GridSorting
Remarks

The default value is Ascending.

Spacing

Gets or sets the minimum horizontal and vertical space between parts.

Declaration
public Size Spacing { get; set; }
Property Value
Type Description
Size
Remarks

The default value is 10 x 10. The units are in document coordinates.

WrappingColumn

Gets or sets the maximum number of columns.

Declaration
public int WrappingColumn { get; set; }
Property Value
Type Description
int
Remarks

The default is 0, meaning not to limit the number of columns. 1 is a common value to produce a single column of parts. Must be greater than or equal to 0.

WrappingWidth

Gets or sets the wrapping width.

Declaration
public double WrappingWidth { get; set; }
Property Value
Type Description
double
Remarks

The default is NaN, meaning to use the width of the diagram's panel's viewport. Must be a value greater than 0.

Methods

DoLayout(IEnumerable<Part>)

Assign the positions of the parts, ignoring any links.

Declaration
public override void DoLayout(IEnumerable<Part> coll = null)
Parameters
Type Name Description
IEnumerable<Part> coll
Overrides