ui/wpf/UIcore/Container.cs

changeset 83
a38aec91bd66
child 84
a56c2baa9429
equal deleted inserted replaced
82:0cdb8089a29f 83:a38aec91bd66
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Windows;
7 using System.Windows.Controls;
8
9 namespace UI
10 {
11 public interface Container
12 {
13 void Add(UIElement control, bool fill);
14 }
15
16 public enum BoxOrientation
17 {
18 VERTICAL,
19 HORIZONTAL
20 }
21
22 public class BoxContainer : Container
23 {
24 public Grid Grid;
25 public BoxOrientation Orientation;
26
27 private int x = 0;
28 private int y = 0;
29
30 private bool filled = false;
31
32 public BoxContainer(Grid grid, BoxOrientation orientation)
33 {
34 Grid = grid;
35 Orientation = orientation;
36 if(Orientation == BoxOrientation.HORIZONTAL)
37 {
38 RowDefinition row = new RowDefinition();
39 row.Height = new GridLength(1, GridUnitType.Star);
40 Grid.RowDefinitions.Add(row);
41 }
42 else
43 {
44 ColumnDefinition col = new ColumnDefinition();
45 col.Width = new GridLength(1, GridUnitType.Star);
46 Grid.ColumnDefinitions.Add(col);
47 }
48 }
49
50 public void Add(UIElement control, bool fill)
51 {
52 if(Orientation == BoxOrientation.HORIZONTAL)
53 {
54 ColumnDefinition col = new ColumnDefinition();
55 if(filled && fill)
56 {
57 fill = false;
58 Console.WriteLine("BoxContainer can only contain one filled control");
59 }
60 if(fill)
61 {
62 col.Width = new GridLength(1, GridUnitType.Star);
63 filled = true;
64 }
65 else
66 {
67 col.Width = GridLength.Auto;
68 }
69 Grid.ColumnDefinitions.Add(col);
70 }
71 else
72 {
73 RowDefinition row = new RowDefinition();
74 if (filled && fill)
75 {
76 fill = false;
77 Console.WriteLine("BoxContainer can only contain one filled control");
78 }
79 if(fill)
80 {
81 row.Height = new GridLength(1, GridUnitType.Star);
82 filled = true;
83 }
84 else
85 {
86 row.Height = GridLength.Auto;
87 }
88 Grid.RowDefinitions.Add(row);
89 }
90
91 Grid.SetColumn(control, x);
92 Grid.SetRow(control, y);
93 Grid.Children.Add(control);
94
95 if(Orientation == BoxOrientation.HORIZONTAL)
96 {
97 x++;
98 }
99 else
100 {
101 y++;
102 }
103 }
104 }
105
106 public class GridContainer : Container
107 {
108 public Grid Grid;
109
110 public GridContainer(System.Windows.Controls.Grid grid)
111 {
112 Grid = grid;
113 }
114
115 public void Add(UIElement control, bool fill)
116 {
117
118 }
119 }
120 }

mercurial