ui/wpf/UIcore/Container.cs

Sun, 22 Jan 2017 18:02:45 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 22 Jan 2017 18:02:45 +0100
changeset 136
1df2fb3d079c
parent 135
b9dc9cdfa23a
child 138
d781436e2490
permissions
-rw-r--r--

adds gridwidth layout option (WPF)

83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 using System;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 using System.Collections.Generic;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 using System.Linq;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 using System.Text;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 using System.Threading.Tasks;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 using System.Windows;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 using System.Windows.Controls;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 namespace UI
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 public interface Container
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
13 Layout Layout { get; set; }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
14
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 void Add(UIElement control, bool fill);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
18 public class Layout
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
19 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
20 public bool? Fill { get; set; }
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
21 public bool Hexpand { get; set; }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
22 public bool Vexpand { get; set; }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
23 public bool NewLine { get; set; }
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
24 public int GridWidth { get; set; }
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
25
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
26 public Layout()
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
27 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
28 Reset();
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
29 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
30
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
31 public bool IsFill(bool fill)
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
32 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
33 if (Fill != null)
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
34 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
35
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
36 return (bool)Fill;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
37 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
38 return fill;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
39 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
40
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
41 public void Reset()
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
42 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
43 Fill = null;
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
44 Hexpand = false;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
45 Vexpand = false;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
46 NewLine = false;
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
47 GridWidth = 1;
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
48 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
49 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
50
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 public enum BoxOrientation
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 VERTICAL,
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 HORIZONTAL
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
57 public class BoxContainer : Grid, Container
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
59 public Layout Layout { get; set; }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
60
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
61 private BoxOrientation Orientation;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 private int x = 0;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 private int y = 0;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 private bool filled = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
68 public BoxContainer(BoxOrientation orientation) : base()
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
70 Layout = new Layout();
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
71
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 Orientation = orientation;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 if(Orientation == BoxOrientation.HORIZONTAL)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 RowDefinition row = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 row.Height = new GridLength(1, GridUnitType.Star);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
77 RowDefinitions.Add(row);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 else
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 ColumnDefinition col = new ColumnDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 col.Width = new GridLength(1, GridUnitType.Star);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
83 ColumnDefinitions.Add(col);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
86
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
87 public BoxContainer(Container parent, BoxOrientation orientation) : this(orientation)
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
88 {
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
89 parent.Add(this, true);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
90 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
94 fill = Layout.IsFill(fill);
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
95
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 if(Orientation == BoxOrientation.HORIZONTAL)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 ColumnDefinition col = new ColumnDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 if(filled && fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 fill = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 Console.WriteLine("BoxContainer can only contain one filled control");
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 if(fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 col.Width = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 filled = true;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 else
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 col.Width = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
113 ColumnDefinitions.Add(col);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 else
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 RowDefinition row = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 if (filled && fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 fill = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 Console.WriteLine("BoxContainer can only contain one filled control");
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 if(fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 row.Height = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 filled = true;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 else
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 row.Height = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
132 RowDefinitions.Add(row);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 Grid.SetColumn(control, x);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 Grid.SetRow(control, y);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
137 Children.Add(control);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 if(Orientation == BoxOrientation.HORIZONTAL)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 x++;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 else
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 y++;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
147
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
148 Layout.Reset();
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
152 public class GridContainer : Grid, Container
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
154 public Layout Layout { get; set; }
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
155
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
156 private int X = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
157 private int Y = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
158 private int CurrentWidth = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
159 private int CurrentHeight = 0;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
161 private int ColSpacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
162 private int RowSpacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
163
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
164 public GridContainer(Container parent, int margin, int colspacing, int rowspacing) : base()
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
166 Layout = new Layout();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
167
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
168 Margin = new Thickness(margin);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
169 ColSpacing = colspacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
170 RowSpacing = rowspacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
171
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
172 parent.Add(this, true);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
177 if(Layout.NewLine)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
178 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
179 X = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
180 Y++;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
181 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
183 ColumnDefinition col;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
184 RowDefinition row;
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
185 bool getcol = false;
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
186 if(X >= CurrentWidth)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
187 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
188 if (ColSpacing > 0 && X != 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
189 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
190 ColumnDefinition spaceCol = new ColumnDefinition();
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
191 spaceCol.Width = new GridLength(ColSpacing, GridUnitType.Pixel);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
192 ColumnDefinitions.Add(spaceCol);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
193 X++;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
194 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
195
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
196 col = new ColumnDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
197 col.Width = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
198 ColumnDefinitions.Add(col);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
199
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
200 CurrentWidth = X + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
201 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
202 else
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
203 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
204 if (ColSpacing > 0 && X % 2 > 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
205 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
206 X++;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
207 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
208 col = ColumnDefinitions.ElementAt(X);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
209 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
210
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
211 if(getcol)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
212 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
213 col = ColumnDefinitions.ElementAt(X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
214 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
215
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
216 if (Y >= CurrentHeight)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
217 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
218 if (RowSpacing > 0 && Y != 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
219 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
220 RowDefinition spaceRow = new RowDefinition();
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
221 spaceRow.Height = new GridLength(RowSpacing, GridUnitType.Pixel);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
222 RowDefinitions.Add(spaceRow);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
223 Y++;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
224 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
225
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
226 row = new RowDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
227 row.Height = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
228 RowDefinitions.Add(row);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
229 CurrentHeight = Y + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
230 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
231 else
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
232 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
233 row = RowDefinitions.ElementAt(Y);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
234 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
235
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
236 if(Layout.Hexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
237 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
238 col.Width = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
239 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
240 if(Layout.Vexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
241 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
242 row.Height = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
243 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
244
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
245 int gridwidth = Layout.GridWidth;
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
246 if(gridwidth > 1)
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
247 {
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
248 gridwidth++;
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
249 }
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
250
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
251 Grid.SetColumn(control, X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
252 Grid.SetRow(control, Y);
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
253 Grid.SetColumnSpan(control, gridwidth);
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
254 Children.Add(control);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
255
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
256 Layout.Reset();
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
257 X += gridwidth;
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
258 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 }

mercurial