ui/wpf/UIcore/Container.cs

Wed, 20 Jan 2016 17:37:52 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 20 Jan 2016 17:37:52 +0100
changeset 103
6a6718269c22
parent 101
1c943d43fa81
child 104
3efe0210e27e
permissions
-rw-r--r--

added drawing area (Qt)

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
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
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
168 parent.Add(this, true);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 {
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
173 if(Layout.NewLine)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
174 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
175 X = 0;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
176 Y++;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
177 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
179 ColumnDefinition col;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
180 RowDefinition row;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
181 if(X >= CurrentWidth)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
182 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
183 col = new ColumnDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
184 col.Width = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
185 ColumnDefinitions.Add(col);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
186 CurrentWidth = X + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
187 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
188 else
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
189 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
190 col = ColumnDefinitions.ElementAt(X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
191 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
192
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
193 if (Y >= CurrentHeight)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
194 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
195 row = new RowDefinition();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
196 row.Height = GridLength.Auto;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
197 RowDefinitions.Add(row);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
198 CurrentHeight = Y + 1;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
199 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
200 else
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 row = RowDefinitions.ElementAt(Y);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
203 }
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 if(Layout.Hexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
206 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
207 col.Width = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
208 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
209 if(Layout.Vexpand)
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
210 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
211 row.Height = new GridLength(1, GridUnitType.Star);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
212 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
213
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
214 Grid.SetColumn(control, X);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
215 Grid.SetRow(control, Y);
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
216 Children.Add(control);
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 Layout.Reset();
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
219 X++;
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
220 }
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
221
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
222 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
223 {
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
224 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
225 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 }
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }

mercurial