shithub: riscv

Download patch

ref: 63f8dc808490ef038ce868eba62983290e38489d
parent: aba0c7fceac419c426da85b3f5d4bfe82d410e00
author: phil9 <[email protected]>
date: Wed Apr 6 12:46:58 EDT 2022

mothra: make scrollbar style consistent with other applications

	Scrollbar was drawn using a wide dark gutter over a white background
	whereas other applications (window, sam, ...) use a thinner scrollbar with an
	inverse colorscheme.
	This makes the scrollbar more consistent with other 9front applications.

--- a/sys/src/cmd/mothra/libpanel/draw.c
+++ b/sys/src/cmd/mothra/libpanel/draw.c
@@ -13,12 +13,13 @@
 #define	CKWID	1	/* width of frame around check mark */
 #define	CKINSET	1	/* space around check mark frame */
 #define	CKBORDER 2	/* space around X inside frame */
-static Image *pl_light, *pl_dark, *pl_tick, *pl_hilit;
+static Image *pl_light, *pl_dark, *pl_scrl, *pl_tick, *pl_hilit;
 Image *pl_blue, *pl_white, *pl_black;
 int pl_drawinit(void){
 	pl_white=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xFFFFFFFF);
 	pl_light=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xFFFFFFFF);
 	pl_dark=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
+	pl_scrl=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x999999FF);
 	pl_black=allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x000000FF);
 	pl_hilit=allocimage(display, Rect(0,0,1,1), CHAN1(CAlpha,8), 1, 0x80);
 	pl_blue=allocimage(display, Rect(0,0,1,1), RGB24, 1, 0x0000FFFF);
@@ -28,7 +29,7 @@
 		draw(pl_tick, Rect(0, 0, TICKW, TICKW), pl_black, nil, ZP);
 		draw(pl_tick, Rect(0, font->height-TICKW, TICKW, font->height), pl_black, nil, ZP);
 	}
-	if(pl_white==0 || pl_light==0 || pl_black==0 || pl_dark==0 || pl_blue==0 || pl_tick==0) sysfatal("allocimage: %r");
+	if(pl_white==0 || pl_light==0 || pl_black==0 || pl_dark==0 || pl_scrl==0 || pl_blue==0 || pl_tick==0) sysfatal("allocimage: %r");
 	return 1;
 }
 Rectangle pl_boxoutline(Image *b, Rectangle r, int style, int fill){
@@ -205,6 +206,19 @@
 	draw(b, r1, pl_light, 0, ZP);
 	draw(b, r2, pl_dark, 0, ZP);
 	draw(b, r3, pl_light, 0, ZP);
+}
+void pl_scrollupd(Image *b, Rectangle r, int lo, int hi)
+{
+	Rectangle sr;
+	if(lo<0) lo=0;
+	if(hi<=lo) hi=lo+1;
+	sr=r;
+	sr.min.y+=lo;
+	sr.max.x-=1;
+	sr.max.y=sr.min.y+hi;
+	if(sr.max.y>r.max.y) sr.max.y=r.max.y;
+	draw(b, r, pl_scrl, 0, ZP);
+	draw(b, sr, pl_light, 0, ZP);
 }
 void pl_draw1(Panel *p, Image *b);
 void pl_drawall(Panel *p, Image *b){
--- a/sys/src/cmd/mothra/libpanel/pldefs.h
+++ b/sys/src/cmd/mothra/libpanel/pldefs.h
@@ -68,6 +68,7 @@
 Rectangle pl_radio(Image *, Rectangle, int);
 int pl_ckwid(void);
 void pl_sliderupd(Image *, Rectangle, int, int, int);
+void pl_scrollupd(Image *, Rectangle, int, int);
 void pl_invis(Panel *, int);
 Point pl_iconsize(int, Icon *);
 void pl_highlight(Image *, Rectangle);
--- a/sys/src/cmd/mothra/libpanel/scrollbar.c
+++ b/sys/src/cmd/mothra/libpanel/scrollbar.c
@@ -12,12 +12,12 @@
 	Rectangle interior;
 	Point minsize;
 };
-#define	SBWID	15	/* should come from draw.c? */
+#define	SBWID	8	/* should come from draw.c? */
 void pl_drawscrollbar(Panel *p){
 	Scrollbar *sp;
 	sp=p->data;
 	sp->interior=pl_outline(p->b, p->r, SUP); /* SUP was p->state */
-	pl_sliderupd(p->b, sp->interior, sp->dir, sp->lo, sp->hi);
+	pl_scrollupd(p->b, sp->interior, sp->lo, sp->hi);
 }
 int pl_hitscrollbar(Panel *g, Mouse *m){
 	int oldstate, pos, len, dy;
@@ -49,8 +49,7 @@
 		switch(m->buttons){
 		case 1:
 			dy=pos*(sp->hi-sp->lo)/len;
-			pl_sliderupd(g->b, sp->interior, sp->dir, sp->lo-dy,
-				sp->hi-dy);
+			pl_scrollupd(g->b, sp->interior, sp->lo-dy, sp->hi-dy);
 			break;
 		case 2:
 			if(g->scrollee && g->scrollee->scroll)
@@ -59,8 +58,7 @@
 			break;
 		case 4:
 			dy=pos*(sp->hi-sp->lo)/len;
-			pl_sliderupd(g->b, sp->interior, sp->dir, sp->lo+dy,
-				sp->hi+dy);
+			pl_scrollupd(g->b, sp->interior, sp->lo+dy, sp->hi+dy);
 			break;
 		}
 	}
@@ -94,7 +92,6 @@
 	sp=p->data;
 	ul=p->r.min;
 	size=subpt(p->r.max, p->r.min);
-	pl_interior(p->state, &ul, &size);
 	mylen=sp->dir==HORIZ?size.x:size.y;
 	if(len==0) len=1;
 	sp->lo=lo*mylen/len;