# HG changeset patch # User Olaf Wintermann # Date 1736000211 -3600 # Node ID c7dcd2ab2d3da36f6e3396e29a08fe278ea68114 # Parent 7ead63398a5057e8297a756ca836b404a3d711ca implement label (Motif) diff -r 7ead63398a50 -r c7dcd2ab2d3d ui/motif/label.c --- 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); +} diff -r 7ead63398a50 -r c7dcd2ab2d3d ui/motif/label.h --- 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 diff -r 7ead63398a50 -r c7dcd2ab2d3d ui/ui/display.h --- 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;