add scrolledwindow (WinUI3) newapi

Mon, 02 Oct 2023 09:22:52 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 02 Oct 2023 09:22:52 +0200
branch
newapi
changeset 194
e2281ace0769
parent 193
74c688cc1839
child 195
0f2e69873875

add scrolledwindow (WinUI3)

make/vs/testapp/main.c file | annotate | diff | comparison | revisions
ui/ui/container.h file | annotate | diff | comparison | revisions
ui/winui/container.cpp file | annotate | diff | comparison | revisions
--- a/make/vs/testapp/main.c	Sun Oct 01 22:34:48 2023 +0200
+++ b/make/vs/testapp/main.c	Mon Oct 02 09:22:52 2023 +0200
@@ -77,41 +77,43 @@
     wdata->text = ui_string_new(obj->ctx, "text");
     wdata->password = ui_string_new(obj->ctx, "password");
 
-    ui_grid(obj, .margin=10, .columnspacing=5, .rowspacing=20) {
-        ui_button(obj, .label="Button1", .onclick=action1, .onclickdata="action1");
-        ui_button(obj, .label="Button2", .onclick=action1, .onclickdata="action2");
-        ui_button(obj, .label="Button3", .onclick=action1, .onclickdata="action3", .hexpand=true);
-        ui_newline(obj);
+    ui_scrolledwindow0(obj) {
+        ui_grid(obj, .margin = 10, .columnspacing = 5, .rowspacing = 20) {
+            ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
+            ui_button(obj, .label = "Button2", .onclick = action1, .onclickdata = "action2");
+            ui_button(obj, .label = "Button3", .onclick = action1, .onclickdata = "action3", .hexpand = true);
+            ui_newline(obj);
 
-        ui_button(obj, .label="Button4", .onclick=action1, .onclickdata="action4");
-        ui_button(obj, .label="Button5", .onclick=action1, .onclickdata="action5", .colspan=2);
-        ui_newline(obj);
+            ui_button(obj, .label = "Button4", .onclick = action1, .onclickdata = "action4");
+            ui_button(obj, .label = "Button5", .onclick = action1, .onclickdata = "action5", .colspan = 2);
+            ui_newline(obj);
 
-        ui_button(obj, .label="Very Long Button Label Text ____________ Test", .onclick=action_set_checkbox);
-        ui_newline(obj);
+            ui_button(obj, .label = "Very Long Button Label Text ____________ Test", .onclick = action_set_checkbox);
+            ui_newline(obj);
 
-        ui_checkbox(obj, .label = "Option 1", .value = wdata->check, .onchange=action_onchange);
-        ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle);
-        ui_newline(obj);
+            ui_checkbox(obj, .label = "Option 1", .value = wdata->check, .onchange = action_onchange);
+            ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle);
+            ui_newline(obj);
 
-        ui_hbox(obj, .colspan=3) {
-            ui_radiobutton(obj, .label = "Radio 1", .value = wdata->radio);
-            ui_radiobutton(obj, .label = "Radio 2", .value = wdata->radio);
-            ui_radiobutton(obj, .label = "Radio 3", .value = wdata->radio);
+            ui_hbox(obj, .colspan = 3) {
+                ui_radiobutton(obj, .label = "Radio 1", .value = wdata->radio);
+                ui_radiobutton(obj, .label = "Radio 2", .value = wdata->radio);
+                ui_radiobutton(obj, .label = "Radio 3", .value = wdata->radio);
+            }
+            ui_newline(obj);
+            ui_radiobutton(obj, .label = "Radio 4", .value = wdata->radio);
+            ui_switch(obj, .label = "test", .onchange = action_switch);
+            ui_newline(obj);
+
+            ui_textfield(obj, .value = wdata->text);
+            ui_passwordfield(obj, .value = wdata->password);
+            ui_newline(obj);
+
+            ui_frame(obj, .label = "Test", .colspan = 3, .vexpand = true) {
+                ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
+            }
         }
-        ui_newline(obj);
-        ui_radiobutton(obj, .label = "Radio 4", .value = wdata->radio);
-        ui_switch(obj, .label = "test", .onchange=action_switch);
-        ui_newline(obj);
-
-        ui_textfield(obj, .value = wdata->text);
-        ui_passwordfield(obj, .value = wdata->password);
-        ui_newline(obj);
-
-        ui_frame(obj, .label = "Test", .colspan = 3, .vexpand = true) {
-            ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
-        }
-    }
+    }   
 
     ui_show(obj);
 }
--- a/ui/ui/container.h	Sun Oct 01 22:34:48 2023 +0200
+++ b/ui/ui/container.h	Mon Oct 02 09:22:52 2023 +0200
@@ -64,22 +64,24 @@
 #define ui_hbox(obj, ...) for(ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
 #define ui_grid(obj, ...) for(ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
 #define ui_frame(obj, ...) for(ui_frame_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
-   
+#define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+
+#define ui_vbox0(obj) for(ui_vbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_hbox0(obj) for(ui_hbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_grid0(obj) for(ui_grid_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_frame0(obj) for(ui_frame_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
 
 void ui_end(UiObject *obj);
     
 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args);
 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args);
-
 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args);
-
 UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args);
+UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args);
 
 
-
-
-
-UIWIDGET ui_scrolledwindow(UiObject *obj);
+UIWIDGET ui_scrolledwindow_deprecated(UiObject *obj);
 
 UIWIDGET ui_sidebar(UiObject *obj);
 
--- a/ui/winui/container.cpp	Sun Oct 01 22:34:48 2023 +0200
+++ b/ui/winui/container.cpp	Mon Oct 02 09:22:52 2023 +0200
@@ -238,7 +238,7 @@
 	ui_reset_layout(layout);
 }
 
-// --------------------- UiFrameContainer ---------------------
+// --------------------- UI Frame ---------------------
 
 UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args) {
 	// create a grid for the frame, that contains the label and a sub-frame
@@ -309,6 +309,30 @@
 	return widget;
 }
 
+// --------------------- UI ScrolledWindow ---------------------
+
+UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args) {
+	ScrollViewer scrollW = ScrollViewer();
+
+	// add frame to the parent container
+	UiObject* current = uic_current_obj(obj);
+	UI_APPLY_LAYOUT1(current, args);
+	current->container->Add(scrollW, true);
+
+	UIElement elm = scrollW;
+	UiWidget* widget = new UiWidget(elm);
+
+	// create a vbox as child container
+	Grid vbox = Grid();
+	scrollW.Content(vbox);
+
+	UiObject* newobj = uic_object_new(obj, widget);
+	newobj->container = new UiBoxContainer(vbox, UI_CONTAINER_VBOX, args.margin, args.spacing);
+	uic_obj_add(obj, newobj);
+
+	return widget;
+}
+
 
 /*
  * -------------------- Layout Functions --------------------

mercurial