ui/wpf/UIcore/Container.cs

changeset 138
d781436e2490
parent 136
1df2fb3d079c
--- a/ui/wpf/UIcore/Container.cs	Mon Jan 23 10:50:22 2017 +0100
+++ b/ui/wpf/UIcore/Container.cs	Mon Jan 23 12:17:34 2017 +0100
@@ -22,6 +22,7 @@
         public bool Vexpand { get; set; }
         public bool NewLine { get; set; }
         public int GridWidth { get; set; }
+        public String Label { get; set; }
 
         public Layout()
         {
@@ -45,6 +46,7 @@
             Vexpand = false;
             NewLine = false;
             GridWidth = 1;
+            Label = null;
         }
     }
 
@@ -59,15 +61,18 @@
         public Layout Layout { get; set; }
         
         private BoxOrientation Orientation;
+        private int Spacing;
 
         private int x = 0;
         private int y = 0;
 
         private bool filled = false;
 
-        public BoxContainer(BoxOrientation orientation) : base()
+        public BoxContainer(BoxOrientation orientation, int margin, int spacing) : base()
         {
             Layout = new Layout();
+            Margin = new Thickness(margin);
+            Spacing = spacing;
             
             Orientation = orientation;
             if(Orientation == BoxOrientation.HORIZONTAL)
@@ -84,7 +89,7 @@
             }
         }
 
-        public BoxContainer(Container parent, BoxOrientation orientation) : this(orientation)
+        public BoxContainer(Container parent, BoxOrientation orientation, int margin, int spacing) : this(orientation, margin, spacing)
         {
             parent.Add(this, true);
         }
@@ -95,6 +100,14 @@
             
             if(Orientation == BoxOrientation.HORIZONTAL)
             {
+                if(Spacing > 0)
+                {
+                    ColumnDefinition spaceCol = new ColumnDefinition();
+                    spaceCol.Width = new GridLength(Spacing, GridUnitType.Pixel);
+                    ColumnDefinitions.Add(spaceCol);
+                    x++;
+                }
+
                 ColumnDefinition col = new ColumnDefinition();
                 if(filled && fill)
                 {
@@ -114,6 +127,14 @@
             }
             else
             {
+                if (Spacing > 0)
+                {
+                    RowDefinition spaceRow = new RowDefinition();
+                    spaceRow.Height = new GridLength(Spacing, GridUnitType.Pixel);
+                    RowDefinitions.Add(spaceRow);
+                    y++;
+                }
+
                 RowDefinition row = new RowDefinition();
                 if (filled && fill)
                 {
@@ -257,4 +278,44 @@
             X += gridwidth;
         }
     }
+
+    public class ScrollViewerContainer : ScrollViewer, Container
+    {
+        public Layout Layout { get; set; }
+
+        public ScrollViewerContainer(Container parent) : base()
+        {
+            Layout = new Layout();
+
+            HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
+            VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
+
+            parent.Add(this, true);
+        }
+
+        public void Add(UIElement control, bool fill)
+        {
+            Content = control;
+        }
+    }
+
+    public class TabViewContainer : TabControl, Container
+    {
+        public Layout Layout { get; set; }
+
+        public TabViewContainer(Container parent) : base()
+        {
+            Layout = new Layout();
+            parent.Add(this, true);
+        }
+
+        public void Add(UIElement control, bool fill)
+        {
+            TabItem tab = new TabItem();
+            tab.Header = Layout.Label != null ? Layout.Label : "New Tab";
+            Items.Add(tab);
+            tab.Content = control;
+            Layout.Reset();
+        }
+    }
 }

mercurial