From: Olaf Wintermann Date: Sat, 16 Aug 2025 16:09:12 +0000 (+0200) Subject: autoadjust sidebar widget size X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;p=uwplayer.git autoadjust sidebar widget size --- diff --git a/application/Sidebar.c b/application/Sidebar.c index 481caf2..85bd0eb 100644 --- a/application/Sidebar.c +++ b/application/Sidebar.c @@ -294,9 +294,11 @@ static void sidebar_expose(Widget widget, XEvent *event, Region region) { 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); + 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); } - 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); } }