Browse code

Navigate directories

Dario Rodriguez authored on 28/02/2025 19:33:08
Showing 1 changed files
... ...
@@ -654,6 +654,49 @@ im_body_add(body_t *body,char *dir)
654 654
 int
655 655
 im_body_mouse(body_t *body, Vector2 mousepos, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail)
656 656
 {
657
+        int i;
658
+        char *ptr;
659
+        dirdata_t *dirdata;
660
+        listingdata_t *ld;
661
+        if(body==NULL || click_avail==NULL || body->currentdirdata<0 || body->currentdirdata>=body->sizedirdata || body->dirdata[body->currentdirdata]==NULL)
662
+                return(-1); /* sanity check error */
663
+        if(*click_avail==0 || lmbreleased==0)
664
+                return(0); /* nothing to do */
665
+        dirdata=body->dirdata[body->currentdirdata];
666
+        /* leftside backbutton */
667
+        if(is_imutil_insidexywh(mousepos,&(body->backxywh))) {
668
+                static char sep[]={SEP};
669
+                if((ptr=strrchr(dirdata->dirname,sep[0]))!=NULL) {
670
+                        *ptr='\0';
671
+                        listing_get(&(dirdata->listing),body->rootdir,dirdata->dirname,1);
672
+                        *click_avail=0;
673
+                        return(0);
674
+                }
675
+        }
676
+        /* leftside directories */
677
+        for(i=0;i<dirdata->listing.usedelems;i++) {
678
+                ld=dirdata->listing.elems+i;
679
+                if(ld->name[0]!='d')
680
+                        continue;
681
+                if(is_imutil_insidexywh(mousepos,&(ld->leftxywh))) {
682
+                        char *newname,*oldprefix;
683
+                        int l,l0,l1;
684
+                        static char sep[]={SEP};
685
+                        oldprefix=(strcmp(dirdata->dirname,SEP)==0)?"":dirdata->dirname;
686
+                        l=(l0=strlen(oldprefix))+1+(l1=strlen(ld->name+1))+1;
687
+                        if((newname=malloc(l))==NULL)
688
+                                return(-1); /* insuf. mem. */
689
+                        memcpy(newname,oldprefix,l0);
690
+                        newname[l0]=sep[0];
691
+                        memcpy(newname+l0+1,ld->name+1,l1);
692
+                        newname[l0+1+l1]='\0';
693
+                        free(dirdata->dirname),dirdata->dirname=NULL;
694
+                        dirdata->dirname=newname;
695
+                        listing_get(&(dirdata->listing),body->rootdir,dirdata->dirname,1);
696
+                        *click_avail=0;
697
+                        return(0);
698
+                }
699
+        }
657 700
 #warning TODO
658 701
         return(0);
659 702
 }
... ...
@@ -689,8 +732,8 @@ im_body_draw(body_t *body, int windowwidth, int windowheight)
689 732
                                 continue; /* this element is not in leftside */
690 733
                         margin=font->height/4;
691 734
                         sidelen=(is_leftside)?LEFTIMAGESIDELEN:dirdata->height-(fontbig->height+fontbig->height/4+font->height+margin*4+fontbig->height/4);
692
-                        if(is_leftside) {
693
-                                /* draw left side back arrow */
735
+                        /* draw left side back arrow if is_leftside and not in root dir */
736
+                        if(is_leftside && !(dirdata->dirname[0]=='\0' || strcmp(dirdata->dirname,SEP)==0)) {
694 737
                                 v2.x=(float) (body->xywh.x+fontbig->height/2);
695 738
                                 v2.y=(float) (body->xywh.y+fontbig->height/4);
696 739
                                 m2=MeasureTextEx(fontbig->font,UTF8DOWNARROW,fontbig->height,0);