Jelajahi Sumber

Add gallery button and fix scrollbar dragging

Johannes Zellner 2 minggu lalu
induk
melakukan
c90950ca63
4 mengubah file dengan 40 tambahan dan 5 penghapusan
  1. 1 0
      browser.c
  2. 27 3
      ngui.c
  3. 8 2
      ucmd_wm.c
  4. 4 0
      wm_abi.h

+ 1 - 0
browser.c

@@ -3117,6 +3117,7 @@ static void draw_page(struct ngui_rect page)
 	page_rect = page;
 	if (page_backbuf && pagebuf_w == ui.w && pagebuf_h == ui.h &&
 	    page_cache_valid && layout_valid &&
+	    !ui.pressed && !(ui.buttons & 1) && !ui.released &&
 	    page_scroll.offset == page_cache_scroll &&
 	    page_cache_nnode == doc.nnode &&
 	    page_cache_x == page.x && page_cache_y == page.y &&

+ 27 - 3
ngui.c

@@ -1157,7 +1157,7 @@ void ngui_scroll_begin(struct ngui *ui, struct ngui_rect r,
 		int th = scroll_thumb_h(&r, s);
 		int ty = scroll_thumb_y(&r, s);
 
-		bar = rect_make(r.x + r.w - 9, r.y, 8, r.h);
+		bar = rect_make(r.x + r.w - 15, r.y, 14, r.h);
 		if (ui->pressed &&
 		    ngui_rect_contains(&bar, ui->press_x, ui->press_y)) {
 			if (ui->press_y >= ty && ui->press_y < ty + th) {
@@ -1179,6 +1179,30 @@ void ngui_scroll_begin(struct ngui *ui, struct ngui_rect r,
 				scroll_clamp(s);
 			}
 		}
+		/* Sampled buttons are authoritative while held: some event paths
+		 * deliver the press late or coalesce it with the release.  Start
+		 * the drag from the current pointer position as well. */
+		if (!s->dragging && (ui->buttons & 1) &&
+		    ngui_rect_contains(&bar, ui->mouse_x, ui->mouse_y)) {
+			if (ui->mouse_y >= ty && ui->mouse_y < ty + th) {
+				s->dragging = 1;
+				s->drag_dy = ui->mouse_y - ty;
+			} else {
+				int rel = ui->mouse_y - r.y - th / 2;
+				int avail = r.h - th;
+				int max = s->content_h - s->view_h;
+
+				if (rel < 0)
+					rel = 0;
+				if (rel > avail)
+					rel = avail;
+				if (avail > 0)
+					s->offset = rel * max / avail;
+				s->dragging = 1;
+				s->drag_dy = th / 2;
+				scroll_clamp(s);
+			}
+		}
 		if (s->dragging && (ui->buttons & 1)) {
 			int rel = ui->mouse_y - r.y - s->drag_dy;
 			int avail = r.h - th;
@@ -1205,10 +1229,10 @@ void ngui_scroll_end(struct ngui *ui, struct ngui_rect r,
 	if (!scrollable(s))
 		return;
 	{
-		struct ngui_rect bar = rect_make(r.x + r.w - 9, r.y, 8, r.h);
+		struct ngui_rect bar = rect_make(r.x + r.w - 15, r.y, 14, r.h);
 		int th = scroll_thumb_h(&r, s);
 		int ty = scroll_thumb_y(&r, s);
-		struct ngui_rect thumb = rect_make(bar.x, ty, 8, th);
+		struct ngui_rect thumb = rect_make(bar.x, ty, 14, th);
 
 		ngui_fill_rect(ui, bar, ui->theme.panel_alt);
 		ngui_fill_rect(ui, thumb, s->dragging ?

+ 8 - 2
ucmd_wm.c

@@ -139,9 +139,11 @@ static void draw_bar(void)
 		   WM_BTN_WEB_H, "Web");
 	bar_button(WM_BTN_CARDS_X, WM_BTN_CARDS_Y, WM_BTN_CARDS_W,
 		   WM_BTN_CARDS_H, "Cards");
+	bar_button(WM_BTN_GALLERY_X, WM_BTN_GALLERY_Y, WM_BTN_GALLERY_W,
+		   WM_BTN_GALLERY_H, "Gallery");
 	if (bar_msg_until &&
 	    (int)(u_ticks_ms() - bar_msg_until) < 0)
-		usurf_text(&screen, (int)(WM_BTN_CARDS_X + WM_BTN_CARDS_W + 8),
+		usurf_text(&screen, (int)(WM_BTN_GALLERY_X + WM_BTN_GALLERY_W + 8),
 			   5, bar_msg, 0xFFD250u, 0, 0, fbw, WM_BAR_H);
 
 	/* Rainbow separator (same y as the kernel's old bar). */
@@ -196,7 +198,7 @@ static void draw_bar(void)
 			int tx = (int)fbw - 4 - (int)clock_chars * 8 -
 				 (clock_chars ? 8 : 0) - (int)tn * 8;
 
-			if (tx >= WM_BTN_CARDS_X + (int)WM_BTN_CARDS_W + 4)
+			if (tx >= WM_BTN_GALLERY_X + (int)WM_BTN_GALLERY_W + 4)
 				usurf_text(&screen, tx, 5, tb,
 					   temp_color(bar_temp_c), 0, 0,
 					   fbw, WM_BAR_H);
@@ -602,6 +604,10 @@ static void handle_mouse(struct wm_status *st)
 			   mx < WM_BTN_CARDS_X + WM_BTN_CARDS_W &&
 			   my < WM_BTN_CARDS_Y + WM_BTN_CARDS_H) {
 			spawn_app_checked("/ramfs/bin/solitaire");
+		} else if (mx >= WM_BTN_GALLERY_X && my >= WM_BTN_GALLERY_Y &&
+			   mx < WM_BTN_GALLERY_X + WM_BTN_GALLERY_W &&
+			   my < WM_BTN_GALLERY_Y + WM_BTN_GALLERY_H) {
+			spawn_app_checked("/ramfs/bin/gallery");
 		} else {
 			int idx = window_at(mx, my);
 

+ 4 - 0
wm_abi.h

@@ -38,6 +38,10 @@
 #define WM_BTN_CARDS_Y WM_BTN_Y
 #define WM_BTN_CARDS_W 56
 #define WM_BTN_CARDS_H WM_BTN_H
+#define WM_BTN_GALLERY_X (WM_BTN_CARDS_X + WM_BTN_CARDS_W + WM_BTN_GAP)
+#define WM_BTN_GALLERY_Y WM_BTN_Y
+#define WM_BTN_GALLERY_W 72
+#define WM_BTN_GALLERY_H WM_BTN_H
 #define WM_TITLE_H 22
 #define WM_CLOSE_W 16