# HG changeset patch # User Olaf Wintermann # Date 1756033824 -7200 # Node ID 6963d97a38d3bb8217129d7b246725f5b48f01b2 # Parent 06eec75a6fd52c442294cee538eaa7abe899e335 add label (Cocoa) diff -r 06eec75a6fd5 -r 6963d97a38d3 make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj --- a/make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj Sun Aug 24 12:37:33 2025 +0200 +++ b/make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj Sun Aug 24 13:10:24 2025 +0200 @@ -44,6 +44,7 @@ ED6581462CFF3BCE00F5402F /* GridLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = ED6581402CFF3BCE00F5402F /* GridLayout.m */; }; ED65815C2CFF3EE900F5402F /* MainWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = ED65815B2CFF3EE900F5402F /* MainWindow.m */; }; ED65815F2CFF4BF200F5402F /* WindowManager.m in Sources */ = {isa = PBXBuildFile; fileRef = ED65815E2CFF4BF200F5402F /* WindowManager.m */; }; + ED679B0A2E5B266C001D4F71 /* label.m in Sources */ = {isa = PBXBuildFile; fileRef = ED679B092E5B266C001D4F71 /* label.m */; }; ED8687E52D999CF3002F3EC2 /* menu.m in Sources */ = {isa = PBXBuildFile; fileRef = ED8687E42D999CF3002F3EC2 /* menu.m */; }; EDB452C32E302C65006FB12D /* image.m in Sources */ = {isa = PBXBuildFile; fileRef = EDB452C22E302C65006FB12D /* image.m */; }; EDCD22272E59EEF5000612AF /* list.m in Sources */ = {isa = PBXBuildFile; fileRef = EDCD22262E59EEF5000612AF /* list.m */; }; @@ -148,6 +149,8 @@ ED65815B2CFF3EE900F5402F /* MainWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MainWindow.m; path = /Users/olaf/Projekte/toolkit/ui/cocoa/MainWindow.m; sourceTree = ""; }; ED65815D2CFF4BF200F5402F /* WindowManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WindowManager.h; path = /Users/olaf/Projekte/toolkit/ui/cocoa/WindowManager.h; sourceTree = ""; }; ED65815E2CFF4BF200F5402F /* WindowManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = WindowManager.m; path = /Users/olaf/Projekte/toolkit/ui/cocoa/WindowManager.m; sourceTree = ""; }; + ED679B082E5B266C001D4F71 /* label.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = label.h; path = /Users/olaf/Projekte/toolkit/ui/cocoa/label.h; sourceTree = ""; }; + ED679B092E5B266C001D4F71 /* label.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = label.m; path = /Users/olaf/Projekte/toolkit/ui/cocoa/label.m; sourceTree = ""; }; ED8687E32D999CF3002F3EC2 /* menu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = menu.h; path = ../../../ui/cocoa/menu.h; sourceTree = SOURCE_ROOT; }; ED8687E42D999CF3002F3EC2 /* menu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = menu.m; path = ../../../ui/cocoa/menu.m; sourceTree = SOURCE_ROOT; }; EDB452C12E302C65006FB12D /* image.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = image.h; path = /Users/olaf/Projekte/toolkit/ui/cocoa/image.h; sourceTree = ""; }; @@ -278,6 +281,8 @@ ED65812E2CFF1A7200F5402F /* cocoa */ = { isa = PBXGroup; children = ( + ED679B082E5B266C001D4F71 /* label.h */, + ED679B092E5B266C001D4F71 /* label.m */, EDCD22362E5A160A000612AF /* ListDelegate.h */, EDCD22372E5A160A000612AF /* ListDelegate.m */, EDCD22332E59F3B1000612AF /* ListDataSource.h */, @@ -415,6 +420,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ED679B0A2E5B266C001D4F71 /* label.m in Sources */, ED6580EE2CFF19F900F5402F /* context.c in Sources */, ED6580EF2CFF19F900F5402F /* menu.c in Sources */, EDCD22352E59F3B1000612AF /* ListDataSource.m in Sources */, diff -r 06eec75a6fd5 -r 6963d97a38d3 make/xcode/toolkit/toolkit/main.m --- a/make/xcode/toolkit/toolkit/main.m Sun Aug 24 12:37:33 2025 +0200 +++ b/make/xcode/toolkit/toolkit/main.m Sun Aug 24 13:10:24 2025 +0200 @@ -109,6 +109,9 @@ ui_vbox(obj, .spacing = 0, .fill = UI_OFF) { ui_combobox(obj, .varname = "list2"); + ui_llabel(obj, .label = "Left Label"); + ui_rlabel(obj, .label = "Right Label"); + ui_textfield(obj, .varname = "textfield1"); ui_radiobutton(obj, .label = "V Button 1", .varname = "radio1"); ui_radiobutton(obj, .label = "V Button 2", .varname = "radio1"); diff -r 06eec75a6fd5 -r 6963d97a38d3 ui/cocoa/label.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/cocoa/label.h Sun Aug 24 13:10:24 2025 +0200 @@ -0,0 +1,33 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "toolkit.h" +#import "../ui/display.h" + +char* ui_label_get(UiString *s); +void ui_label_set(UiString *s, const char *str); diff -r 06eec75a6fd5 -r 6963d97a38d3 ui/cocoa/label.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/cocoa/label.m Sun Aug 24 13:10:24 2025 +0200 @@ -0,0 +1,104 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "label.h" +#import "container.h" + +#import + +static UIWIDGET create_label(UiObject *obj, UiLabelArgs *args) { + NSTextField *label = [[NSTextField alloc] init]; + label.editable = NO; + label.bezeled = NO; + label.drawsBackground = NO; + label.selectable = NO; + + NSTextAlignment alignment; + switch(args->align) { + case UI_ALIGN_LEFT: alignment = NSTextAlignmentLeft; break; + case UI_ALIGN_RIGHT: alignment = NSTextAlignmentRight; break; + default: alignment = NSTextAlignmentCenter; + } + label.alignment = alignment; + + if(args->label) { + NSString *str = [[NSString alloc] initWithUTF8String:args->label]; + label.stringValue = str; + } + + UiLayout layout = UI_INIT_LAYOUT(args); + ui_container_add(obj, label, &layout); + + UiVar *var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); + if(var) { + UiString *s = var->value; + s->obj = (__bridge void*)label; + s->get = ui_label_get; + s->set = ui_label_set; + + if(s->value.ptr) { + label.stringValue = [[NSString alloc]initWithUTF8String:s->value.ptr]; + } + } + + return (__bridge void*)label; +} + + +UIWIDGET ui_label_create(UiObject* obj, UiLabelArgs *args) { + return create_label(obj, args); +} + +UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs *args) { + args->align = UI_ALIGN_LEFT; + return create_label(obj, args); +} + +UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs *args) { + args->align = UI_ALIGN_RIGHT; + return create_label(obj, args); +} + + +char* ui_label_get(UiString *s) { + NSTextField *label = (__bridge NSTextField*)s->obj; + if(s->value.free) { + s->value.free(s->value.ptr); + } + s->value.ptr = strdup(label.stringValue.UTF8String); + return s->value.ptr; +} + +void ui_label_set(UiString *s, const char *str) { + NSTextField *label = (__bridge NSTextField*)s->obj; + if(s->value.free) { + s->value.free(s->value.ptr); + } + s->value.ptr = NULL; + label.stringValue = [[NSString alloc] initWithUTF8String:str]; +}