ui/win32/button.c

changeset 827
eae5b817aa47
parent 825
1bac7e45712b
child 841
651cf2c59dd9
--- a/ui/win32/button.c	Fri Oct 10 09:05:11 2025 +0200
+++ b/ui/win32/button.c	Fri Oct 10 09:06:06 2025 +0200
@@ -27,7 +27,67 @@
  */
 
 #include "button.h"
+#include "widget.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static W32WidgetClass button_widget_class = {
+    .eventproc = ui_button_eventproc,
+    .enable = w32_widget_default_enable,
+    .show = w32_widget_default_show,
+    .get_preferred_size = ui_button_get_preferred_size,
+    .destroy  = w32_widget_default_destroy
+};
 
 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) {
-    return NULL;
+    HINSTANCE hInstance = GetModuleHandle(NULL);
+    UiContainerPrivate *container = ui_obj_container(obj);
+    HWND parent = ui_container_get_parent(container);
+    UiLayout layout = UI_ARGS2LAYOUT(args);
+
+    HWND hwnd = CreateWindow(
+            "BUTTON",
+            args->label,
+            WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
+            0, 0, 100, 30,
+            parent,
+            (HMENU)0,
+            hInstance,
+            NULL);
+    ui_win32_set_ui_font(hwnd);
+
+    W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiWidget));
+    ui_container_add(container, widget, &layout);
+
+    UiWidget *btn = (UiWidget*)widget;
+    btn->obj = obj;
+    btn->callback = args->onclick;
+    btn->callbackdata = args->onclickdata;
+
+    return widget;
 }
+
+W32Size ui_button_get_preferred_size(W32Widget *widget) {
+    W32Size size;
+    size.width = 100;
+    size.height = 30;
+    return size;
+}
+
+void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+    UiWidget *w = (UiWidget*)widget;
+
+    UiEvent e;
+    e.obj = w->obj;
+    e.document = e.obj->ctx->document;
+    e.window = e.obj->window;
+    e.eventdata = NULL;
+    e.eventdatatype = 0;
+    e.intval = 0;
+    e.set = ui_get_setop();
+
+    if (w->callback) {
+        w->callback(&e, w->callbackdata);
+    }
+}

mercurial