]> uap-core.de Git - uwplayer.git/commitdiff
autoadjust sidebar widget size default
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 16 Aug 2025 16:09:12 +0000 (18:09 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 16 Aug 2025 16:09:12 +0000 (18:09 +0200)
application/Sidebar.c

index 481caf2b9618a7b15f6869d9a12bce78595ef293..85bd0eb3926270c840b0af734b6ed0d1374280fd 100644 (file)
@@ -294,9 +294,11 @@ static void sidebar_expose(Widget widget, XEvent *event, Region    region) {
     int height = s->sidebar.elmHeight;
     
     
     int height = s->sidebar.elmHeight;
     
     
+    Dimension new_width = parent->core.width;
     int list_height = numTracks * height;
     if((list_height > s->core.height) || (w < parent->core.width)) {
         XtMakeResizeRequest(widget, parent->core.width, list_height + 5, &w, &h);
     int list_height = numTracks * height;
     if((list_height > s->core.height) || (w < parent->core.width)) {
         XtMakeResizeRequest(widget, parent->core.width, list_height + 5, &w, &h);
+        new_width = w;
     }
     
     
     }
     
     
@@ -316,7 +318,20 @@ static void sidebar_expose(Widget widget, XEvent *event, Region    region) {
             XftDrawRect(s->sidebar.d, &s->sidebar.select2_bg, 0, i.index*height, s->core.width, height);
         }
         
             XftDrawRect(s->sidebar.d, &s->sidebar.select2_bg, 0, i.index*height, s->core.width, height);
         }
         
-        FontDrawString8(s->sidebar.d, cg, s->sidebar.font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
+        size_t namelen = strlen(name);
+        XGlyphInfo ext;
+        FontTextExtents8(XtDisplay(widget), s->sidebar.font, (const FcChar8*)name, namelen, &ext);
+        
+        FontDrawString8(s->sidebar.d, cg, s->sidebar.font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, namelen);
+        
+        if(ext.xOff + 20 > new_width) {
+            new_width = ext.xOff + 20;
+        }
+    }
+    
+    if(new_width != w) {
+        printf("adjust sidebar size: %d\n", (int)new_width);
+        XtMakeResizeRequest(widget, new_width, list_height + 5, &w, &h);
     }
 }
 
     }
 }