# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1743022482 -3600
# Node ID ea1bba55de441e70bed4ff2adde3e4d5853fd575
# Parent  8884c7fbe4cbd3d3b8ba417b00ca2980d88af5d9
add button (QT)

diff -r 8884c7fbe4cb -r ea1bba55de44 application/main.c
--- a/application/main.c	Wed Mar 26 21:47:04 2025 +0100
+++ b/application/main.c	Wed Mar 26 21:54:42 2025 +0100
@@ -775,7 +775,9 @@
 
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_window("My Window", NULL);
-    
+    ui_button(obj, .label = "Button 1");
+    ui_button(obj, .label = "Button 2");
+    ui_button(obj, .label = "Button 3");
     ui_show(obj);
 }
 
diff -r 8884c7fbe4cb -r ea1bba55de44 ui/qt/button.cpp
--- a/ui/qt/button.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/button.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -30,3 +30,20 @@
 #include "container.h"
 #include "toolkit.h"
 
+UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) {
+    UiContainerPrivate *ctn = ui_obj_container(obj);
+    UI_APPLY_LAYOUT(ctn->layout, args);
+    
+    QString str = QString::fromUtf8(args.label);
+    QPushButton *button = new QPushButton(str);
+    
+    if(args.onclick) {
+        UiEventWrapper *event = new UiEventWrapper(obj, args.onclick, args.onclickdata);
+        button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
+    }
+    
+    ctn->add(button, false);
+    
+    return button;
+}
+
diff -r 8884c7fbe4cb -r ea1bba55de44 ui/qt/container.cpp
--- a/ui/qt/container.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/container.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -39,7 +39,7 @@
     delete ct;
 }
 
-static void add_container(UiObject *obj, UiContainerPrivate *ct) {
+void ui_container_add(UiObject *obj, UiContainerPrivate *ct) {
     UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX));
     container->close = 0;
     container->container = ct;
diff -r 8884c7fbe4cb -r ea1bba55de44 ui/qt/container.h
--- a/ui/qt/container.h	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/container.h	Wed Mar 26 21:54:42 2025 +0100
@@ -54,7 +54,7 @@
 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
 
-#define ui_obj_container(obj) (UiContainerPrivate*)obj->container_end
+#define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container
 
 typedef enum UiLayoutBool {
     UI_LAYOUT_UNDEFINED = 0,
@@ -106,6 +106,8 @@
     virtual void add(QWidget *widget, bool fill);
 };
 
+void ui_container_add(UiObject *obj, UiContainerPrivate *ct);
+
 
 #endif	/* CONTAINER_H */
 
diff -r 8884c7fbe4cb -r ea1bba55de44 ui/qt/window.cpp
--- a/ui/qt/window.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/window.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -60,7 +60,7 @@
     QWidget *boxWidget = new QWidget();
     boxWidget->setLayout(box);
     window->setCentralWidget(boxWidget);
-    //obj->container = new UiBoxContainer(box);
+    ui_container_add(obj, new UiBoxContainer(box));
     
     obj->widget = window;
     return obj;