Sfoglia il codice sorgente

disks: keep scroll pane content clear of the scrollbar

ngui paints the scrollbar over the right edge of a scroll pane, so the
device list and the details page drew rows and buttons underneath it.
Narrow the content while a pane scrolls, and redraw once when the details
page starts or stops needing the bar (its height is measured while
drawing).

Co-Authored-By: Claude <noreply@anthropic.com>
Johannes Zellner 3 giorni fa
parent
commit
312f63a340
1 ha cambiato i file con 28 aggiunte e 8 eliminazioni
  1. 28 8
      user/apps/disks/ucmd_disks.c

+ 28 - 8
user/apps/disks/ucmd_disks.c

@@ -609,6 +609,18 @@ static void draw_toolbar(struct ngui_rect r)
 	}
 	}
 }
 }
 
 
+/* ngui's scroll pane paints its bar over the right edge of the pane, so the
+ * content must leave that strip free while the pane scrolls. */
+#define SCROLLBAR_ROOM 20
+
+static struct ngui_rect scroll_content(struct ngui_rect area,
+				       const struct ngui_scroll *s)
+{
+	if (!s->hide_bar && s->content_h > s->view_h)
+		area.w -= SCROLLBAR_ROOM;
+	return area;
+}
+
 /* Empty IDE channels and absent eMMC/USB slots are registered as devices
 /* Empty IDE channels and absent eMMC/USB slots are registered as devices
  * but have nothing to show; a floppy drive is listed without media too. */
  * but have nothing to show; a floppy drive is listed without media too. */
 static int listed(const struct disk *d)
 static int listed(const struct disk *d)
@@ -619,7 +631,7 @@ static int listed(const struct disk *d)
 static void draw_device_list(struct ngui_rect area)
 static void draw_device_list(struct ngui_rect area)
 {
 {
 	struct ngui_row row;
 	struct ngui_row row;
-	struct ngui_rect r;
+	struct ngui_rect r, col;
 	char sub[64], size[16];
 	char sub[64], size[16];
 	int i, y;
 	int i, y;
 
 
@@ -630,12 +642,13 @@ static void draw_device_list(struct ngui_rect area)
 	list_scroll.content_h = (y + 1) * ROW_H + 2 * SECTION_H;
 	list_scroll.content_h = (y + 1) * ROW_H + 2 * SECTION_H;
 	ngui_scroll_begin(&ui, area, &list_scroll);
 	ngui_scroll_begin(&ui, area, &list_scroll);
 	ngui_scroll_wheel(&ui, area, &list_scroll);
 	ngui_scroll_wheel(&ui, area, &list_scroll);
+	col = scroll_content(area, &list_scroll);
 	y = area.y - list_scroll.offset;
 	y = area.y - list_scroll.offset;
 
 
-	r = (struct ngui_rect){ area.x, y, area.w, SECTION_H };
+	r = (struct ngui_rect){ col.x, y, col.w, SECTION_H };
 	ngui_section(&ui, r, "Overview", 0, 0);
 	ngui_section(&ui, r, "Overview", 0, 0);
 	y += SECTION_H;
 	y += SECTION_H;
-	r = (struct ngui_rect){ area.x, y, area.w, ROW_H };
+	r = (struct ngui_rect){ col.x, y, col.w, ROW_H };
 	if (visible(r, area)) {
 	if (visible(r, area)) {
 		snprintf(sub, sizeof(sub), "%d filesystem%s", nmounts,
 		snprintf(sub, sizeof(sub), "%d filesystem%s", nmounts,
 			 nmounts == 1 ? "" : "s");
 			 nmounts == 1 ? "" : "s");
@@ -652,7 +665,7 @@ static void draw_device_list(struct ngui_rect area)
 	}
 	}
 	y += ROW_H;
 	y += ROW_H;
 
 
-	r = (struct ngui_rect){ area.x, y, area.w, SECTION_H };
+	r = (struct ngui_rect){ col.x, y, col.w, SECTION_H };
 	ngui_section(&ui, r, "Devices", 0, 0);
 	ngui_section(&ui, r, "Devices", 0, 0);
 	y += SECTION_H;
 	y += SECTION_H;
 	for (i = 0; i < ndisks; i++) {
 	for (i = 0; i < ndisks; i++) {
@@ -660,7 +673,7 @@ static void draw_device_list(struct ngui_rect area)
 
 
 		if (!listed(d))
 		if (!listed(d))
 			continue;
 			continue;
-		r = (struct ngui_rect){ area.x, y, area.w, ROW_H };
+		r = (struct ngui_rect){ col.x, y, col.w, ROW_H };
 		y += ROW_H;
 		y += ROW_H;
 		if (!visible(r, area))
 		if (!visible(r, area))
 			continue;
 			continue;
@@ -985,20 +998,27 @@ static int draw_disk(struct ngui_rect area, int y, struct disk *d)
 
 
 static void draw_details(struct ngui_rect area)
 static void draw_details(struct ngui_rect area)
 {
 {
-	int y, top;
+	struct ngui_rect col;
+	int y, top, had_bar;
 
 
 	ngui_inset(&area, 14);
 	ngui_inset(&area, 14);
 	ngui_scroll_begin(&ui, area, &detail_scroll);
 	ngui_scroll_begin(&ui, area, &detail_scroll);
 	ngui_scroll_wheel(&ui, area, &detail_scroll);
 	ngui_scroll_wheel(&ui, area, &detail_scroll);
 	if (!ui.focus)
 	if (!ui.focus)
 		ngui_scroll_keys(&ui, &detail_scroll);
 		ngui_scroll_keys(&ui, &detail_scroll);
+	/* The height is only known after drawing, so the bar decision uses
+	 * the previous frame's; redraw once when it flips. */
+	col = scroll_content(area, &detail_scroll);
+	had_bar = col.w != area.w;
 	top = area.y - detail_scroll.offset;
 	top = area.y - detail_scroll.offset;
 	if (sel_disk < 0)
 	if (sel_disk < 0)
-		y = draw_overview(area, top);
+		y = draw_overview(col, top);
 	else
 	else
-		y = draw_disk(area, top, &disks[sel_disk]);
+		y = draw_disk(col, top, &disks[sel_disk]);
 	detail_scroll.content_h = y - top;
 	detail_scroll.content_h = y - top;
 	ngui_scroll_end(&ui, area, &detail_scroll);
 	ngui_scroll_end(&ui, area, &detail_scroll);
+	if (had_bar != (scroll_content(area, &detail_scroll).w != area.w))
+		ngui_invalidate(&ui);
 }
 }
 
 
 /* ---- dialogs ---- */
 /* ---- dialogs ---- */