ui/wpf/UIcore/Container.cs

Sun, 15 Jan 2017 15:08:07 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Jan 2017 15:08:07 +0100
changeset 132
a24465cc7262
parent 104
3efe0210e27e
child 135
b9dc9cdfa23a
permissions
-rw-r--r--

fixes VS settings

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; }
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
24
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
25 public Layout()
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
26 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
27 Reset();
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
28 }
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 public bool IsFill(bool fill)
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
31 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
32 if (Fill != null)
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
33 {
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 return (bool)Fill;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
36 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
37 return fill;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
38 }
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 public void Reset()
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
41 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
42 Fill = null;
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
43 Hexpand = false;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
44 Vexpand = false;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
45 NewLine = false;
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
46 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
47 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
48
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 public enum BoxOrientation
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 VERTICAL,
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 HORIZONTAL
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
55 public class BoxContainer : Grid, Container
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
57 public Layout Layout { get; set; }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
58
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
59 private BoxOrientation Orientation;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 private int x = 0;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 private int y = 0;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 private bool filled = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
66 public BoxContainer(BoxOrientation orientation) : base()
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
68 Layout = new Layout();
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
69
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 Orientation = orientation;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 if(Orientation == BoxOrientation.HORIZONTAL)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 RowDefinition row = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 row.Height = new GridLength(1, GridUnitType.Star);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
75 RowDefinitions.Add(row);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 else
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 ColumnDefinition col = new ColumnDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 col.Width = new GridLength(1, GridUnitType.Star);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
81 ColumnDefinitions.Add(col);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
85 public BoxContainer(Container parent, BoxOrientation orientation) : this(orientation)
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 parent.Add(this, true);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
88 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
92 fill = Layout.IsFill(fill);
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
93
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 if(Orientation == BoxOrientation.HORIZONTAL)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 ColumnDefinition col = new ColumnDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 if(filled && fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 fill = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 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
101 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 if(fill)
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 col.Width = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 filled = true;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 else
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 col.Width = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
111 ColumnDefinitions.Add(col);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 else
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 RowDefinition row = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 if (filled && fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 fill = false;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 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
120 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 if(fill)
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 row.Height = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 filled = true;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 else
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 row.Height = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
130 RowDefinitions.Add(row);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 Grid.SetColumn(control, x);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 Grid.SetRow(control, y);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
135 Children.Add(control);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 if(Orientation == BoxOrientation.HORIZONTAL)
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 x++;
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 else
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 y++;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
145
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
146 Layout.Reset();
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 }
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
148
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
149 public static BoxContainer CreateBoxContainer(Container parent, BoxOrientation orientation)
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
150 {
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
151 return Application.GetInstance().Exec<BoxContainer>(() => new BoxContainer(parent, orientation));
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
152 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
155 public class GridContainer : Grid, Container
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
157 public Layout Layout { get; set; }
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
158
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
159 private int X = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
160 private int Y = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
161 private int CurrentWidth = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
162 private int CurrentHeight = 0;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
164 private int ColSpacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
165 private int RowSpacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
166
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
167 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
168 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
169 Layout = new Layout();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
170
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
171 Margin = new Thickness(margin);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
172 ColSpacing = colspacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
173 RowSpacing = rowspacing;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
174
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
175 parent.Add(this, true);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
180 if(Layout.NewLine)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
181 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
182 X = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
183 Y++;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
184 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
186 ColumnDefinition col;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
187 RowDefinition row;
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
188 bool getcol = false;
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
189 if(X >= CurrentWidth)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
190 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
191 if (ColSpacing > 0 && X != 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
192 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
193 ColumnDefinition spaceCol = new ColumnDefinition();
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
194 spaceCol.Width = new GridLength(ColSpacing, GridUnitType.Pixel);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
195 ColumnDefinitions.Add(spaceCol);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
196 X++;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
197 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
198
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
199 col = new ColumnDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
200 col.Width = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
201 ColumnDefinitions.Add(col);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
202
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
203 CurrentWidth = X + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
204 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
205 else
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
206 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
207 if (ColSpacing > 0 && X % 2 > 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
208 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
209 X++;
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 col = ColumnDefinitions.ElementAt(X);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
212 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
213
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
214 if(getcol)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
215 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
216 col = ColumnDefinitions.ElementAt(X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
217 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
218
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
219 if (Y >= CurrentHeight)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
220 {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
221 if (RowSpacing > 0 && Y != 0)
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
222 {
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
223 RowDefinition spaceRow = new RowDefinition();
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
224 spaceRow.Height = new GridLength(RowSpacing, GridUnitType.Pixel);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
225 RowDefinitions.Add(spaceRow);
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
226 Y++;
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
227 }
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
228
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
229 row = new RowDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
230 row.Height = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
231 RowDefinitions.Add(row);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
232 CurrentHeight = Y + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
233 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
234 else
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 row = RowDefinitions.ElementAt(Y);
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
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
239 if(Layout.Hexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
240 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
241 col.Width = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
242 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
243 if(Layout.Vexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
244 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
245 row.Height = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
246 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
247
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
248 Grid.SetColumn(control, X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
249 Grid.SetRow(control, Y);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
250 Children.Add(control);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
251
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
252 Layout.Reset();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
253 X++;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
254 }
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 public static GridContainer CreateGridContainer(Container parent, int margin, int colspacing, int rowspacing)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
257 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
258 return Application.GetInstance().Exec<GridContainer>(() => new GridContainer(parent, margin, colspacing, rowspacing));
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 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 }

mercurial