# HG changeset patch # User Olaf Wintermann # Date 1485170254 -3600 # Node ID d781436e249088f833b548cea3690cc4e6ffd2a1 # Parent c9b8b9e0cfe8e8d1e1b7533670ffcc2722e49517 adds scrolledwindow and tabview container (WPF) diff -r c9b8b9e0cfe8 -r d781436e2490 .hgignore --- 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 diff -r c9b8b9e0cfe8 -r d781436e2490 application/main.c --- 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); diff -r c9b8b9e0cfe8 -r d781436e2490 ui/wpf/UIcore/Container.cs --- 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(); + } + } } diff -r c9b8b9e0cfe8 -r d781436e2490 ui/wpf/UIcore/Window.cs --- 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); diff -r c9b8b9e0cfe8 -r d781436e2490 ui/wpf/UIwrapper/UIwrapper/container.cpp --- 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 *parent) { - UI::BoxContainer ^vbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::VERTICAL); +UI_EXPORT void* __stdcall UIvbox(gcroot *parent, int margin, int spacing) { + UI::BoxContainer ^vbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::VERTICAL, margin, spacing); gcroot *container = new gcroot(); *container = vbox; return container; } -UI_EXPORT void* __stdcall UIhbox(gcroot *parent) { - UI::BoxContainer ^hbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::HORIZONTAL); +UI_EXPORT void* __stdcall UIhbox(gcroot *parent, int margin, int spacing) { + UI::BoxContainer ^hbox = gcnew UI::BoxContainer(*parent, UI::BoxOrientation::HORIZONTAL, margin, spacing); gcroot *container = new gcroot(); *container = hbox; return container; @@ -28,6 +28,25 @@ return container; } +UI_EXPORT void* __stdcall UIscrolledwindow(gcroot *parent) { + UI::ScrollViewerContainer ^scrollviewer = gcnew UI::ScrollViewerContainer(*parent); + gcroot *container = new gcroot(); + *container = scrollviewer; + return container; +} + +UI_EXPORT void* __stdcall UItabview(gcroot *parent) { + UI::TabViewContainer ^tabview = gcnew UI::TabViewContainer(*parent); + gcroot *container = new gcroot(); + *container = tabview; + return container; +} + +UI_EXPORT void __stdcall UItab(gcroot *container, char *label) { + UI::Container ^ct = *container; + ct->Layout->Label = gcnew String(label); +} + /* ------------------- layout functions ------------------- */ diff -r c9b8b9e0cfe8 -r d781436e2490 ui/wpf/container.c --- 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 -------------------- * diff -r c9b8b9e0cfe8 -r d781436e2490 ui/wpf/container.h --- 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);