add support for sublists without headers (Cocoa)

Sat, 11 Oct 2025 12:00:07 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 11 Oct 2025 12:00:07 +0200
changeset 834
8801df33144f
parent 833
6cbc74aeff13
child 835
a0e1ff100512

add support for sublists without headers (Cocoa)

ui/cocoa/list.h file | annotate | diff | comparison | revisions
ui/cocoa/list.m file | annotate | diff | comparison | revisions
--- a/ui/cocoa/list.h	Sat Oct 11 11:23:24 2025 +0200
+++ b/ui/cocoa/list.h	Sat Oct 11 12:00:07 2025 +0200
@@ -68,7 +68,7 @@
 @property UiVar *var;
 @property UiSubList *sublist;
 
-@property int index;
+@property int sublistIndex;
 @property int sublistStartRow;
 @property int rownum;
 
@@ -114,6 +114,7 @@
 @property NSTrackingArea *trackingArea;
 @property NSView *disclosureButton;
 @property BOOL hover;
+@property BOOL showDisclosureButton;
 
 @end
 
--- a/ui/cocoa/list.m	Sat Oct 11 11:23:24 2025 +0200
+++ b/ui/cocoa/list.m	Sat Oct 11 12:00:07 2025 +0200
@@ -490,7 +490,7 @@
     int rownum = 0;
     cx_foreach(UiSubList *, sl, i) {
         UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl];
-        section.index = index;
+        section.sublistIndex = index;
         section.rownum = rownum;
         section.sublistStartRow = rownum;
         [section update:-1];
@@ -516,7 +516,7 @@
 
 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
     UiSourceListItem *i = item;
-    return [i isSection];
+    return [i isSection] ? YES : NO;
 }
 
 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
@@ -601,8 +601,12 @@
 }
 
 - (NSTableRowView *) outlineView:(NSOutlineView *) outlineView
-                  rowViewForItem:(id) item {
+                  rowViewForItem:(id)item {
+    UiSourceListItem *it = item;
     UiSourceListRow *row = [[UiSourceListRow alloc]init];
+    if([it isSection] && it.sublist->header) {
+        row.showDisclosureButton = YES;
+    }
     return row;
 }
 
@@ -619,10 +623,10 @@
     UiSourceListItem *i = item;
     CGFloat rowHeight = outlineView.rowHeight;
     if([i isSection]) {
-        if(i.index == 0) {
-            rowHeight -= 12;
+        if(i.sublist->header) {
+            rowHeight += i.sublistIndex == 0 ? -12 : 4;
         } else {
-            rowHeight += 4;
+            rowHeight = i.sublistIndex == 0 ? 0.1 : 12;
         }
     }
     return rowHeight;
@@ -648,7 +652,7 @@
         UiVar *var = parent != nil ? parent.var : item.var;
         if(item && var) {
             sublistEvent.list = var->value;
-            sublistEvent.sublist_index = parent ? parent.index : item.index;
+            sublistEvent.sublist_index = parent ? parent.sublistIndex : item.sublistIndex;
             sublistEvent.row_index = (int)selectedRow - item.sublistStartRow - 1;
             sublistEvent.sublist_userdata = sublist ? sublist->userdata : NULL;
             sublistEvent.event_data = item.eventdata;
@@ -678,6 +682,8 @@
     _items = [[NSMutableArray alloc]initWithCapacity:16];
     if(sublist->header) {
         _label = [[NSString alloc]initWithUTF8String:sublist->header];
+    } else {
+        _label = @"";
     }
     UiVar *var = uic_widget_var(sourcelist.obj->ctx,
                                 sourcelist.obj->ctx,
@@ -692,6 +698,8 @@
     _parent = parent;
     if(item->label) {
         _label = [[NSString alloc]initWithUTF8String:item->label];
+    } else {
+        _label = @"";
     }
     _eventdata = item->eventdata;
     return self;
@@ -720,7 +728,7 @@
         }
         
         UiSourceListItem *it = [[UiSourceListItem alloc] init:&item parent:self];
-        it.index = index;
+        it.sublistIndex = index;
         it.rownum = self.rownum + index;
         it.sublistStartRow = _parent ? _parent.sublistStartRow : _sublistStartRow;
         [_items addObject:it];
@@ -788,7 +796,7 @@
 
 - (void)mouseEntered:(NSEvent *)event {
     _hover = YES;
-    _disclosureButton.hidden = NO;
+    _disclosureButton.hidden = _showDisclosureButton ? NO : YES;
 }
 
 - (void)mouseExited:(NSEvent *)event {

mercurial