implement label (Motif) newapi

Sat, 04 Jan 2025 15:16:51 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 04 Jan 2025 15:16:51 +0100
branch
newapi
changeset 428
c7dcd2ab2d3d
parent 427
7ead63398a50
child 429
0921f8a5d535

implement label (Motif)

ui/motif/label.c file | annotate | diff | comparison | revisions
ui/motif/label.h file | annotate | diff | comparison | revisions
ui/ui/display.h file | annotate | diff | comparison | revisions
--- a/ui/motif/label.c	Wed Jan 01 11:39:42 2025 +0100
+++ b/ui/motif/label.c	Sat Jan 04 15:16:51 2025 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2014 Olaf Wintermann. All rights reserved.
+ * Copyright 2024 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -34,3 +34,39 @@
 #include "../common/context.h"
 #include "../common/object.h"
 
+static UIWIDGET label_create(UiObject *obj, UiLabelArgs args, int align) {
+    Arg xargs[16];
+    int n = 0;
+    
+    UiContainerPrivate *ctn = ui_obj_container(obj);
+    UI_APPLY_LAYOUT(ctn->layout, args);
+    
+    Widget parent = ctn->prepare(ctn, xargs, &n);
+    
+    XtSetArg(xargs[n], XmNalignment, align); n++;
+    XmString label = NULL;
+    if(args.label) {
+        label = XmStringCreateLocalized((char*)args.label);
+        XtSetArg(xargs[n], XmNlabelString, label); n++;
+    }
+    
+    char *name = args.name ? (char*)args.name : "label";
+    Widget w = XmCreateLabel(parent, name, xargs, n);
+    XtManageChild(w);
+    ctn->add(ctn, w);
+    
+    XmStringFree(label);
+    return w;
+} 
+
+UIWIDGET ui_label_create(UiObject* obj, UiLabelArgs args) {
+    return label_create(obj, args, XmALIGNMENT_CENTER);
+}
+
+UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) {
+    return label_create(obj, args, XmALIGNMENT_BEGINNING);
+}
+
+UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) {
+    return label_create(obj, args, XmALIGNMENT_END);
+}
--- a/ui/motif/label.h	Wed Jan 01 11:39:42 2025 +0100
+++ b/ui/motif/label.h	Sat Jan 04 15:16:51 2025 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2014 Olaf Wintermann. All rights reserved.
+ * Copyright 2024 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -29,6 +29,8 @@
 #ifndef LABEL_H
 #define	LABEL_H
 
+#include "../ui/display.h"
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
--- a/ui/ui/display.h	Wed Jan 01 11:39:42 2025 +0100
+++ b/ui/ui/display.h	Sat Jan 04 15:16:51 2025 +0100
@@ -65,6 +65,8 @@
     UiBool vfill;
     int colspan;
     int rowspan;
+    const char *name;
+    const char *style_class;
 
     const char* label;
     UiAlignment align;

mercurial