added grid spacing (WPF)

Thu, 21 Jan 2016 20:40:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 21 Jan 2016 20:40:14 +0100
changeset 104
3efe0210e27e
parent 103
6a6718269c22
child 105
86d729874ff4

added grid spacing (WPF)

application/main.c file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Container.cs file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Controls.cs file | annotate | diff | comparison | revisions
ui/wpf/UIcore/TextArea.cs file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/controls.cpp file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Jan 20 17:37:52 2016 +0100
+++ b/application/main.c	Thu Jan 21 20:40:14 2016 +0100
@@ -45,7 +45,7 @@
 }
 
 void draw(UiEvent *event, UiGraphics *g, void *data) {
-
+    /*
     int width = g->width;
     int height = g->height;
     printf("rec[%d,%d]\n", width, height);
@@ -64,6 +64,7 @@
     ui_draw_text(g, 50, 50, text);
     
     ui_text_free(text);
+    */
 }
 
 void click(UiEvent *event, void *data) {
@@ -90,24 +91,21 @@
     ui_toolbar_add_default("button2");
     
     UiObject *obj = ui_window("Test", NULL);
-    UIWIDGET w = ui_drawingarea(obj, draw, NULL);
+    //UIWIDGET w = ui_drawingarea(obj, draw, NULL);
     //ui_mouse_handler(obj, w, click, NULL);
     
-/*
+///*
     ui_grid_sp(obj, 8, 4, 4);
     
     ui_button(obj, "OK", NULL, NULL);
+    ui_layout_hexpand(obj, TRUE);
     ui_button(obj, "Google", NULL, NULL);
     ui_textfield(obj, NULL);
     ui_newline(obj);
     
-    ui_button(obj, "OK", NULL, NULL);
-    ui_newline(obj);
-    
     ui_vbox(obj);
     ui_button(obj, "txt", NULL, NULL);
     ui_textfield(obj, NULL);
-    ui_space(obj);
     ui_end(obj);
     ui_layout_hexpand(obj, TRUE);
     ui_layout_vexpand(obj, TRUE);
@@ -115,7 +113,7 @@
     ui_button(obj, "BTN1", NULL, NULL);
     
     ui_end(obj);
-*/
+//*/
     
     ui_show(obj);
     ui_main();
--- a/ui/wpf/UIcore/Container.cs	Wed Jan 20 17:37:52 2016 +0100
+++ b/ui/wpf/UIcore/Container.cs	Thu Jan 21 20:40:14 2016 +0100
@@ -161,10 +161,17 @@
         private int CurrentWidth = 0;
         private int CurrentHeight = 0;
 
+        private int ColSpacing;
+        private int RowSpacing;
+
         public GridContainer(Container parent, int margin, int colspacing, int rowspacing) : base()
         {
             Layout = new Layout();
 
+            Margin = new Thickness(margin);
+            ColSpacing = colspacing;
+            RowSpacing = rowspacing;
+
             parent.Add(this, true);
         }
 
@@ -178,20 +185,47 @@
 
             ColumnDefinition col;
             RowDefinition row;
+            bool getcol = false;
             if(X >= CurrentWidth)
             {
+                if (ColSpacing > 0 && X != 0)
+                {
+                    ColumnDefinition spaceCol = new ColumnDefinition();
+                    spaceCol.Width = new GridLength(ColSpacing, GridUnitType.Pixel);
+                    ColumnDefinitions.Add(spaceCol);
+                    X++;
+                }
+
                 col = new ColumnDefinition();
                 col.Width = GridLength.Auto;
                 ColumnDefinitions.Add(col);
+
                 CurrentWidth = X + 1;
             }
             else
             {
+                if (ColSpacing > 0 && X % 2 > 0)
+                {
+                    X++;
+                }
+                col = ColumnDefinitions.ElementAt(X);
+            }
+
+            if(getcol)
+            {
                 col = ColumnDefinitions.ElementAt(X);
             }
 
             if (Y >= CurrentHeight)
             {
+                if (RowSpacing > 0 && Y != 0)
+                {
+                    RowDefinition spaceRow = new RowDefinition();
+                    spaceRow.Height = new GridLength(RowSpacing, GridUnitType.Pixel);
+                    RowDefinitions.Add(spaceRow);
+                    Y++;
+                }
+
                 row = new RowDefinition();
                 row.Height = GridLength.Auto;
                 RowDefinitions.Add(row);
--- a/ui/wpf/UIcore/Controls.cs	Wed Jan 20 17:37:52 2016 +0100
+++ b/ui/wpf/UIcore/Controls.cs	Thu Jan 21 20:40:14 2016 +0100
@@ -34,6 +34,11 @@
             return Application.GetInstance().Exec<Label>(() => Controls.CreateLabel(container, null, HorizontalAlignment.Center));
         }
 
+        public static Separator Separator(Container container)
+        {
+            return Application.GetInstance().Exec<Separator>(() => Controls.CreateSeparator(container));
+        }
+
         public static Button CreateButton(Container container, String label, RoutedEventHandler e)
         {
             Button button = new Button();
@@ -54,5 +59,12 @@
 
             return label;
         }
+
+        public static Separator CreateSeparator(Container container)
+        {
+            Separator separator = new Separator();
+            container.Add(separator, false);
+            return separator;
+        }
     }
 }
--- a/ui/wpf/UIcore/TextArea.cs	Wed Jan 20 17:37:52 2016 +0100
+++ b/ui/wpf/UIcore/TextArea.cs	Thu Jan 21 20:40:14 2016 +0100
@@ -19,6 +19,11 @@
                 HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto;
                 fill = true;
             }
+            else
+            {
+                HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto;
+                MinWidth = 15;
+            }
 
             if (text != null)
             {
--- a/ui/wpf/UIwrapper/UIwrapper/controls.cpp	Wed Jan 20 17:37:52 2016 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/controls.cpp	Thu Jan 21 20:40:14 2016 +0100
@@ -30,13 +30,14 @@
 
 UI_EXPORT void* __stdcall UIspace(gcroot<UI::Container^> *container) {
 	gcroot<Label^> *control = new gcroot<Label^>();
-
 	*control = UI::Controls::Space(*container);
 	return control;
 }
 
 UI_EXPORT void* __stdcall UIseparator(gcroot<UI::Container^> *container) {
-	return NULL;
+	gcroot<Separator^> *control = new gcroot<Separator^>();
+	*control = UI::Controls::Separator(*container);
+	return control;
 }
 
 

mercurial