ui/wpf/UIcore/Container.cs

changeset 138
d781436e2490
parent 136
1df2fb3d079c
equal deleted inserted replaced
137:c9b8b9e0cfe8 138:d781436e2490
20 public bool? Fill { get; set; } 20 public bool? Fill { get; set; }
21 public bool Hexpand { get; set; } 21 public bool Hexpand { get; set; }
22 public bool Vexpand { get; set; } 22 public bool Vexpand { get; set; }
23 public bool NewLine { get; set; } 23 public bool NewLine { get; set; }
24 public int GridWidth { get; set; } 24 public int GridWidth { get; set; }
25 public String Label { get; set; }
25 26
26 public Layout() 27 public Layout()
27 { 28 {
28 Reset(); 29 Reset();
29 } 30 }
43 Fill = null; 44 Fill = null;
44 Hexpand = false; 45 Hexpand = false;
45 Vexpand = false; 46 Vexpand = false;
46 NewLine = false; 47 NewLine = false;
47 GridWidth = 1; 48 GridWidth = 1;
49 Label = null;
48 } 50 }
49 } 51 }
50 52
51 public enum BoxOrientation 53 public enum BoxOrientation
52 { 54 {
57 public class BoxContainer : Grid, Container 59 public class BoxContainer : Grid, Container
58 { 60 {
59 public Layout Layout { get; set; } 61 public Layout Layout { get; set; }
60 62
61 private BoxOrientation Orientation; 63 private BoxOrientation Orientation;
64 private int Spacing;
62 65
63 private int x = 0; 66 private int x = 0;
64 private int y = 0; 67 private int y = 0;
65 68
66 private bool filled = false; 69 private bool filled = false;
67 70
68 public BoxContainer(BoxOrientation orientation) : base() 71 public BoxContainer(BoxOrientation orientation, int margin, int spacing) : base()
69 { 72 {
70 Layout = new Layout(); 73 Layout = new Layout();
74 Margin = new Thickness(margin);
75 Spacing = spacing;
71 76
72 Orientation = orientation; 77 Orientation = orientation;
73 if(Orientation == BoxOrientation.HORIZONTAL) 78 if(Orientation == BoxOrientation.HORIZONTAL)
74 { 79 {
75 RowDefinition row = new RowDefinition(); 80 RowDefinition row = new RowDefinition();
82 col.Width = new GridLength(1, GridUnitType.Star); 87 col.Width = new GridLength(1, GridUnitType.Star);
83 ColumnDefinitions.Add(col); 88 ColumnDefinitions.Add(col);
84 } 89 }
85 } 90 }
86 91
87 public BoxContainer(Container parent, BoxOrientation orientation) : this(orientation) 92 public BoxContainer(Container parent, BoxOrientation orientation, int margin, int spacing) : this(orientation, margin, spacing)
88 { 93 {
89 parent.Add(this, true); 94 parent.Add(this, true);
90 } 95 }
91 96
92 public void Add(UIElement control, bool fill) 97 public void Add(UIElement control, bool fill)
93 { 98 {
94 fill = Layout.IsFill(fill); 99 fill = Layout.IsFill(fill);
95 100
96 if(Orientation == BoxOrientation.HORIZONTAL) 101 if(Orientation == BoxOrientation.HORIZONTAL)
97 { 102 {
103 if(Spacing > 0)
104 {
105 ColumnDefinition spaceCol = new ColumnDefinition();
106 spaceCol.Width = new GridLength(Spacing, GridUnitType.Pixel);
107 ColumnDefinitions.Add(spaceCol);
108 x++;
109 }
110
98 ColumnDefinition col = new ColumnDefinition(); 111 ColumnDefinition col = new ColumnDefinition();
99 if(filled && fill) 112 if(filled && fill)
100 { 113 {
101 fill = false; 114 fill = false;
102 Console.WriteLine("BoxContainer can only contain one filled control"); 115 Console.WriteLine("BoxContainer can only contain one filled control");
112 } 125 }
113 ColumnDefinitions.Add(col); 126 ColumnDefinitions.Add(col);
114 } 127 }
115 else 128 else
116 { 129 {
130 if (Spacing > 0)
131 {
132 RowDefinition spaceRow = new RowDefinition();
133 spaceRow.Height = new GridLength(Spacing, GridUnitType.Pixel);
134 RowDefinitions.Add(spaceRow);
135 y++;
136 }
137
117 RowDefinition row = new RowDefinition(); 138 RowDefinition row = new RowDefinition();
118 if (filled && fill) 139 if (filled && fill)
119 { 140 {
120 fill = false; 141 fill = false;
121 Console.WriteLine("BoxContainer can only contain one filled control"); 142 Console.WriteLine("BoxContainer can only contain one filled control");
255 276
256 Layout.Reset(); 277 Layout.Reset();
257 X += gridwidth; 278 X += gridwidth;
258 } 279 }
259 } 280 }
281
282 public class ScrollViewerContainer : ScrollViewer, Container
283 {
284 public Layout Layout { get; set; }
285
286 public ScrollViewerContainer(Container parent) : base()
287 {
288 Layout = new Layout();
289
290 HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
291 VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
292
293 parent.Add(this, true);
294 }
295
296 public void Add(UIElement control, bool fill)
297 {
298 Content = control;
299 }
300 }
301
302 public class TabViewContainer : TabControl, Container
303 {
304 public Layout Layout { get; set; }
305
306 public TabViewContainer(Container parent) : base()
307 {
308 Layout = new Layout();
309 parent.Add(this, true);
310 }
311
312 public void Add(UIElement control, bool fill)
313 {
314 TabItem tab = new TabItem();
315 tab.Header = Layout.Label != null ? Layout.Label : "New Tab";
316 Items.Add(tab);
317 tab.Content = control;
318 Layout.Reset();
319 }
320 }
260 } 321 }

mercurial