# HG changeset patch # User Olaf Wintermann # Date 1422701514 -3600 # Node ID a38aec91bd66f6dd7e7293de19f665bff1b5cd70 # Parent 0cdb8089a29fbc539284b48c633560180360cb3b added box layout and button (WPF) diff -r 0cdb8089a29f -r a38aec91bd66 application/main.c --- a/application/main.c Tue Jan 27 09:59:32 2015 +0100 +++ b/application/main.c Sat Jan 31 11:51:54 2015 +0100 @@ -98,6 +98,11 @@ fflush(stdout); } +void action_button(UiEvent *event, void *data) { + printf("button clicked\n"); + fflush(stdout); +} + int main(int argc, char** argv) { ui_init("app1", argc, argv); @@ -112,6 +117,10 @@ ui_menuitem("item4", NULL, NULL); UiObject *obj = ui_window("Test", NULL); + ui_button(obj, "Test1", action_button, NULL); + ui_button(obj, "Test2", action_button, NULL); + ui_button(obj, "Test3", action_button, NULL); + ui_button(obj, "Test4", action_button, NULL); ui_show(obj); ui_main(); /* diff -r 0cdb8089a29f -r a38aec91bd66 config.mk --- a/config.mk Tue Jan 27 09:59:32 2015 +0100 +++ b/config.mk Sat Jan 31 11:51:54 2015 +0100 @@ -11,7 +11,7 @@ CFLAGS += -DUI_WPF LDFLAGS += $(BUILD_ROOT)/build/UIwrapper/UIwrapper.lib -LDFLAGS += -mwindows +#LDFLAGS += -mwindows TOOLKIT = wpf diff -r 0cdb8089a29f -r a38aec91bd66 ui/wpf/UIcore/Container.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/wpf/UIcore/Container.cs Sat Jan 31 11:51:54 2015 +0100 @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace UI +{ + public interface Container + { + void Add(UIElement control, bool fill); + } + + public enum BoxOrientation + { + VERTICAL, + HORIZONTAL + } + + public class BoxContainer : Container + { + public Grid Grid; + public BoxOrientation Orientation; + + private int x = 0; + private int y = 0; + + private bool filled = false; + + public BoxContainer(Grid grid, BoxOrientation orientation) + { + Grid = grid; + Orientation = orientation; + if(Orientation == BoxOrientation.HORIZONTAL) + { + RowDefinition row = new RowDefinition(); + row.Height = new GridLength(1, GridUnitType.Star); + Grid.RowDefinitions.Add(row); + } + else + { + ColumnDefinition col = new ColumnDefinition(); + col.Width = new GridLength(1, GridUnitType.Star); + Grid.ColumnDefinitions.Add(col); + } + } + + public void Add(UIElement control, bool fill) + { + if(Orientation == BoxOrientation.HORIZONTAL) + { + ColumnDefinition col = new ColumnDefinition(); + if(filled && fill) + { + fill = false; + Console.WriteLine("BoxContainer can only contain one filled control"); + } + if(fill) + { + col.Width = new GridLength(1, GridUnitType.Star); + filled = true; + } + else + { + col.Width = GridLength.Auto; + } + Grid.ColumnDefinitions.Add(col); + } + else + { + RowDefinition row = new RowDefinition(); + if (filled && fill) + { + fill = false; + Console.WriteLine("BoxContainer can only contain one filled control"); + } + if(fill) + { + row.Height = new GridLength(1, GridUnitType.Star); + filled = true; + } + else + { + row.Height = GridLength.Auto; + } + Grid.RowDefinitions.Add(row); + } + + Grid.SetColumn(control, x); + Grid.SetRow(control, y); + Grid.Children.Add(control); + + if(Orientation == BoxOrientation.HORIZONTAL) + { + x++; + } + else + { + y++; + } + } + } + + public class GridContainer : Container + { + public Grid Grid; + + public GridContainer(System.Windows.Controls.Grid grid) + { + Grid = grid; + } + + public void Add(UIElement control, bool fill) + { + + } + } +} diff -r 0cdb8089a29f -r a38aec91bd66 ui/wpf/UIcore/Controls.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/wpf/UIcore/Controls.cs Sat Jan 31 11:51:54 2015 +0100 @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace UI +{ + public class Controls + { + + public static Button Button(Container container, String label, RoutedEventHandler e) + { + return Application.GetInstance().Exec