LayoutSpec ls = new LayoutSpec(); XTab x1 = ls.AddXTab(); YTab y1 = ls.AddYTab(); ls.AddArea(ls.Left, ls.Top, x1, y1, button1); ls.AddArea(x1, ls.Top, ls.Right, y1, button2); ls.AddArea(ls.Left, y1, ls.Right, ls.Bottom, button3); // give the two columns the same width and the two rows the same height ls.AddConstraint(new double[] { 2, -1 }, new Variable[] { x1, ls.Right }, OperatorType.EQ, 0); ls.AddConstraint(new double[] { 2, -1 }, new Variable[] { y1, ls.Bottom }, OperatorType.EQ, 0); |
This example shows how three buttons are arranged using three areas. The buttons have already been added to the window, but have not been arraged. Their location and size is determined by the ALM specification. No matter how we resize the window, the two columns will always have the same width, and the two rows will always have the same height due to the two linear constraints. On a Pentium 4 with 3.4 Ghz layout calculation takes about 0.3 milliseconds. Interestingly, on a Pentium M with 1.6 Ghz the calculation takes also about 0.3 milliseconds. On a Pentium 3 with 788 Mhz the calculation takes about 0.7 milliseconds.
LayoutSpec ls = new LayoutSpec(); Column c1 = ls.AddColumn(); c1.Constraints.Add(c1.Left.IsEqual(ls.Left)); c1.Constraints.Add(c1.Right.IsEqual(ls.Right)); Row r1 = ls.AddRow(); r1.Constraints.Add(r1.Top.IsEqual(ls.Top)); Row r3 = ls.AddRow(); r3.Constraints.Add(r3.Bottom.IsEqual(ls.Bottom)); r1.Next = r3; Row r2 = ls.AddRow(); r2.InsertAfter(r1); Area a1 = ls.AddArea(r1, c1, b1); a1.HAlignment = ALM.HorizontalAlignment.LEFT; a1.VAlignment = VerticalAlignment.TOP; Area a2 = ls.AddArea(r2, c1, b2); a2.HAlignment = ALM.HorizontalAlignment.CENTER; a2.VAlignment = VerticalAlignment.CENTER; Area a3 = ls.AddArea(r3, c1, b3); a3.HAlignment = ALM.HorizontalAlignment.RIGHT; a3.VAlignment = VerticalAlignment.BOTTOM; r2.HasSameHeightAs(r1); r3.HasSameHeightAs(r1); |
This example shows how layouts can be specified using abstractions for rows and columns. In the first block of the source code a new column c1 is created that spans across the whole GUI. In the following block, we create two rows r1 and r3, with r1 being at the top of the GUI, and r3 ending at the bottom of the GUI. The code demonstrates how the Next property can be used to specify which rows (or columns) are directly adjacent to which other rows (or columns). Analogously, there is a property Previous. It then shows how a row r2 is inserted after r1. Like this, rows and columns can be conveniently arranged, and dynamically rearranged, inserted and deleted. The three following blocks demonstrate alignment of controls in areas. The last block shows an example of convenience methods for setting same-height and same-width constraints for rows and columns. On a Pentium 4 with 3.4 Ghz layout calculation takes about 0.3 milliseconds. A similar calculation time is achieved on a Pentium M with 1.6 Ghz. On a Pentium 3 with 788 Mhz the calculation takes about 0.8 milliseconds.
LayoutSpec ls = new LayoutSpec(); XTab x1 = ls.AddXTab(); XTab x2 = ls.AddXTab(); XTab x3 = ls.AddXTab(); YTab y1 = ls.AddYTab(); YTab y2 = ls.AddYTab(); YTab y3 = ls.AddYTab(); YTab y4 = ls.AddYTab(); YTab y5 = ls.AddYTab(); ls.AddArea(ls.Left, ls.Top, x1, y1, button1); ls.AddArea(x1, ls.Top, x2, y1, button2); ls.AddArea(ls.Left, y1, x1, y2, button3); ls.AddArea(x1, y1, x2, y2, button4); ls.AddArea(ls.Left, y2, x1, y3, button5); ls.AddArea(x1, y2, x2, y3, button6); // give the buttons the same size ls.AddConstraint(new double[] { 2, -1 }, new Variable[] { x1, x2 }, OperatorType.EQ, 0); ls.AddConstraint(new double[] { 2, -1 }, new Variable[] { y1, y2 }, OperatorType.EQ, 0); ls.AddConstraint(new double[] { 1, 1, -1 }, new Variable[] { y1, y2, y3 }, OperatorType.EQ, 0); ls.AddArea(ls.Left, y3, x2, y4, checkedListBox1); ls.AddArea(x2, ls.Top, ls.Right, y2, textBox1); ls.AddArea(ls.Left, y4, x3, y5, listView1); ls.AddArea(x3, y2, ls.Right, y5, textBox2); Area richTextBox1Area = ls.AddArea(x2, y2, x3, y4, richTextBox1); richTextBox1Area.LeftMargin = richTextBox1Area.TopMargin = richTextBox1Area.RightMargin = richTextBox1Area.BottomMargin = 10; Area label1Area = ls.AddArea(ls.Left, y5, x2, ls.Bottom, label1); label1Area.HAlignment = ALM.HorizontalAlignment.LEFT; label1Area.TopMargin = label1Area.BottomMargin = 4; Area label2Area = ls.AddArea(x2, y5, x3, ls.Bottom, label2); label2Area.HAlignment = ALM.HorizontalAlignment.CENTER; label2Area.TopMargin = label2Area.BottomMargin = 4; Area label3Area = ls.AddArea(x3, y5, ls.Right, ls.Bottom, label3); label3Area.HAlignment = ALM.HorizontalAlignment.RIGHT; label3Area.TopMargin = label3Area.BottomMargin = 4; |
In the first block of the source code we add all the x-tabs and y-tabs that we need for the layout. Afterwards, the buttons are added. The following block adds three linear constraints that make sure that the buttons will always have the same size. The rest of the code adds arweas for the the other controls, demonstrating some properties for margins and alignment. On a Pentium 4 with 3.4Ghz layout calculation takes about 0.7 milliseconds. A similar calculation time is achieved on a Pentium M with 1.6Ghz. On a Pentium 3 with 788 Mhz the calculation takes about 1.4 milliseconds.
This layout contains 100 areas. It was generated randomly. Note that not all areas are visible due to the lack of screen space. ALM offers rigidity parameters to let the user specify which areas should be given preference in such a situation. On a Pentium 4 with 3.4Ghz layout calculation takes about 5 milliseconds. On a Pentium M with 1.6Ghz the calculation takes about 6 milliseconds. On a Pentium 3 with 788 Mhz the calculation takes about 15 milliseconds.