9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <unobe@cpan.org>
To: 9front@9front.org
Subject: [9front] [PATCH] rio: resize border and scrollbar based on font
Date: Thu, 09 May 2024 21:04:32 +0000	[thread overview]
Message-ID: <DB8996DAC2058F8EB352F7251479F544@smtp.pobox.com> (raw)


when using large fonts the scroll bar is aberrantly small, as is
the border size. initialize the border widths and scroll widths
based on the font size. set a minimum value based on existing
hard-coded values.
---
diff 025a2d172ebfe36bc0da32f5712dd250916c73f1 e51d4aa069548de51d0e88a6d621d278e9138cd0
--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -46,11 +46,11 @@
 
 enum
 {
-	Selborder		= 4,		/* border of selected window */
-	Unselborder	= 1,		/* border of unselected window */
-	Scrollwid 		= 12,		/* width of scroll bar */
-	Scrollgap 		= 4,		/* gap right of scroll bar */
-	BIG			= 3,		/* factor by which window dimension can exceed screen */
+	Minselborder	= 4,		/* minimum border of selected window */
+	Minunselborder	= 1,		/* minimum border of unselected window */
+	Minscrollwid 	= 12,		/* minimum width of scroll bar */
+	Minscrollgap 	= 4,		/* minimum gap right of scroll bar */
+	BIG		= 3,		/* factor by which window dimension can exceed screen */
 	TRUE		= 1,
 	FALSE		= 0,
 };
@@ -341,3 +341,8 @@
 int		messagesize;		/* negotiated in 9P version setup */
 int		shiftdown;
 int		debug;
+int 		Borderwid;		/* border width of window */
+int 		Selborder;		/* border of selected window */
+int 		Unselborder;		/* border of unselected window */
+int 		Scrollwid;		/* width of scroll bar */
+int 		Scrollgap;		/* gap right of scroll bar */
--- a/sys/src/cmd/rio/data.c
+++ b/sys/src/cmd/rio/data.c
@@ -185,6 +185,16 @@
 };
 
 void
+fontinit(void)
+{
+	Borderwid = ceil(stringwidth(font, "0") / 4) > Borderwidth ? ceil(stringwidth(font, "0") / 4) : Borderwidth;
+	Selborder = ceil(stringwidth(font, "0") / 2) > Minselborder ? ceil(stringwidth(font, "0") / 2) : Minselborder;
+	Unselborder = ceil(stringwidth(font, "0") / 8) > Minunselborder ? ceil(stringwidth(font, "0") / 8) : Minunselborder;
+	Scrollwid = ceil(stringwidth(font, "0") * 1.5) > Minscrollwid ? ceil(stringwidth(font, "0") * 1.5) : Minscrollwid;
+	Scrollgap = ceil(stringwidth(font, "0") / 2) > Minscrollgap ? ceil(stringwidth(font, "0") / 2) : Minscrollgap;
+}
+
+void
 iconinit(void)
 {
 	background = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
--- a/sys/src/cmd/rio/fns.h
+++ b/sys/src/cmd/rio/fns.h
@@ -16,6 +16,7 @@
 void	error(char*);
 void	killprocs(void);
 int	shutdown(void*, char*);
+void	fontinit(void);
 void	iconinit(void);
 void	*erealloc(void*, uint);
 void *emalloc(uint);
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -182,6 +182,7 @@
 		fprint(2, "rio: can't open display: %r\n");
 		exits("display open");
 	}
+	fontinit();
 	iconinit();
 
 	exitchan = chancreate(sizeof(int), 0);
@@ -951,10 +952,10 @@
 	}
 	if(col != nil){
 		r = canonrect(r);
-		drawedge(&b[0], col, Rect(r.min.x, r.min.y, r.min.x+Borderwidth, r.max.y));
-		drawedge(&b[1], col, Rect(r.min.x+Borderwidth, r.min.y, r.max.x-Borderwidth, r.min.y+Borderwidth));
-		drawedge(&b[2], col, Rect(r.max.x-Borderwidth, r.min.y, r.max.x, r.max.y));
-		drawedge(&b[3], col, Rect(r.min.x+Borderwidth, r.max.y-Borderwidth, r.max.x-Borderwidth, r.max.y));
+		drawedge(&b[0], col, Rect(r.min.x, r.min.y, r.min.x+Borderwid, r.max.y));
+		drawedge(&b[1], col, Rect(r.min.x+Borderwid, r.min.y, r.max.x-Borderwid, r.min.y+Borderwid));
+		drawedge(&b[2], col, Rect(r.max.x-Borderwid, r.min.y, r.max.x, r.max.y));
+		drawedge(&b[3], col, Rect(r.min.x+Borderwid, r.max.y-Borderwid, r.max.x-Borderwid, r.max.y));
 	}
 	lastcol = col;
 }
--- a/sys/src/cmd/rio/wctl.c
+++ b/sys/src/cmd/rio/wctl.c
@@ -100,13 +100,13 @@
 	 * that includes the border on each side with an extra pixel
 	 * so that the text is still drawn
 	 */
-	if(Dx(r) < 100 || Dy(r) < 2*(Borderwidth+1)+font->height)
+	if(Dx(r) < 100 || Dy(r) < 2*(Borderwid+Unselborder)+font->height)
 		return 0;
 	/* window must be on screen */
 	if(!rectXrect(screen->r, r))
 		return 0;
 	/* must have some screen and border visible so we can move it out of the way */
-	if(rectinrect(screen->r, insetrect(r, Borderwidth)))
+	if(rectinrect(screen->r, insetrect(r, Borderwid)))
 		return 0;
 	return 1;
 }
@@ -148,8 +148,8 @@
 	static int i = 0;
 	int minx, miny, dx, dy;
 
-	dx = min(600, Dx(screen->r) - 2*Borderwidth);
-	dy = min(400, Dy(screen->r) - 2*Borderwidth);
+	dx = min(600, Dx(screen->r) - 2*Borderwid);
+	dy = min(400, Dy(screen->r) - 2*Borderwid);
 	minx = 32 + 16*i;
 	miny = 32 + 16*i;
 	i++;
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -353,7 +353,7 @@
 
 	w->i = i;
 	w->mc.image = i;
-	r = insetrect(i->r, Selborder+1);
+	r = insetrect(i->r, Selborder+Unselborder);
 	w->scrollr = r;
 	w->scrollr.max.x = r.min.x+Scrollwid;
 	w->lastsr = ZR;
@@ -1249,7 +1249,7 @@
 
 	w = emalloc(sizeof(Window));
 	w->screenr = i->r;
-	r = insetrect(i->r, Selborder+1);
+	r = insetrect(i->r,Selborder+Unselborder);
 	w->i = i;
 	w->mc = *mc;
 	w->ck = ck;

             reply	other threads:[~2024-05-10  0:03 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 21:04 Romano [this message]
2024-05-10  0:14 ` Jacob Moody
2024-05-10  0:34   ` sl
2024-05-10  6:20   ` Kurt H Maier
2024-05-10 14:10     ` Jacob Moody
2024-05-10 14:16       ` Stanley Lieber
2024-05-10 14:20         ` Jacob Moody
2024-05-10 14:23           ` Stanley Lieber
2024-05-10 14:21         ` ori
2024-05-10 14:33           ` Stanley Lieber
2024-05-10 14:37             ` Stanley Lieber
2024-05-10 14:58       ` Kurt H Maier
2024-05-10 15:28         ` Stuart Morrow
2024-05-10 16:11           ` Stanley Lieber
2024-05-10 16:43             ` Stuart Morrow
2024-05-10 16:50               ` Stuart Morrow
2024-05-11 16:36               ` hiro
2024-05-11 16:30             ` hiro
2024-05-11 16:27       ` hiro
2024-05-11 16:36         ` Jacob Moody
2024-05-10  6:13 Romano
2024-05-10 13:27 ` Kristo
2024-05-10 14:01   ` Stanley Lieber
2024-05-10 14:17 ` Jacob Moody
2024-05-10 18:43   ` Romano
2024-05-10 19:15     ` Jacob Moody
2024-05-10 19:40       ` ori
2024-05-11 16:45         ` hiro
2024-05-11  4:31       ` Romano
2024-05-11 15:00         ` Jacob Moody
2024-05-11 16:54           ` hiro
2024-05-13  5:18           ` Romano
2024-05-11 16:42       ` hiro
2024-05-10 21:00     ` sl
2024-05-11  4:34       ` Romano
2024-05-13  5:38         ` Romano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB8996DAC2058F8EB352F7251479F544@smtp.pobox.com \
    --to=unobe@cpan.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).