# HG changeset patch # User Olaf Wintermann # Date 1453286101 -3600 # Node ID 1c943d43fa813e4f55815419c6e7550b73bc64e5 # Parent d276306d801f94b6fa4818eb93c84d92a0ae4b3b implemented grid container (WPF) diff -r d276306d801f -r 1c943d43fa81 application/main.c --- a/application/main.c Sun Jan 17 19:19:28 2016 +0100 +++ b/application/main.c Wed Jan 20 11:35:01 2016 +0100 @@ -43,7 +43,7 @@ printf("button clicked\n"); fflush(stdout); } - +/* void draw(UiEvent *event, UiGraphics *g, void *data) { int width = g->width; int height = g->height; @@ -63,6 +63,7 @@ ui_text_free(text); } +*/ void click(UiEvent *event, void *data) { UiMouseEvent *me = event->eventdata; @@ -92,22 +93,24 @@ //ui_mouse_handler(obj, w, click, NULL); ui_grid_sp(obj, 40, 4, 4); + ui_button(obj, "OK", NULL, NULL); ui_button(obj, "Google", NULL, NULL); ui_textfield(obj, NULL); ui_newline(obj); ui_button(obj, "OK", NULL, NULL); - ui_space(obj); - ui_textfield(obj, 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); ui_textarea(obj, NULL); + ui_button(obj, "BTN1", NULL, NULL); ui_end(obj); diff -r d276306d801f -r 1c943d43fa81 ui/wpf/UIcore/Container.cs --- a/ui/wpf/UIcore/Container.cs Sun Jan 17 19:19:28 2016 +0100 +++ b/ui/wpf/UIcore/Container.cs Wed Jan 20 11:35:01 2016 +0100 @@ -18,10 +18,13 @@ public class Layout { public bool? Fill { get; set; } + public bool Hexpand { get; set; } + public bool Vexpand { get; set; } + public bool NewLine { get; set; } public Layout() { - Fill = null; + Reset(); } public bool IsFill(bool fill) @@ -37,6 +40,9 @@ public void Reset() { Fill = null; + Hexpand = false; + Vexpand = false; + NewLine = false; } } @@ -146,20 +152,76 @@ } } - public class GridContainer : Container + public class GridContainer : Grid, Container { public Layout Layout { get; set; } - - public Grid Grid; + + private int X = 0; + private int Y = 0; + private int CurrentWidth = 0; + private int CurrentHeight = 0; - public GridContainer(System.Windows.Controls.Grid grid) + public GridContainer(Container parent, int margin, int colspacing, int rowspacing) : base() { - Grid = grid; + Layout = new Layout(); + + parent.Add(this, true); } public void Add(UIElement control, bool fill) { + if(Layout.NewLine) + { + X = 0; + Y++; + } + ColumnDefinition col; + RowDefinition row; + if(X >= CurrentWidth) + { + col = new ColumnDefinition(); + col.Width = GridLength.Auto; + ColumnDefinitions.Add(col); + CurrentWidth = X + 1; + } + else + { + col = ColumnDefinitions.ElementAt(X); + } + + if (Y >= CurrentHeight) + { + row = new RowDefinition(); + row.Height = GridLength.Auto; + RowDefinitions.Add(row); + CurrentHeight = Y + 1; + } + else + { + row = RowDefinitions.ElementAt(Y); + } + + if(Layout.Hexpand) + { + col.Width = new GridLength(1, GridUnitType.Star); + } + if(Layout.Vexpand) + { + row.Height = new GridLength(1, GridUnitType.Star); + } + + Grid.SetColumn(control, X); + Grid.SetRow(control, Y); + Children.Add(control); + + Layout.Reset(); + X++; + } + + public static GridContainer CreateGridContainer(Container parent, int margin, int colspacing, int rowspacing) + { + return Application.GetInstance().Exec(() => new GridContainer(parent, margin, colspacing, rowspacing)); } } } diff -r d276306d801f -r 1c943d43fa81 ui/wpf/UIcore/Controls.cs --- a/ui/wpf/UIcore/Controls.cs Sun Jan 17 19:19:28 2016 +0100 +++ b/ui/wpf/UIcore/Controls.cs Wed Jan 20 11:35:01 2016 +0100 @@ -16,6 +16,24 @@ return Application.GetInstance().Exec