diff -r 0cdb8089a29f -r a38aec91bd66 ui/wpf/UIcore/Container.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/wpf/UIcore/Container.cs Sat Jan 31 11:51:54 2015 +0100 @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace UI +{ + public interface Container + { + void Add(UIElement control, bool fill); + } + + public enum BoxOrientation + { + VERTICAL, + HORIZONTAL + } + + public class BoxContainer : Container + { + public Grid Grid; + public BoxOrientation Orientation; + + private int x = 0; + private int y = 0; + + private bool filled = false; + + public BoxContainer(Grid grid, BoxOrientation orientation) + { + Grid = grid; + Orientation = orientation; + if(Orientation == BoxOrientation.HORIZONTAL) + { + RowDefinition row = new RowDefinition(); + row.Height = new GridLength(1, GridUnitType.Star); + Grid.RowDefinitions.Add(row); + } + else + { + ColumnDefinition col = new ColumnDefinition(); + col.Width = new GridLength(1, GridUnitType.Star); + Grid.ColumnDefinitions.Add(col); + } + } + + public void Add(UIElement control, bool fill) + { + if(Orientation == BoxOrientation.HORIZONTAL) + { + ColumnDefinition col = new ColumnDefinition(); + if(filled && fill) + { + fill = false; + Console.WriteLine("BoxContainer can only contain one filled control"); + } + if(fill) + { + col.Width = new GridLength(1, GridUnitType.Star); + filled = true; + } + else + { + col.Width = GridLength.Auto; + } + Grid.ColumnDefinitions.Add(col); + } + else + { + RowDefinition row = new RowDefinition(); + if (filled && fill) + { + fill = false; + Console.WriteLine("BoxContainer can only contain one filled control"); + } + if(fill) + { + row.Height = new GridLength(1, GridUnitType.Star); + filled = true; + } + else + { + row.Height = GridLength.Auto; + } + Grid.RowDefinitions.Add(row); + } + + Grid.SetColumn(control, x); + Grid.SetRow(control, y); + Grid.Children.Add(control); + + if(Orientation == BoxOrientation.HORIZONTAL) + { + x++; + } + else + { + y++; + } + } + } + + public class GridContainer : Container + { + public Grid Grid; + + public GridContainer(System.Windows.Controls.Grid grid) + { + Grid = grid; + } + + public void Add(UIElement control, bool fill) + { + + } + } +}