Browse code

Aesthetic fixes for leftside

Dario Rodriguez authored on 01/03/2025 20:14:21
Showing 1 changed files
... ...
@@ -13,6 +13,8 @@
13 13
  *      20250224 Draw right dir list and store elem positions.
14 14
  *      20250225 Draw image placeholders
15 15
  *      20250226 Fix rightside positions
16
+ *      20250228 Navigate directories
17
+ *      20250301 Aestetic fixes for leftside.
16 18
  *
17 19
  * Author: Dario Rodriguez dario@darionomono.com
18 20
  * (c) Dario Rodriguez 2025
... ...
@@ -38,7 +40,7 @@
38 40
 #define LEFTSIZE 720
39 41
 #define DEFAULTDIRDATAHEIGHT 150
40 42
 #define DEFAULTDIRDATATRIANGLEW 35
41
-#define LEFTIMAGESIDELEN 130
43
+#define LEFTIMAGESIDELEN 125
42 44
 
43 45
 #define FONTSIZE 18
44 46
 #define FONTBIGSIZE 32
... ...
@@ -282,7 +284,7 @@ im_init(char *menus, char *rootdir)
282 284
                 return(NULL); /* insuf. mem. */
283 285
         }
284 286
         /* add the starting directory */
285
-        im_body_add(im->body,"/");
287
+        im_body_add(im->body,"");
286 288
         return(im);
287 289
 }
288 290
 
... ...
@@ -667,11 +669,15 @@ im_body_mouse(body_t *body, Vector2 mousepos, int lmbpressed, int lmbreleased, i
667 669
         if(is_imutil_insidexywh(mousepos,&(body->backxywh))) {
668 670
                 static char sep[]={SEP};
669 671
                 if((ptr=strrchr(dirdata->dirname,sep[0]))!=NULL) {
672
+                        /* previous dir */
670 673
                         *ptr='\0';
671
-                        listing_get(&(dirdata->listing),body->rootdir,dirdata->dirname,1);
672
-                        *click_avail=0;
673
-                        return(0);
674
+                } else {
675
+                        /* root dir */
676
+                        dirdata->dirname[0]='\0';
674 677
                 }
678
+                listing_get(&(dirdata->listing),body->rootdir,dirdata->dirname,1);
679
+                *click_avail=0;
680
+                return(0);
675 681
         }
676 682
         /* leftside directories */
677 683
         for(i=0;i<dirdata->listing.usedelems;i++) {
... ...
@@ -683,13 +689,17 @@ im_body_mouse(body_t *body, Vector2 mousepos, int lmbpressed, int lmbreleased, i
683 689
                         int l,l0,l1;
684 690
                         static char sep[]={SEP};
685 691
                         oldprefix=(strcmp(dirdata->dirname,SEP)==0)?"":dirdata->dirname;
686
-                        l=(l0=strlen(oldprefix))+1+(l1=strlen(ld->name+1))+1;
692
+                        l0=strlen(oldprefix);
693
+                        l1=strlen(ld->name+1);
694
+                        l=l0+((l0>0)?1:0)+l1+1;
687 695
                         if((newname=malloc(l))==NULL)
688 696
                                 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';
697
+                        if(l0>0) {
698
+                                memcpy(newname,oldprefix,l0);
699
+                                newname[l0]=sep[0];
700
+                        }
701
+                        memcpy(newname+l0+((l0>0)?1:0),ld->name+1,l1);
702
+                        newname[l0+((l0>0)?1:0)+l1]='\0';
693 703
                         free(dirdata->dirname),dirdata->dirname=NULL;
694 704
                         dirdata->dirname=newname;
695 705
                         listing_get(&(dirdata->listing),body->rootdir,dirdata->dirname,1);
... ...
@@ -734,9 +744,9 @@ im_body_draw(body_t *body, int windowwidth, int windowheight)
734 744
                         sidelen=(is_leftside)?LEFTIMAGESIDELEN:dirdata->height-(fontbig->height+fontbig->height/4+font->height+margin*4+fontbig->height/4);
735 745
                         /* draw left side back arrow if is_leftside and not in root dir */
736 746
                         if(is_leftside && !(dirdata->dirname[0]=='\0' || strcmp(dirdata->dirname,SEP)==0)) {
737
-                                v2.x=(float) (body->xywh.x+fontbig->height/2);
738
-                                v2.y=(float) (body->xywh.y+fontbig->height/4);
739 747
                                 m2=MeasureTextEx(fontbig->font,UTF8DOWNARROW,fontbig->height,0);
748
+                                v2.x=(float) (body->xywh.x+fontbig->height/2);
749
+                                v2.y=(float) (body->xywh.y+fontbig->height/4+(fontbig->height-v2.x)/2);
740 750
                                 FILLXYWH(body->backxywh,v2.x-fontbig->height/4,v2.y-fontbig->height/8,m2.x+fontbig->height/4,m2.x+fontbig->height/4);
741 751
 #if 0
742 752
 DrawTexture(fontbig->font.texture, 0, 0, WHITE); /* font glyphs -- see https://github.com/raysan5/raylib/issues/2022 */
... ...
@@ -773,7 +783,7 @@ DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone
773 783
                         /* directories */
774 784
                         if(is_leftside) {
775 785
                                 x0=body->xywh.x+font->height/2;
776
-                                x1=body->xywh.x+body->leftsize-font->height/2;
786
+                                x1=body->xywh.x+body->leftsize-DEFAULTDIRDATATRIANGLEW-font->height/2;
777 787
                                 y0=body->xywh.y+font->height/4+m2.y+font->height/2;
778 788
                                 y1=body->xywh.y+body->xywh.h-DEFAULTDIRDATATRIANGLEW-font->height/2;
779 789
                         } else {