]> uap-core.de Git - uwplayer.git/commitdiff
add playlist scrollbar
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 5 Sep 2022 11:54:33 +0000 (13:54 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 5 Sep 2022 11:54:33 +0000 (13:54 +0200)
application/Sidebar.c
application/main.c
application/window.c
application/window.h

index 4faff71308150ce2f5d60cfc3b9ad0a9b449e4a6..3a2c29b632dd00a61ec0263ed7aaee8e90a9b049 100644 (file)
@@ -192,8 +192,18 @@ static void sidebar_destroy(Widget widget) {
     
 }
 
+static int testresize = 1;
 static void sidebar_resize(Widget widget) {
-    
+    if(testresize) {
+        XtWidgetGeometry geom;
+        geom.request_mode = CWWidth | CWHeight;
+        geom.width = 200;
+        geom.height = 2000;
+        XtWidgetGeometry result;
+        //XtMakeGeometryRequest(widget, &geom, &result);
+        testresize = 0;
+    }
+    printf("resize\n");
 }
 
 static int xdnd_initialized = 0;
@@ -222,22 +232,44 @@ static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttribut
             XtWindow(widget),
             visual,
             widget->core.colormap);
+    
+    Dimension w, h;
+    
+    Widget parent = XtParent(widget);
+    XtVaSetValues(parent, XmNbackground, WhitePixelOfScreen(XtScreen(parent)), NULL);
+    
+    XtMakeResizeRequest(widget, 200, 100, &w, &h);
+    
+    
 }
 
 static void sidebar_expose(Widget widget, XEvent *event, Region        region) {
     //printf("expose\n");
     Dimension w, h;
-    XtMakeResizeRequest(widget, 200, 200, &w, &h);
+    //XtMakeResizeRequest(widget, 200, 2000, &w, &h);
     
-    Sidebar s = (Sidebar)widget;
-    XftFont *xftFont = s->sidebar.font->fonts->font;
+    w = widget->core.width;
+    h = widget->core.height;
     
+    Widget parent = XtParent(widget);
     
-    XftDrawRect(s->sidebar.d, &s->sidebar.bg, 0, 0, s->core.width, s->core.height);
+    Sidebar s = (Sidebar)widget;
+    XftFont *xftFont = s->sidebar.font->fonts->font;
+    UcxList *tracks = s->sidebar.window->playlist.tracks;
+    size_t numTracks = ucx_list_size(tracks);
     
     int fontheight = xftFont->ascent;
     int height = s->sidebar.elmHeight;
     
+    int list_height = numTracks * height;
+    if((list_height > s->core.height) || (w < parent->core.width)) {
+        XtMakeResizeRequest(widget, parent->core.width, list_height, &w, &h);
+    }
+    
+    
+    XftDrawRect(s->sidebar.d, &s->sidebar.bg, 0, 0, w, h);
+    
+    
     //printf("current track: %d\n", s->sidebar.window->playlist.current_track);
     
     int i = 0;
@@ -345,6 +377,7 @@ static void sidebar_xdnd_callback(Widget w, XtPointer udata, XtPointer cdata) {
     path[k] = '\0';
     
     PlayListAddFile(s->sidebar.window, path);
+    SidebarRepaint((Widget)s);
     
     free(path);
 }
index ecaf72bdf89530c609f1f33514081aeebeb8c164..e12d1aa0df620f21f7ddee76e1e229b6763037eb 100644 (file)
@@ -51,7 +51,7 @@ static String fallback[] = {
         
         "*pbbutton.shadowThickness: 1",
         "*pbbutton.highlightThickness: 1",
-    
+        
         "*XmText.baseTranslations: #override\\n" \
                                 "Ctrl~Alt~Meta<KeyPress>v: paste-clipboard()\\n" \
                                 "Ctrl~Alt~Meta<KeyPress>c: copy-clipboard()\\n" \
index 4cdeadc18ad9fe13e85fbc1a4b22f9f6406d03c2..7f1158c96e2f4312232db62d0fdfbfd794b4bce2 100644 (file)
@@ -307,10 +307,16 @@ MainWindow* WindowCreate(Display *display) {
     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
     XtSetArg(args[n], XmNtopWidget, window->menubar); n++;
     XtSetArg(args[n], XmNwidth, 300); n++;
-    window->sidebar = CreateSidebar(container, "sidebar", args, n);
+    XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
+    XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
+    XtSetArg(args[n], XmNspacing, 0); n++;
+    XtSetArg(args[n], XmNshadowThickness, 0); n++;
+    window->sidebar_scrolledwindow = XmCreateScrolledWindow(container, "sw_sidebar", args, n);
+    window->sidebar = CreateSidebar(window->sidebar_scrolledwindow, "sidebar", args, 0);
     SidebarSetWindow(window->sidebar, window);
+    XtManageChild(window->sidebar);
     //XtManageChild(window->sidebar);
-       
+        
     n = 0;
     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
@@ -721,10 +727,10 @@ void WindowShowPlayerCursor(MainWindow *win) {
 
 void WindowShowSidebar(MainWindow *win, bool visible) {
     if(visible) {
-        XtManageChild(win->sidebar);
-        XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar, NULL);
+        XtManageChild(win->sidebar_scrolledwindow);
+        XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar_scrolledwindow, NULL);
     } else {
-        XtUnmanageChild(win->sidebar);
+        XtUnmanageChild(win->sidebar_scrolledwindow);
         XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_FORM, NULL);
     }
 }
index dd44b8893a7e05d06c93b05bcd892f660708e678..77939b034f54b6ac8d619d4cd3ce88c727228b73 100644 (file)
@@ -62,6 +62,7 @@ typedef struct MainWindow {
     Widget window;
     Widget menubar;
     Widget player_widget;
+    Widget sidebar_scrolledwindow;
     Widget sidebar;
     char *file;
     Player *player;