Explorar el Código

Use one font size in the network popover

Render every heading, section caption, row and footer line at the
toolkit's 14 px default (bold for headings and captions) instead of
mixing 11, 14 and 16 px.  Give the panel a consistent 12 px outer inset
and 10 px gaps, use 28 px section headers, grow two-line rows to 42 px
and single-line detail rows to 30 px, and drop the "Join again without
the passphrase" subtitle from the Saved networks row.

make all passes; the popover layout was checked in a headless QEMU run.
Johannes Zellner hace 1 semana
padre
commit
47aeb06a63
Se han modificado 2 ficheros con 81 adiciones y 76 borrados
  1. 21 17
      ngui.c
  2. 60 59
      ucmd_netmenu.c

+ 21 - 17
ngui.c

@@ -1392,8 +1392,8 @@ void ngui_popover_begin(struct ngui *ui, struct ngui_popover *p)
 	struct ngui_rect all = { 0, 0, ui->w, ui->h };
 
 	ngui_fill_rect(ui, all, ui->theme.bg);
-	p->body = rect_make(12, 12, ui->w - 24, ui->h - 12 - 28);
-	p->footer = rect_make(12, ui->h - 26, ui->w - 24, 16);
+	p->body = rect_make(12, 12, ui->w - 24, ui->h - 12 - 34);
+	p->footer = rect_make(12, ui->h - 30, ui->w - 24, 18);
 }
 
 void ngui_popover_footer(struct ngui *ui, const struct ngui_popover *p,
@@ -1402,8 +1402,7 @@ void ngui_popover_footer(struct ngui *ui, const struct ngui_popover *p,
 	if (!p || !text || !text[0])
 		return;
 	ngui_push_clip(ui, p->footer);
-	ngui_text_px(ui, p->footer.x, p->footer.y, text, slen(text),
-		     color, 11, 0, 0, 0);
+	ngui_text_utf8(ui, p->footer.x, p->footer.y, text, color);
 	ngui_pop_clip(ui);
 }
 
@@ -1412,12 +1411,12 @@ int ngui_section(struct ngui *ui, struct ngui_rect r, const char *caption,
 {
 	struct ngui_rect br;
 	int fired = 0;
-	int y = r.y + (r.h - 18) / 2;
+	int y = r.y + (r.h - 17) / 2;
 
 	if (y < r.y)
 		y = r.y;
 	ngui_text_px(ui, r.x, y, caption, slen(caption), ui->theme.text_dim,
-		     11, 1, 0, 0);
+		     14, 1, 0, 0);
 	ngui_fill_rect(ui, rect_make(r.x, r.y + r.h - 1, r.w, 1),
 		       ui->theme.button);
 	if (action_id && action && action[0]) {
@@ -1426,7 +1425,7 @@ int ngui_section(struct ngui *ui, struct ngui_rect r, const char *caption,
 
 		if (bw < 58)
 			bw = 58;
-		br = rect_make(r.x + r.w - bw, r.y + (r.h - 22) / 2, bw, 22);
+		br = rect_make(r.x + r.w - bw, r.y + (r.h - 24) / 2, bw, 24);
 		if (ngui_button(ui, action_id, br, action))
 			fired = 1;
 	}
@@ -1446,7 +1445,7 @@ static int ngui_list_row_common(struct ngui *ui, unsigned int id,
 		ngui_rect_contains(&r, ui->release_x, ui->release_y);
 	int fired = 0;
 	int left = r.x + 10, right = r.x + r.w - 10;
-	int title_h, sub_h, block_h, ty;
+	int title_h, block_h, ty;
 	unsigned short bg = 0, fg, sub_fg, trail_fg;
 
 	if (press_hot)
@@ -1465,6 +1464,7 @@ static int ngui_list_row_common(struct ngui *ui, unsigned int id,
 		bg = ui->theme.panel_alt;
 	if (bg)
 		ngui_fill_round_rect(ui, r, 6, 6, 6, 6, bg);
+	title_h = ngui_text_line_height(ui, ui->font_px, 0);
 	fg = ui->theme.text;
 	sub_fg = row->selected ? ui->theme.text : ui->theme.text_dim;
 	trail_fg = row->selected ? ui->theme.text : ui->theme.text_dim;
@@ -1483,10 +1483,11 @@ static int ngui_list_row_common(struct ngui *ui, unsigned int id,
 		right -= tw + 8;
 		if (utf8)
 			ngui_text_utf8(ui, right + 8,
-				       r.y + (r.h - 16) / 2, row->trailing,
-				       trail_fg);
+				       r.y + (r.h - title_h) / 2,
+				       row->trailing, trail_fg);
 		else
-			ngui_text(ui, right + 8, r.y + (r.h - 16) / 2,
+			ngui_text(ui, right + 8,
+				  r.y + (r.h - title_h) / 2,
 				  row->trailing, trail_fg);
 	}
 	if (row->bars >= 0) {
@@ -1504,9 +1505,7 @@ static int ngui_list_row_common(struct ngui *ui, unsigned int id,
 	if (right <= left)
 		return fired;
 
-	title_h = ngui_text_line_height(ui, ui->font_px, 0);
-	sub_h = ngui_text_line_height(ui, 11, 0);
-	block_h = row->subtitle && row->subtitle[0] ? title_h + sub_h - 2 :
+	block_h = row->subtitle && row->subtitle[0] ? title_h * 2 - 2 :
 						      title_h;
 	ty = r.y + (r.h - block_h) / 2;
 	if (ty < r.y)
@@ -1517,9 +1516,14 @@ static int ngui_list_row_common(struct ngui *ui, unsigned int id,
 		ngui_text_utf8(ui, left, ty, row->title, fg);
 	else
 		ngui_text(ui, left, ty, row->title, fg);
-	if (row->subtitle && row->subtitle[0])
-		ngui_text_px(ui, left, ty + title_h - 2, row->subtitle,
-			     slen(row->subtitle), sub_fg, 11, 0, 0, 0);
+	if (row->subtitle && row->subtitle[0]) {
+		if (utf8)
+			ngui_text_utf8(ui, left, ty + title_h - 2,
+				       row->subtitle, sub_fg);
+		else
+			ngui_text(ui, left, ty + title_h - 2, row->subtitle,
+				  sub_fg);
+	}
 	ngui_pop_clip(ui);
 
 	if (hot)

+ 60 - 59
ucmd_netmenu.c

@@ -19,9 +19,12 @@
 
 #define MAX_DEVS 8
 #define MAX_BSS  32
-#define DEV_ROW_H  32
-#define WIFI_ROW_H 38
-#define SAVED_ROW_H 34
+#define DEV_ROW_H        42
+#define WIFI_ROW_H       42
+#define SAVED_ROW_H      30
+#define SAVED_LIST_ROW_H 42
+#define SECTION_H        28
+#define MENU_GAP         10
 #define LOG_MAX  2048
 
 #define ID_REFRESH       1
@@ -755,7 +758,7 @@ static void draw_status_card(struct ngui_rect r)
 		p = sput(p, "Wired network");
 	*p = '\0';
 	ngui_text_px(&ui, r.x + 34, r.y + 10, line, slen(line),
-		     ui.theme.text, 16, 1, 0, 0);
+		     ui.theme.text, 14, 1, 0, 0);
 
 	p = line;
 	if (net_present) {
@@ -788,16 +791,14 @@ static void draw_wifi_list(struct ngui_rect area, int *y)
 	int i;
 
 	if (!wifi_present) {
-		ngui_text_px(&ui, area.x + 12, *y + 10,
-			     "No Wi-Fi card detected", 22,
-			     ui.theme.text_dim, 11, 0, 0, 0);
+		ngui_text(&ui, area.x + 12, *y + 12,
+			  "No Wi-Fi card detected", ui.theme.text_dim);
 		*y += WIFI_ROW_H;
 		return;
 	}
 	if (scanning) {
-		ngui_text_px(&ui, area.x + 12, *y + 10,
-			     "Scanning for networks...", 24,
-			     ui.theme.accent, 11, 0, 0, 0);
+		ngui_text(&ui, area.x + 12, *y + 12,
+			  "Scanning for networks...", ui.theme.accent);
 		*y += WIFI_ROW_H;
 		return;
 	}
@@ -806,8 +807,8 @@ static void draw_wifi_list(struct ngui_rect area, int *y)
 			"Connected - disconnect to scan for other networks" :
 			"Press Scan to list Wi-Fi networks";
 
-		ngui_text_px(&ui, area.x + 12, *y + 10, msg, slen(msg),
-			     ui.theme.text_dim, 11, 0, 0, 0);
+		ngui_text(&ui, area.x + 12, *y + 12, msg,
+			  ui.theme.text_dim);
 		*y += WIFI_ROW_H;
 		return;
 	}
@@ -850,8 +851,8 @@ static void draw_main(void)
 
 	card = ngui_cut_top(&body, 64);
 	draw_status_card(card);
-	body.y += 8;
-	body.h -= 8;
+	body.y += MENU_GAP;
+	body.h -= MENU_GAP;
 
 	shown = 0;
 	for (i = 0; i < ndev; i++)
@@ -861,16 +862,16 @@ static void draw_main(void)
 	if (shown > 4)
 		shown = 4;
 
-	content_h = 26 + (shown ? shown * DEV_ROW_H : DEV_ROW_H) +
-		    (more ? 18 : 0) + 10 + 26;
+	content_h = SECTION_H + (shown ? shown * DEV_ROW_H : DEV_ROW_H) +
+		    (more ? 20 : 0) + MENU_GAP + SECTION_H;
 	if (!wifi_present || scanning || nbss == 0)
 		content_h += WIFI_ROW_H;
 	else
 		content_h += nbss * WIFI_ROW_H;
 	if (net_present)
-		content_h += 10 + 26 + 4 * 26;
+		content_h += MENU_GAP + SECTION_H + 4 * 30;
 	if (nsaved)
-		content_h += SAVED_ROW_H + 8;
+		content_h += SAVED_ROW_H + MENU_GAP;
 
 	main_scroll.content_h = content_h;
 	area = body;
@@ -879,10 +880,10 @@ static void draw_main(void)
 	ngui_scroll_keys(&ui, &main_scroll);
 
 	y = area.y - main_scroll.offset;
-	r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+	r = (struct ngui_rect){ area.x, y, area.w - 18, SECTION_H };
 	if (ngui_section(&ui, r, "Devices", ID_REFRESH, "Refresh"))
 		actions |= ACT_REFRESH;
-	y += 26;
+	y += SECTION_H;
 
 	{
 		int n = 0;
@@ -912,8 +913,8 @@ static void draw_main(void)
 			"No wired or USB device" :
 			"No device found - plug one in and Refresh";
 
-		ngui_text_px(&ui, area.x + 12, y + 8, msg, slen(msg),
-			     ui.theme.text_dim, 11, 0, 0, 0);
+		ngui_text(&ui, area.x + 12, y + 12, msg,
+			  ui.theme.text_dim);
 		y += DEV_ROW_H;
 	} else if (more) {
 		p = line;
@@ -921,13 +922,13 @@ static void draw_main(void)
 		p = put_dec(p, (unsigned int)more);
 		p = sput(p, " more devices");
 		*p = '\0';
-		ngui_text_px(&ui, area.x + 12, y + 2, line, slen(line),
-			     ui.theme.text_dim, 11, 0, 0, 0);
-		y += 18;
+		ngui_text(&ui, area.x + 12, y + 2, line,
+			  ui.theme.text_dim);
+		y += 20;
 	}
 
-	y += 10;
-	r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+	y += MENU_GAP;
+	r = (struct ngui_rect){ area.x, y, area.w - 18, SECTION_H };
 	if (wifi_present && wst.state >= SYS_WIFI_ST_ASSOC) {
 		if (ngui_section(&ui, r, "Wi-Fi", ID_DISCONNECT,
 				 "Disconnect"))
@@ -938,7 +939,7 @@ static void draw_main(void)
 	} else {
 		ngui_section(&ui, r, "Wi-Fi", 0, 0);
 	}
-	y += 26;
+	y += SECTION_H;
 
 	draw_wifi_list(area, &y);
 
@@ -949,10 +950,10 @@ static void draw_main(void)
 		char value[40];
 		int di;
 
-		y += 10;
-		r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+		y += MENU_GAP;
+		r = (struct ngui_rect){ area.x, y, area.w - 18, SECTION_H };
 		ngui_section(&ui, r, "Connection", 0, 0);
-		y += 26;
+		y += SECTION_H;
 		for (di = 0; di < 4; di++) {
 			char *vp = value;
 
@@ -969,7 +970,7 @@ static void draw_main(void)
 				vp = put_mac(vp, net.mac);
 			*vp = '\0';
 
-			r = (struct ngui_rect){ area.x, y, area.w - 18, 26 };
+			r = (struct ngui_rect){ area.x, y, area.w - 18, 30 };
 			if (r.y + r.h > area.y && r.y < area.y + area.h) {
 				row.title = labels[di];
 				row.subtitle = 0;
@@ -978,20 +979,20 @@ static void draw_main(void)
 				row.selected = 0;
 				ngui_list_row(&ui, ID_INFO_BASE + di, r, &row);
 			}
-			y += 26;
+			y += 30;
 		}
 	}
 
 	if (nsaved) {
 		char nbuf[12], *np = nbuf;
 
-		y += 8;
+		y += MENU_GAP;
 		r = (struct ngui_rect){ area.x, y, area.w - 18, SAVED_ROW_H };
 		if (r.y + r.h > area.y && r.y < area.y + area.h) {
 			np = put_dec(np, (unsigned int)nsaved);
 			*np = '\0';
 			row.title = "Saved networks";
-			row.subtitle = "Join again without the passphrase";
+			row.subtitle = 0;
 			row.trailing = nbuf;
 			row.bars = -1;
 			row.selected = 0;
@@ -1018,7 +1019,7 @@ static void draw_pass(void)
 
 	r = ngui_cut_top(&body, 22);
 	ngui_text_px(&ui, r.x, r.y, "WPA2-PSK passphrase", 19,
-		     ui.theme.text_dim, 11, 1, 0, 0);
+		     ui.theme.text_dim, 14, 1, 0, 0);
 
 	r = ngui_cut_top(&body, 34);
 	ev = ngui_text_input(&ui, ID_PASS, r, &pass_in);
@@ -1026,17 +1027,17 @@ static void draw_pass(void)
 		actions |= ACT_CONNECT;
 	if (ev & NGUI_INPUT_CANCEL)
 		actions |= ACT_BACK;
-	body.y += 8;
-	body.h -= 8;
+	body.y += MENU_GAP;
+	body.h -= MENU_GAP;
 
-	r = ngui_cut_top(&body, 20);
-	ngui_text_px(&ui, r.x, r.y,
-		     "8-63 characters, or 64 hex digits for a raw PSK.",
-		     48, ui.theme.text_dim, 11, 0, 0, 0);
-	body.y += 12;
-	body.h -= 12;
+	r = ngui_cut_top(&body, 22);
+	ngui_text(&ui, r.x, r.y,
+		  "8-63 characters, or 64 hex digits for a raw PSK.",
+		  ui.theme.text_dim);
+	body.y += MENU_GAP;
+	body.h -= MENU_GAP;
 
-	r = ngui_cut_top(&body, 30);
+	r = ngui_cut_top(&body, 28);
 	b1 = r;
 	b1.w = 110;
 	b2 = r;
@@ -1079,7 +1080,7 @@ static void draw_connect(void)
 		}
 	}
 	y = log.y + 10;
-	for (i = start; i < conn_log_len && y + 14 <= log.y + log.h - 8; i++) {
+	for (i = start; i < conn_log_len && y + 17 <= log.y + log.h - 8; i++) {
 		char c = conn_log[i];
 
 		if (c == '\r')
@@ -1089,8 +1090,8 @@ static void draw_connect(void)
 			if (line_y)
 				ngui_text_px(&ui, log.x + 10, y, line,
 					     (unsigned int)line_y,
-					     ui.theme.text_dim, 11, 0, 0, 1);
-			y += 14;
+					     ui.theme.text_dim, 14, 0, 0, 1);
+			y += 17;
 			line_y = 0;
 			continue;
 		}
@@ -1100,14 +1101,14 @@ static void draw_connect(void)
 	if (line_y) {
 		line[line_y] = '\0';
 		ngui_text_px(&ui, log.x + 10, y, line, (unsigned int)line_y,
-			     ui.theme.text_dim, 11, 0, 0, 1);
+			     ui.theme.text_dim, 14, 0, 0, 1);
 	}
 	ngui_pop_clip(&ui);
 
 	b.x = body.x;
 	b.y = body.y + body.h - 28;
 	b.w = 110;
-	b.h = 26;
+	b.h = 28;
 	if (ngui_button(&ui, ID_CONN_CANCEL, b,
 			connect_pid > 0 ? "Cancel" : "Back"))
 		actions |= ACT_BACK;
@@ -1123,24 +1124,24 @@ static void draw_saved(void)
 
 	r = ngui_cut_top(&body, 22);
 	ngui_text_px(&ui, r.x, r.y, "Saved Wi-Fi networks", 20,
-		     ui.theme.text, 16, 1, 0, 0);
+		     ui.theme.text, 14, 1, 0, 0);
 
 	if (!nsaved) {
-		ngui_text_px(&ui, body.x + 2, body.y + 4,
-			     "No saved networks", 17,
-			     ui.theme.text_dim, 11, 0, 0, 0);
+		ngui_text(&ui, body.x + 2, body.y + 4,
+			  "No saved networks", ui.theme.text_dim);
 	} else {
 		list = body;
 		list.h -= 38;
-		saved_scroll.content_h = nsaved * 40;
+		saved_scroll.content_h = nsaved * SAVED_LIST_ROW_H;
 		ngui_scroll_begin(&ui, list, &saved_scroll);
 		ngui_scroll_wheel(&ui, list, &saved_scroll);
 		ngui_scroll_keys(&ui, &saved_scroll);
 		for (i = 0; i < nsaved; i++) {
 			row.x = list.x;
-			row.y = list.y - saved_scroll.offset + i * 40;
+			row.y = list.y - saved_scroll.offset +
+				i * SAVED_LIST_ROW_H;
 			row.w = list.w - 16;
-			row.h = 38;
+			row.h = SAVED_LIST_ROW_H;
 			if (row.y + row.h <= list.y ||
 			    row.y >= list.y + list.h)
 				continue;
@@ -1149,7 +1150,7 @@ static void draw_saved(void)
 			bt.x = row.x + row.w - 64;
 			bt.w = 60;
 			bt.h = 28;
-			bt.y = row.y + 5;
+			bt.y = row.y + 7;
 			row.w -= 76;
 
 			desc.title = ssid;
@@ -1172,7 +1173,7 @@ static void draw_saved(void)
 	back.x = body.x;
 	back.y = body.y + body.h - 28;
 	back.w = 100;
-	back.h = 26;
+	back.h = 28;
 	if (ngui_button(&ui, ID_SAVED_BACK, back, "Back"))
 		actions |= ACT_BACK;
 }