adds scrolledwindow and tabview container (WPF)

Mon, 23 Jan 2017 12:17:34 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 23 Jan 2017 12:17:34 +0100
changeset 138
d781436e2490
parent 137
c9b8b9e0cfe8
child 139
dbde25a5bc53

adds scrolledwindow and tabview container (WPF)

.hgignore file | annotate | diff | comparison | revisions
application/main.c file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Container.cs file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Window.cs file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/container.cpp file | annotate | diff | comparison | revisions
ui/wpf/container.c file | annotate | diff | comparison | revisions
ui/wpf/container.h file | annotate | diff | comparison | revisions
--- a/.hgignore	Mon Jan 23 10:50:22 2017 +0100
+++ b/.hgignore	Mon Jan 23 12:17:34 2017 +0100
@@ -4,7 +4,7 @@
 relre:^ui/wpf/UIcore/obj
 relre:^ui/wpf/UIwrapper/.vs
 relre:^ui/wpf/UIwrapper/UIwrapper.VC
-relre:^ui/wpf/UIwrapper/UIWrapper/Debug
-relre:^ui/wpf/UIwrapper/UIWrapper/Release
-relre:^ui/wpf/UIwrapper/UIWrapper/x64
+relre:^ui/wpf/UIwrapper/UIwrapper/Debug
+relre:^ui/wpf/UIwrapper/UIwrapper/Release
+relre:^ui/wpf/UIwrapper/UIwrapper/x64
 relre:^ui/wpf/UIwrapper/ipch
\ No newline at end of file
--- a/application/main.c	Mon Jan 23 10:50:22 2017 +0100
+++ b/application/main.c	Mon Jan 23 12:17:34 2017 +0100
@@ -65,22 +65,13 @@
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_window("Test", NULL);
     
-    ui_grid_sp(obj, 10, 10, 10);
-    
-    ui_label(obj, "Test2");
-    ui_layout_hexpand(obj, TRUE);
-    ui_button(obj, "OK", NULL, NULL);
-    ui_button(obj, "------------------------", NULL, NULL);
-    ui_newline(obj);
+    ui_tabview(obj);
     
-    ui_label(obj, "Test2");
-    ui_layout_hexpand(obj, TRUE);
-    ui_layout_vexpand(obj, TRUE);
-    ui_layout_gridwidth(obj, 2);
+    ui_tab(obj, "Tab 1");
+    ui_textarea(obj, NULL);
     
-    ui_drawingarea(obj, draw, NULL);
-    
-    ui_newline(obj);
+    ui_tab(obj, "Tab 2");
+    ui_textarea(obj, NULL);
     
     ui_end(obj);
     
--- 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();
+        }
+    }
 }
--- a/ui/wpf/UIcore/Window.cs	Mon Jan 23 10:50:22 2017 +0100
+++ b/ui/wpf/UIcore/Window.cs	Mon Jan 23 12:17:34 2017 +0100
@@ -80,7 +80,7 @@
             RowDefinition contentRow = new RowDefinition();
             contentRow.Height = new GridLength(1, GridUnitType.Star);
             windowGrid.RowDefinitions.Add(contentRow);
-            BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL);
+            BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL, 0, 0);
             Grid.SetColumn(vbox, 0);
             Grid.SetRow(vbox, rowIndex);
             windowGrid.Children.Add(vbox);
--- a/ui/wpf/UIwrapper/UIwrapper/container.cpp	Mon Jan 23 10:50:22 2017 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/container.cpp	Mon Jan 23 12:17:34 2017 +0100
@@ -7,15 +7,15 @@
 
 #using "UIcore.dll"
 
-UI_EXPORT void* __stdcall UIvbox(gcroot<UI::Container^> *parent) {
-	UI::BoxContainer ^vbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::VERTICAL);
+UI_EXPORT void* __stdcall UIvbox(gcroot<UI::Container^> *parent, int margin, int spacing) {
+	UI::BoxContainer ^vbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::VERTICAL, margin, spacing);
 	gcroot<UI::BoxContainer^> *container = new gcroot<UI::BoxContainer^>();
 	*container = vbox;
 	return container;
 }
 
-UI_EXPORT void* __stdcall UIhbox(gcroot<UI::Container^> *parent) {
-	UI::BoxContainer ^hbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::HORIZONTAL);
+UI_EXPORT void* __stdcall UIhbox(gcroot<UI::Container^> *parent, int margin, int spacing) {
+	UI::BoxContainer ^hbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::HORIZONTAL, margin, spacing);
 	gcroot<UI::BoxContainer^> *container = new gcroot<UI::BoxContainer^>();
 	*container = hbox;
 	return container;
@@ -28,6 +28,25 @@
 	return container;
 }
 
+UI_EXPORT void* __stdcall UIscrolledwindow(gcroot<UI::Container^> *parent) {
+	UI::ScrollViewerContainer ^scrollviewer = gcnew UI::ScrollViewerContainer(*parent);
+	gcroot<UI::ScrollViewerContainer^> *container = new gcroot<UI::ScrollViewerContainer^>();
+	*container = scrollviewer;
+	return container;
+}
+
+UI_EXPORT void* __stdcall UItabview(gcroot<UI::Container^> *parent) {
+	UI::TabViewContainer ^tabview = gcnew UI::TabViewContainer(*parent);
+	gcroot<UI::TabViewContainer^> *container = new gcroot<UI::TabViewContainer^>();
+	*container = tabview;
+	return container;
+}
+
+UI_EXPORT void __stdcall UItab(gcroot<UI::Container^> *container, char *label) {
+	UI::Container ^ct = *container;
+	ct->Layout->Label = gcnew String(label);
+}
+
 
 
 /* ------------------- layout functions ------------------- */
--- a/ui/wpf/container.c	Mon Jan 23 10:50:22 2017 +0100
+++ b/ui/wpf/container.c	Mon Jan 23 12:17:34 2017 +0100
@@ -33,9 +33,17 @@
 #include "../common/object.h"
 
 UIWIDGET ui_vbox(UiObject *obj) {
+    return ui_vbox_sp(obj, 0, 0);
+}
+
+UIWIDGET ui_hbox(UiObject *obj) {
+    return ui_hbox_sp(obj, 0, 0);
+}
+
+UIWIDGET ui_vbox_sp(UiObject *obj, int margin, int spacing) {
     UiContainer *ct = uic_get_current_container(obj);
     
-    UIWIDGET vbox = UIvbox(ct);
+    UIWIDGET vbox = UIvbox(ct, margin, spacing);
     
     UiObject *newobj = uic_object_new(obj, vbox);
     newobj->container = (UiContainer*)vbox;
@@ -44,10 +52,10 @@
     return vbox;
 }
 
-UIWIDGET ui_hbox(UiObject *obj) {
+UIWIDGET ui_hbox_sp(UiObject *obj, int margin, int spacing) {
     UiContainer *ct = uic_get_current_container(obj);
     
-    UIWIDGET hbox = UIhbox(ct);
+    UIWIDGET hbox = UIhbox(ct, margin, spacing);
     
     UiObject *newobj = uic_object_new(obj, hbox);
     newobj->container = (UiContainer*)hbox;
@@ -72,6 +80,40 @@
     return grid;
 }
 
+UIWIDGET ui_scrolledwindow(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    UIWIDGET scrolledwindow = UIscrolledwindow(ct);
+    
+    UiObject *newobj = uic_object_new(obj, scrolledwindow);
+    newobj->container = (UiContainer*)scrolledwindow;
+    uic_obj_add(obj, newobj);
+    
+    return scrolledwindow;
+}
+
+/*
+ * TODO: sidebar
+ */
+
+UIWIDGET ui_tabview(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    UIWIDGET tabview = UItabview(ct);
+    
+    UiObject *newobj = uic_object_new(obj, tabview);
+    newobj->container = (UiContainer*)tabview;
+    uic_obj_add(obj, newobj);
+    
+    return tabview;
+}
+
+void ui_tab(UiObject *obj, char *title) {
+    UiContainer *ct = uic_get_current_container(obj);
+    UItab(ct, title);
+}
+
+
 /*
  * -------------------- Layout Functions --------------------
  * 
--- a/ui/wpf/container.h	Mon Jan 23 10:50:22 2017 +0100
+++ b/ui/wpf/container.h	Mon Jan 23 12:17:34 2017 +0100
@@ -35,10 +35,14 @@
 extern "C" {
 #endif
 
-UI_IMPORT void* __stdcall UIvbox(UiContainer *parent);
-UI_IMPORT void* __stdcall UIhbox(UiContainer *parent);
+UI_IMPORT void* __stdcall UIvbox(UiContainer *parent, int margin, int spacing);
+UI_IMPORT void* __stdcall UIhbox(UiContainer *parent, int margin, int spacing);
 UI_IMPORT void* __stdcall UIgrid(UiContainer *parent, int margin, int columnspacing, int rowspacing);
 
+UI_IMPORT void* __stdcall UIscrolledwindow(UiContainer *parent);
+
+UI_IMPORT void* __stdcall UItabview(UiContainer *parent);
+UI_IMPORT void  __stdcall UItab(UiContainer *container, char *label);
 
 UI_IMPORT void __stdcall UIlayout_fill(UiContainer *container, int fill);
 UI_IMPORT void __stdcall UIlayout_hexpand(UiContainer *container, int expand);

mercurial