From bb978fd6de70393d5ff76bb7184c363ca175be56 Mon Sep 17 00:00:00 2001 From: Sprite Date: Mon, 23 Nov 2026 05:29:33 +0000 Subject: [PATCH] Fix widget resizing handles, edge anchoring, scroll sync, and axis limits --- .sweet/jade-autumn-bear.md | 2 +- .../java/dev/ultra/launcher/HomeActivity.java | 28 ++- app/model.mbt | 15 +- app/pkg.generated.mbti | 12 +- app/sim_wbtest.mbt | 186 +++++++++++++++++- app/update.mbt | 137 +++++++++---- app/view.mbt | 33 +++- grid/grid_wbtest.mbt | 13 ++ tests/android-sim.cjs | 102 +++++++++- tests/e2e.cjs | 17 +- web/ffi.mbt | 2 +- web/main.mbt | 33 +++- web/style.css | 34 ++-- 13 files changed, 538 insertions(+), 76 deletions(-) diff --git a/.sweet/jade-autumn-bear.md b/.sweet/jade-autumn-bear.md index 444d59d..d083478 100644 --- a/.sweet/jade-autumn-bear.md +++ b/.sweet/jade-autumn-bear.md @@ -2,4 +2,4 @@ type: fix --- -Show the Android system wallpaper behind the transparent WebView, add an in-app setup guide for Android 13+ "Restricted setting" on the Windows button, and smooth out app drawer animations with keyed overlays, GPU-composited open/close transitions, delayed IME focus, and pre-warmed app icons. +Show the Android system wallpaper behind the transparent WebView, add an in-app setup guide for Android 13+ "Restricted setting" on the Windows button, smooth out app drawer animations with keyed overlays, GPU-composited transitions, delayed IME focus, and pre-warmed app icons, and fix widget resizing across all four edges with edge touch passthrough, scroll-synced coordinates, and axis-conditional handles. diff --git a/android/java/dev/ultra/launcher/HomeActivity.java b/android/java/dev/ultra/launcher/HomeActivity.java index 09d4805..effc2e8 100644 --- a/android/java/dev/ultra/launcher/HomeActivity.java +++ b/android/java/dev/ultra/launcher/HomeActivity.java @@ -105,6 +105,7 @@ public class HomeActivity extends Activity { private final Map widgetSizes = new HashMap<>(); // last size told to each widget private int pendingWidget = -1; private int editingWidget = -1; // showing resize handles: a press on it moves it + private int editingResizeMode; // RESIZE_HORIZONTAL | RESIZE_VERTICAL for editingWidget private boolean ready; private int insetTop, insetBottom; // CSS px private LauncherApps launcher; @@ -570,6 +571,14 @@ public class HomeActivity extends Activity { return; } editingWidget = editing; + if (editing != -1) { + AppWidgetProviderInfo editInfo = widgets.getAppWidgetInfo(editing); + editingResizeMode = editInfo != null + ? editInfo.resizeMode + : (AppWidgetProviderInfo.RESIZE_HORIZONTAL | AppWidgetProviderInfo.RESIZE_VERTICAL); + } else { + editingResizeMode = 0; + } for (Map.Entry e : widgetViews.entrySet()) { if (!want.containsKey(e.getKey())) e.getValue().setVisibility(View.GONE); } @@ -590,7 +599,7 @@ public class HomeActivity extends Activity { v.setLayoutParams(lp); v.setVisibility(View.VISIBLE); // Scrolling moves a widget without resizing it; only tell it about new sizes. - long size = ((long) r[4] << 32) | r[5]; + long size = ((long) r[4] << 32) | (r[5] & 0xffffffffL); Long was = widgetSizes.put(id, size); if (was == null || was != size) { if (Build.VERSION.SDK_INT >= 31) { @@ -674,6 +683,23 @@ public class HomeActivity extends Activity { super.setPadding(0, 0, 0, 0); } + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + if (home.editingWidget == id && ev.getActionMasked() == MotionEvent.ACTION_DOWN) { + int mode = home.editingResizeMode; + boolean canH = (mode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0; + boolean canV = (mode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0; + float d = getResources().getDisplayMetrics().density; + float insetX = Math.min(18f * d, getWidth() * 0.3f); + float insetY = Math.min(18f * d, getHeight() * 0.3f); + float x = ev.getX(), y = ev.getY(); + boolean nearH = canH && (x < insetX || x > getWidth() - insetX); + boolean nearV = canV && (y < insetY || y > getHeight() - insetY); + if (nearH || nearV) return false; + } + return super.dispatchTouchEvent(ev); + } + @Override public boolean onInterceptTouchEvent(MotionEvent e) { switch (e.getActionMasked()) { diff --git a/app/model.mbt b/app/model.mbt index 3482d15..357d770 100644 --- a/app/model.mbt +++ b/app/model.mbt @@ -66,19 +66,29 @@ pub(all) enum Sheet { ///| #derive(Eq, Debug) pub(all) enum Edge { + Left Right + Top Bottom Corner } ///| -/// A resize in progress: a handle was pressed on the widget whose box (px, viewport) was -/// at `left`, `top`. +/// A resize in progress: a handle was pressed on the widget whose viewport box and +/// grid edges were captured on down. pub(all) struct ResizeDrag { edge : Edge slot : Int32 left : Double top : Double + right : Double + bottom : Double + anchor_col : Int32 + anchor_row : Int32 + right_col : Int32 + bottom_row : Int32 + mut col : Int32 + mut row : Int32 mut cols : Int32 mut rows : Int32 } @@ -227,6 +237,7 @@ pub(all) enum Msg { grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double, + scroll_y~ : Double, ) AppsLoaded(String?) WidgetsLoaded(String?) diff --git a/app/pkg.generated.mbti b/app/pkg.generated.mbti index b980c7a..ccc68f8 100644 --- a/app/pkg.generated.mbti +++ b/app/pkg.generated.mbti @@ -60,7 +60,9 @@ pub(all) struct Carry { #derive(Eq, @debug.Debug) pub(all) enum Edge { + Left Right + Top Bottom Corner } @@ -166,7 +168,7 @@ pub fn Model::widget_matches(Self, Int32) -> Bool pub(all) enum Msg { Restore(saved~ : String?, legacy~ : String?) Started(now~ : Int64, last_check~ : Int64, declined~ : Int32, installed~ : Int32) - Measured(vw~ : Int32, vh~ : Int32, grid_left~ : Double, grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double) + Measured(vw~ : Int32, vh~ : Int32, grid_left~ : Double, grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double, scroll_y~ : Double) AppsLoaded(String?) WidgetsLoaded(String?) LimitsKnown(Int32, String?) @@ -227,6 +229,14 @@ pub(all) struct ResizeDrag { slot : Int32 left : Double top : Double + right : Double + bottom : Double + anchor_col : Int32 + anchor_row : Int32 + right_col : Int32 + bottom_row : Int32 + mut col : Int32 + mut row : Int32 mut cols : Int32 mut rows : Int32 } diff --git a/app/sim_wbtest.mbt b/app/sim_wbtest.mbt index f10ded8..fa272b1 100644 --- a/app/sim_wbtest.mbt +++ b/app/sim_wbtest.mbt @@ -42,6 +42,7 @@ fn Sim::new() -> Sim { grid_top=150.0, grid_w=358.0, bottom_pad=24.0, + scroll_y=0.0, ), ) s.send(AppsLoaded(Some(apps_json))) @@ -600,8 +601,10 @@ test "a widget: hold opens resize handles; drag the handles; Done" { s.long_press(s.chain("widget-slot"), x=wx, y=wy) assert_eq(s.m.resizing, 0) // no item menu for a widget: handles assert_eq(s.m.sheet, NoSheet) + assert_true(s.has_effect(QueryLimits(100))) // queried immediately on entering resize mode let html = @vdom.to_html(s.tree[0]) assert_true(html.contains("resize-handle")) + assert_true(@vdom.to_html(s.tree[1]).contains("5 × 2")) assert_true( @vdom.to_html(s.tree[1]).contains( "Drag to move, or drag the handles to resize", @@ -612,10 +615,10 @@ test "a widget: hold opens resize handles; drag the handles; Done" { .chain_where(fn(e) { e.attrs.contains(("data-edge", "b")) }) .unwrap() s.press(hc, x=100.0, y=150.0 + 2.0 * 72.0 + 70.0) - assert_true(s.has_effect(QueryLimits(100))) s.move_to(100.0, 150.0 + 3.0 * 72.0 + 40.0) s.release() assert_eq(s.m.home[0].rows, 4) + assert_true(@vdom.to_html(s.tree[1]).contains("5 × 4")) assert_eq(s.m.resizing, 0) // handles stay // the right handle to three columns (the widget starts the full row) let rc = s @@ -626,6 +629,7 @@ test "a widget: hold opens resize handles; drag the handles; Done" { s.move_to(c3x + 36.0, 170.0) s.release() assert_eq(s.m.home[0].w, 3) + assert_true(@vdom.to_html(s.tree[1]).contains("3 × 4")) // pressing the widget's body picks it up at once; letting go keeps the handles let wc = s.chain("widget-slot") s.press(wc, x=wx, y=wy) @@ -656,10 +660,19 @@ test "resizing stays within the widget's limits" { ) let (wx, wy) = cell_center(2, 0) s.long_press(s.chain("widget-slot"), x=wx, y=wy) + let html = @vdom.to_html(s.tree[0]) + assert_true( + html.contains("data-edge=\"l\"") && html.contains("data-edge=\"r\""), + ) + assert_true( + !html.contains("data-edge=\"t\"") && + !html.contains("data-edge=\"b\"") && + !html.contains("data-edge=\"rb\""), + ) let rc = s - .chain_where(fn(e) { e.attrs.contains(("data-edge", "rb")) }) + .chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) }) .unwrap() - s.press(rc, x=370.0, y=250.0) + s.press(rc, x=370.0, y=200.0) s.move_to(60.0, 600.0) // far left and down s.release() assert_eq(s.m.home[0].w, 3) // 3 columns = 204px, the nearest to 200 within the limit @@ -990,3 +1003,170 @@ test "top-level view nodes have distinct non-zero keys" { } assert_eq(keys, [1, 2, 3, 4, 6]) } + +///| +test "left/right/top/bottom resize anchors opposite edge and pins unpinned widget" { + let s = Sim::new() + s.add_apps(["Chrome", "Gmail", "Phone"]) + s.send(PickWidget) + s.send(WidgetsLoaded(Some(widgets_json))) + s.send(ChooseWidget(0)) + s.send(WidgetAdded(100)) + s.send( + LimitsKnown( + 100, + Some("{\"w\":130,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"), + ), + ) + // Unpinned 2x2 widget starts at (3, 0) beside the 3 apps; resizing Right pins it at (3, 0) + // and widening past the right edge caps at 5 - 3 = 2 columns without shifting x or jumping rows + assert_eq((s.m.home[3].x, s.m.home[3].y, s.m.home[3].w), (-1, -1, 2)) + let (wx, wy) = cell_center(3, 0) + s.long_press(s.chain("widget-slot"), x=wx, y=wy) + let rc = s + .chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) }) + .unwrap() + s.press(rc, x=374.0, y=200.0) + s.move_to(520.0, 200.0) + s.release() + assert_eq((s.m.home[3].x, s.m.home[3].y, s.m.home[3].w), (3, 0, 2)) + + // Place widget at (2, 2) and test Left + Top handles keeping right/bottom anchored + s.m.home[3].x = 2 + s.m.home[3].y = 2 + s.m.home[3].w = 2 + s.m.home[3].rows = 2 + s.refresh() + let lc = s + .chain_where(fn(e) { e.attrs.contains(("data-edge", "l")) }) + .unwrap() + let (c1x, c2y) = cell_center(1, 2) + s.press(lc, x=c1x + 40.0, y=c2y) + s.move_to(c1x - 32.0, c2y) // grow left by 1 col -> (1, 2), w=3 (right_col stays 4) + assert_eq((s.m.home[3].x, s.m.home[3].w), (1, 3)) + s.move_to(-100.0, c2y) // clamp at col 0 -> (0, 2), w=4 (right_col stays 4) + assert_eq((s.m.home[3].x, s.m.home[3].w), (0, 4)) + let (c2x, _) = cell_center(2, 2) + s.move_to(c2x + 40.0, c2y) // shrink back to 1 col -> (3, 2), w=1 (right_col stays 4) + s.release() + assert_eq((s.m.home[3].x, s.m.home[3].w), (3, 1)) + + let tc = s + .chain_where(fn(e) { e.attrs.contains(("data-edge", "t")) }) + .unwrap() + let (c3x, c1y) = cell_center(3, 1) + s.press(tc, x=c3x, y=150.0 + 2.0 * 72.0) + s.move_to(c3x, c1y - 24.0) // grow up by 1 row -> row 1, rows=3 (bottom_row stays 4) + assert_eq((s.m.home[3].y, s.m.home[3].rows), (1, 3)) + s.move_to(c3x, -50.0) // clamp at row 0 -> row 0, rows=4 (bottom_row stays 4) + assert_eq((s.m.home[3].y, s.m.home[3].rows), (0, 4)) + let (_, c3y) = cell_center(3, 3) + s.move_to(c3x, c3y - 24.0) // shrink down to 1 row -> row 3, rows=1 (bottom_row stays 4) + s.release() + assert_eq((s.m.home[3].y, s.m.home[3].rows), (3, 1)) +} + +///| +test "holding a resize handle for 500ms does not lift widget or corrupt resize state" { + let s = Sim::new() + s.send(PickWidget) + s.send(WidgetsLoaded(Some(widgets_json))) + s.send(ChooseWidget(0)) + s.send(WidgetAdded(100)) + s.send( + LimitsKnown( + 100, + Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"), + ), + ) + let (wx, wy) = cell_center(2, 0) + s.long_press(s.chain("widget-slot"), x=wx, y=wy) + let rc = s + .chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) }) + .unwrap() + s.press(rc, x=370.0, y=170.0) + s.hold() + assert_eq(s.m.resizing, 0) + assert_eq(s.m.lifted, -1) + assert_true(s.m.resize is Some(_)) + let (c2x, _) = cell_center(1, 0) + s.move_to(c2x + 36.0, 170.0) + s.release() + assert_eq(s.m.home[0].w, 2) + assert_eq(s.m.resizing, 0) + assert_eq(s.m.lifted, -1) + assert_eq(s.m.sheet, NoSheet) +} + +///| +test "scrolled Measured keeps nrows constant and resizes in viewport coordinates" { + let s = Sim::new() + s.send(PickWidget) + s.send(WidgetsLoaded(Some(widgets_json))) + s.send(ChooseWidget(0)) + s.send(WidgetAdded(100)) + s.send( + LimitsKnown( + 100, + Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"), + ), + ) + let unscrolled_rows = s.m.nrows + // Scrolled down 200px: grid_top in viewport moved from 150 to -50 + s.send( + Measured( + vw=390, + vh=800, + grid_left=16.0, + grid_top=-50.0, + grid_w=358.0, + bottom_pad=24.0, + scroll_y=200.0, + ), + ) + assert_eq(s.m.nrows, unscrolled_rows) + let (wx, wy) = cell_center(2, 0) + s.long_press(s.chain("widget-slot"), x=wx, y=wy - 200.0) + let bc = s + .chain_where(fn(e) { e.attrs.contains(("data-edge", "b")) }) + .unwrap() + s.press(bc, x=100.0, y=-50.0 + 2.0 * 72.0) + s.move_to(100.0, -50.0 + 3.0 * 72.0 - 8.0) // 3 rows in scrolled viewport coords + s.release() + assert_eq(s.m.home[0].rows, 3) +} + +///| +test "only supported resize handles render per widget resizeMode" { + let s = Sim::new() + s.send(PickWidget) + s.send(WidgetsLoaded(Some(widgets_json))) + s.send(ChooseWidget(0)) + s.send(WidgetAdded(100)) + s.send( + LimitsKnown( + 100, + Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":false,\"v\":true}"), + ), + ) + let (wx, wy) = cell_center(2, 0) + s.long_press(s.chain("widget-slot"), x=wx, y=wy) + let v_only = @vdom.to_html(s.tree[0]) + assert_true( + v_only.contains("data-edge=\"t\"") && v_only.contains("data-edge=\"b\""), + ) + assert_true( + !v_only.contains("data-edge=\"l\"") && + !v_only.contains("data-edge=\"r\"") && + !v_only.contains("data-edge=\"rb\""), + ) + s.send( + LimitsKnown( + 100, + Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":false,\"v\":false}"), + ), + ) + s.refresh() + let none_html = @vdom.to_html(s.tree[0]) + assert_true(!none_html.contains("resize-handle")) +} diff --git a/app/update.mbt b/app/update.mbt index f507aef..c7ddd90 100644 --- a/app/update.mbt +++ b/app/update.mbt @@ -348,7 +348,7 @@ fn Model::drag_lifted( /// The pointer is up. Letting go without moving opens the item's menu (a widget gets /// resize handles instead); letting go of a dragged one just drops it, and whatever it /// then covers moves on to free cells. -fn Model::drop_lifted(self : Model, moved : Bool) -> Unit { +fn Model::drop_lifted(self : Model, moved : Bool, fx : Array[Effect]) -> Unit { self.carry = None if self.lifted < 0 || self.lifted >= self.home.length() { self.lifted = -1 @@ -361,7 +361,10 @@ fn Model::drop_lifted(self : Model, moved : Bool) -> Unit { } if !moved || self.regrab { match s.kind { - Widget => self.resizing = self.lifted + Widget => { + self.resizing = self.lifted + fx.push(QueryLimits(s.wid)) + } App => self.sheet = Item(self.lifted) } } @@ -376,23 +379,34 @@ fn Model::begin_resize(self : Model, edge : Edge, fx : Array[Effect]) -> Unit { return } let s = self.home[i] - let (left, top) = match self.slot_box(self.packed(), i) { - Some(b) => (b.0, b.1) - None => (self.grid_left, self.grid_top) - } + guard self.packed().cells[i] is Some(cell) else { return } + s.x = cell.col + s.y = cell.row + let (bx, by, bw, bh) = @grid.box(cell, self.col_w) + let left = self.grid_left + bx + let top = self.grid_top + by self.resize = Some({ edge, slot: i, left, top, - cols: s.cols(self.cols), - rows: s.height(), + right: left + bw, + bottom: top + bh, + anchor_col: cell.col, + anchor_row: cell.row, + right_col: cell.col + cell.w, + bottom_row: cell.row + cell.h, + col: cell.col, + row: cell.row, + cols: cell.w, + rows: cell.h, }) fx.push(QueryLimits(s.wid)) } ///| -/// Dragging a handle snaps the widget to whole columns and rows, within its limits. +/// Dragging a handle snaps the widget to whole columns and rows, within its limits +/// and without shifting its anchored edge. fn Model::drag_resize( self : Model, r : ResizeDrag, @@ -406,42 +420,86 @@ fn Model::drag_resize( let s = self.home[r.slot] let lim = self.limits.get(s.wid).unwrap_or(default_limits) let n = self.cols + let mut col = r.col + let mut row = r.row let mut cols = r.cols let mut rows = r.rows - if r.edge != Bottom && lim.h { - cols = @grid.fit( - x - r.left, - 1, - n, - self.col_w, - @grid.col_gap.to_double(), - lim.min_w, - lim.max_w, - ) + let cg = @grid.col_gap.to_double() + let rg = @grid.row_gap.to_double() + if lim.h { + match r.edge { + Right | Corner => { + let hi = @cmp.maximum(1, n - r.anchor_col) + cols = @grid.fit( + x - r.left, + 1, + hi, + self.col_w, + cg, + lim.min_w, + lim.max_w, + ) + col = r.anchor_col + } + Left => { + let hi = @cmp.maximum(1, @cmp.minimum(n, r.right_col)) + cols = @grid.fit( + r.right - x, + 1, + hi, + self.col_w, + cg, + lim.min_w, + lim.max_w, + ) + col = r.right_col - cols + } + Top | Bottom => () + } } - if r.edge != Right && lim.v { - rows = @grid.fit( - y - r.top, - 1, - 20, - @grid.cell_px.to_double(), - @grid.row_gap.to_double(), - lim.min_h, - lim.max_h, - ) + if lim.v { + match r.edge { + Bottom | Corner => { + rows = @grid.fit( + y - r.top, + 1, + 20, + @grid.cell_px.to_double(), + rg, + lim.min_h, + lim.max_h, + ) + row = r.anchor_row + } + Top => { + let hi = @cmp.maximum(1, @cmp.minimum(20, r.bottom_row)) + rows = @grid.fit( + r.bottom - y, + 1, + hi, + @grid.cell_px.to_double(), + rg, + lim.min_h, + lim.max_h, + ) + row = r.bottom_row - rows + } + Left | Right => () + } } - if cols == r.cols && rows == r.rows { + if col == r.col && row == r.row && cols == r.cols && rows == r.rows { return } + r.col = col + r.row = row r.cols = cols r.rows = rows fx.push(Haptic) + s.x = col + s.y = row s.w = if cols >= n { 0 } else { cols } s.rows = rows - if s.x >= 0 { - @grid.pin(self.home, r.slot, s.x, s.y, self.cols, self.nrows) - @grid.clear_cells(self.home, r.slot, self.cols) - } + @grid.clear_cells(self.home, r.slot, self.cols) } // ---- update ------------------------------------------------------------------- @@ -504,12 +562,14 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit { fx.push(FetchRelease(@updater.release_api)) } } - Measured(vw~, vh~, grid_left~, grid_top~, grid_w~, bottom_pad~) => { + Measured(vw~, vh~, grid_left~, grid_top~, grid_w~, bottom_pad~, scroll_y~) => { m.cols = @grid.columns_for(vw) m.grid_left = grid_left m.grid_top = grid_top m.col_w = @grid.column_width(grid_w, m.cols) - m.nrows = @grid.rows_fit(vh.to_double() - bottom_pad - grid_top) + m.nrows = @grid.rows_fit( + vh.to_double() - bottom_pad - (grid_top + scroll_y), + ) } AppsLoaded(text) => { m.loading = false @@ -608,7 +668,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit { } NativeDrop(moved) => { m.native_from = None - m.drop_lifted(moved) + m.drop_lifted(moved, fx) } Touch(dx~, dy~, ms~, home_top~, list_end~) => if !m.dragged && m.lifted < 0 && m.sheet == NoSheet { @@ -789,6 +849,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit { Lift(i) => if !m.drawer_open() && m.sheet == NoSheet && + m.resize is None && i != m.lifted && i < m.home.length() { fx.push(Haptic) @@ -815,7 +876,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit { Released(moved~, held~) => { ignore(held) m.resize = None - m.drop_lifted(moved) + m.drop_lifted(moved, fx) } } } diff --git a/app/view.mbt b/app/view.mbt index 75b3eb6..c33b56d 100644 --- a/app/view.mbt +++ b/app/view.mbt @@ -22,12 +22,17 @@ fn cell_style(c : @grid.Cell) -> String { } ///| -fn handle(edge : String, e : Edge) -> Node[Msg] { +fn handle(edge : String, e : Edge, active : Bool) -> Node[Msg] { el( "span", - classes=["resize-handle"], + classes=["resize-handle", cls_if("active", active)], attrs=[("data-edge", edge), ("aria-hidden", "true")], - handlers={ ..Handlers::none(), down: Some(ResizeBegin(e)), tap: Some(Nop), }, + handlers={ + ..Handlers::none(), + down: Some(ResizeBegin(e)), + tap: Some(Nop), + press: Some(Nop), + }, ) } @@ -53,9 +58,22 @@ fn Model::view_slot( el("span", classes=["widget-label"], children=[text(s.str)]), ] if i == self.resizing { - children.push(handle("r", Right)) - children.push(handle("b", Bottom)) - children.push(handle("rb", Corner)) + let lim = self.limits.get(s.wid).unwrap_or(default_limits) + let active = match self.resize { + Some(r) if r.slot == i => Some(r.edge) + _ => None + } + if lim.h { + children.push(handle("l", Left, active == Some(Left))) + children.push(handle("r", Right, active == Some(Right))) + } + if lim.v { + children.push(handle("t", Top, active == Some(Top))) + children.push(handle("b", Bottom, active == Some(Bottom))) + } + if lim.h && lim.v { + children.push(handle("rb", Corner, active == Some(Corner))) + } } Some( el( @@ -463,7 +481,10 @@ fn Model::view_sheet(self : Model) -> Array[Node[Msg]] { ///| fn Model::view_resize_bar(self : Model) -> Node[Msg] { + let s = self.home[self.resizing] + let size = "\{s.cols(self.cols)} × \{s.height()}" el("div", key=5, classes=["resize-bar"], attrs=[("role", "toolbar")], children=[ + el("span", classes=["resize-size"], children=[text(size)]), el("span", classes=["resize-hint"], children=[ text("Drag to move, or drag the handles to resize"), ]), diff --git a/grid/grid_wbtest.mbt b/grid/grid_wbtest.mbt index 37112e4..4c4e508 100644 --- a/grid/grid_wbtest.mbt +++ b/grid/grid_wbtest.mbt @@ -155,3 +155,16 @@ test "viewport to grid" { assert_eq(rows_fit(500.0), 7) assert_eq(rows_fit(10.0), 1) } + +///| +test "fit clamps anchored spans within lo..hi and negative targets" { + // Widget pinned at col 2 of 5 can only grow to hi = 3 columns on the right + assert_eq(fit(500.0, 1, 3, 65.2, 8.0, 64, 0), 3) + // Negative drag past the left/top edge clamps cleanly to 1 + assert_eq(fit(-120.0, 1, 4, 65.2, 8.0, 0, 0), 1) + // Expanding a widget unpins slots now overlapped by it + let h = [widget(2, 2, x=1, y=1), app(x=3, y=1), app(x=0, y=0)] + h[0].w = 3 + clear_cells(h, 0, 5) + assert_eq((h[1].x, h[1].y, h[2].x, h[2].y), (-1, -1, 0, 0)) +} diff --git a/tests/android-sim.cjs b/tests/android-sim.cjs index a87a38b..16b5711 100644 --- a/tests/android-sim.cjs +++ b/tests/android-sim.cjs @@ -29,6 +29,7 @@ const RELEASE = JSON.stringify({ tag_name: "build-9", assets: [ await p.addInitScript((release) => { window.__calls = []; window.__recentsEnabled = true; + window.__widgetLimits = { w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: true, v: true }; const rec = (n) => (...a) => { window.__calls.push([n, ...a]); }; const disc = "data:image/svg+xml," + encodeURIComponent(""); window.Android = { @@ -36,7 +37,7 @@ const RELEASE = JSON.stringify({ tag_name: "build-9", assets: [ addWidget: (prov) => { rec("addWidget")(prov); setTimeout(() => window.launcher.widgetAdded(77), 0); }, removeWidget: rec("removeWidget"), placeWidgets: rec("placeWidgets"), coverWidgets: rec("coverWidgets"), excludeGestures: rec("excludeGestures"), - widgetLimits: () => JSON.stringify({ w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: true, v: true }), + widgetLimits: () => JSON.stringify(window.__widgetLimits), loadIcons: (json) => { rec("loadIcons")(json); const o = {}; for (const k of JSON.parse(json)) o[k] = disc; setTimeout(() => window.launcher.icons(o), 0); }, haptic: rec("haptic"), showKeyboard: rec("showKeyboard"), hideKeyboard: rec("hideKeyboard"), openSettings: rec("openSettings"), pickWallpaper: rec("pickWallpaper"), @@ -150,13 +151,108 @@ const RELEASE = JSON.stringify({ tag_name: "build-9", assets: [ // and the shell is told to keep its edge swipes off them await p.evaluate(() => { window.launcher.widgetMenu(77); window.launcher.widgetDrop(false); }); await settle(); assert.ok(await p.$(".widget-slot.resizing .resize-handle"), "handles"); - assert.ok(JSON.parse((await calls("excludeGestures")).pop()[1]).length === 3, "three handles excluded from system gestures"); + assert.equal(await p.textContent(".resize-size"), "2 × 2"); + assert.equal(JSON.parse((await calls("excludeGestures")).pop()[1]).length, 5, "five handles excluded from system gestures"); assert.equal(JSON.parse((await calls("placeWidgets")).pop()[1])[0][5], 1, "the shell is told which widget is being edited"); // dragging it from the native view moves it to a cell (widgetDrag reports page px) - await p.evaluate(() => { window.launcher.widgetGrab(77); window.launcher.widgetDrag(200, 300); window.launcher.widgetDrag(200, 420); window.launcher.widgetDrop(true); }); + const tileBox = await p.locator(".slots .tile").first().boundingBox(); + const pitchX = Math.round(tileBox.width + 8); + const pitchY = Math.round(tileBox.height + 8); + await p.evaluate(([dx, dy]) => { + window.launcher.widgetGrab(77); + window.launcher.widgetDrag(150, 200); + window.launcher.widgetDrag(150 + dx, 200 + dy); + window.launcher.widgetDrop(true); + }, [pitchX, 2 * pitchY]); await settle(); const moved = await p.$eval(".widget-slot", (s) => s.style.gridRow); assert.ok(!moved.startsWith("1 "), `moved off the first row: ${moved}`); + + // Left and Top resize handles grow without shifting the anchored right/bottom edges + const b0 = await p.locator(".widget-slot").boundingBox(); + const hl = await p.locator(".resize-handle[data-edge=l]").boundingBox(); + await p.mouse.move(hl.x + hl.width / 2, hl.y + hl.height / 2); + await p.mouse.down(); + await p.mouse.move(hl.x + hl.width / 2 - pitchX, hl.y + hl.height / 2, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + const b1 = await p.locator(".widget-slot").boundingBox(); + assert.ok(Math.abs((b0.x + b0.width) - (b1.x + b1.width)) < 2, "left resize keeps right edge anchored"); + assert.ok(Math.abs((b1.width - b0.width) - pitchX) < 3, `left resize grew by 1 col: ${b1.width - b0.width}`); + assert.equal(await p.textContent(".resize-size"), "3 × 2"); + + const ht = await p.locator(".resize-handle[data-edge=t]").boundingBox(); + await p.mouse.move(ht.x + ht.width / 2, ht.y + ht.height / 2); + await p.mouse.down(); + await p.mouse.move(ht.x + ht.width / 2, ht.y + ht.height / 2 - pitchY, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + const b2 = await p.locator(".widget-slot").boundingBox(); + assert.ok(Math.abs((b1.y + b1.height) - (b2.y + b2.height)) < 2, "top resize keeps bottom edge anchored"); + assert.ok(Math.abs((b2.height - b1.height) - pitchY) < 3, `top resize grew by 1 row: ${b2.height - b1.height}`); + assert.equal(await p.textContent(".resize-size"), "3 × 3"); + + // holding a resize handle >= 500ms does not lift widget or corrupt resize state + const hr = await p.locator(".resize-handle[data-edge=r]").boundingBox(); + await p.mouse.move(hr.x + hr.width / 2, hr.y + hr.height / 2); + await p.mouse.down(); await p.waitForTimeout(600); + await p.mouse.move(hr.x + hr.width / 2 + pitchX, hr.y + hr.height / 2, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + assert.ok(await p.$(".widget-slot.resizing"), "still resizing after 600ms hold"); + assert.ok(!(await p.$(".widget-slot.lifted")), "not lifted after holding handle"); + assert.ok(!(await p.$(".sheet")), "no sheet opened after holding handle"); + assert.equal(await p.textContent(".resize-size"), "4 × 3"); + + // scrolled resize: ensure page scrolls, scroll down, then resize bottom by +1 row + await p.evaluate(() => { + document.querySelector(".home").style.minHeight = "1200px"; + window.scrollTo(0, 120); + }); + await settle(); + assert.ok((await p.evaluate(() => window.scrollY)) > 50, "page scrolled for scrolled resize test"); + const bs0 = await p.locator(".widget-slot").boundingBox(); + const hb = await p.locator(".resize-handle[data-edge=b]").boundingBox(); + await p.mouse.move(hb.x + hb.width / 2, hb.y + hb.height / 2); + await p.mouse.down(); + await p.mouse.move(hb.x + hb.width / 2, hb.y + hb.height / 2 + pitchY, { steps: 6 }); await settle(); + await p.mouse.up(); await settle(); + const bs1 = await p.locator(".widget-slot").boundingBox(); + assert.ok(Math.abs((bs1.height - bs0.height) - pitchY) < 3, `scrolled bottom resize grew by 1 row: ${bs1.height - bs0.height}`); + assert.equal(await p.textContent(".resize-size"), "4 × 4"); + await p.evaluate(() => { + document.querySelector(".home").style.minHeight = ""; + window.scrollTo(0, 0); + }); + await settle(); + + // axis-conditional handles: h-only, v-only, and non-resizable + const edges = () => p.$$eval(".resize-handle", (hs) => hs.map((h) => h.dataset.edge)); + await p.click(".resize-bar >> text=Done"); await settle(); + await p.evaluate(() => { + window.__widgetLimits = { w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: true, v: false }; + window.launcher.widgetMenu(77); window.launcher.widgetDrop(false); + }); + await settle(); + assert.deepEqual(await edges(), ["l", "r"]); + assert.equal(JSON.parse((await calls("excludeGestures")).pop()[1]).length, 2); + + await p.click(".resize-bar >> text=Done"); await settle(); + await p.evaluate(() => { + window.__widgetLimits = { w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: false, v: true }; + window.launcher.widgetMenu(77); window.launcher.widgetDrop(false); + }); + await settle(); + assert.deepEqual(await edges(), ["t", "b"]); + assert.equal(JSON.parse((await calls("excludeGestures")).pop()[1]).length, 2); + + await p.click(".resize-bar >> text=Done"); await settle(); + await p.evaluate(() => { + window.__widgetLimits = { w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: false, v: false }; + window.launcher.widgetMenu(77); window.launcher.widgetDrop(false); + }); + await settle(); + assert.deepEqual(await edges(), []); + assert.equal(JSON.parse((await calls("excludeGestures")).pop()[1]).length, 0); + await p.evaluate(() => { window.__widgetLimits = { w: 110, minW: 64, minH: 64, maxW: 0, maxH: 0, h: true, v: true }; }); + await p.click(".resize-bar >> text=Remove"); await settle(); assert.equal((await calls("removeWidget"))[0][1], 77); diff --git a/tests/e2e.cjs b/tests/e2e.cjs index e019bb7..45f96f3 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -173,8 +173,22 @@ const serve = () => new Promise((resolve) => { // hold a widget without moving: resize handles; drag them to snap it to the grid await longpress(".widget-slot"); assert.ok(!(await p.$(".sheet")), "a widget gets handles, not the menu"); - assert.ok(await p.$(".widget-slot.resizing .resize-handle[data-edge=rb]")); + assert.equal(await p.textContent(".resize-size"), "5 × 2"); + for (const edge of ["l", "r", "t", "b", "rb"]) { + const box = await p.locator(`.resize-handle[data-edge=${edge}]`).boundingBox(); + assert.ok(box, `handle ${edge} rendered`); + assert.ok(box.width >= 36 && box.height >= 36, `handle ${edge} generous target: ${box.width}x${box.height}`); + assert.ok(box.x >= 0 && box.x + box.width <= 390, `handle ${edge} stays inside viewport: [${box.x}, ${box.x + box.width}]`); + } await shot(p, "05-resize-handles"); + // resting a finger >= 500ms on a resize handle must not lift the widget or open a menu + const hr = await p.locator(".resize-handle[data-edge=r]").boundingBox(); + await p.mouse.move(hr.x + hr.width / 2, hr.y + hr.height / 2); + await p.mouse.down(); await p.waitForTimeout(600); + assert.ok(await p.$(".widget-slot.resizing"), "holding handle keeps resize mode"); + assert.ok(!(await p.$(".widget-slot.lifted")), "holding handle does not lift widget"); + assert.ok(!(await p.$(".sheet")), "holding handle does not open sheet"); + await p.mouse.up(); await settle(); const size = () => p.$eval(".widget-slot", (w) => [Math.round(w.getBoundingClientRect().width), Math.round(w.getBoundingClientRect().height)]); const [w0] = await size(); const tile = await p.locator(".slots .tile").first().boundingBox(); @@ -187,6 +201,7 @@ const serve = () => new Promise((resolve) => { const [w1, h1] = await size(); assert.ok(w1 < w0 && Math.abs(w1 - (2 * tile.width + 8)) < 3, `two columns wide: ${w1} (tile ${tile.width})`); assert.equal(h1, 2 * 64 + 8, "snapped to two whole rows of tiles"); + assert.equal(await p.textContent(".resize-size"), "2 × 2"); assert.ok(await p.$(".widget-slot.resizing"), "letting go of a handle keeps the handles"); await p.click(".resize-bar >> text=Done"); await settle(); assert.ok(!(await p.$(".resize-handle"))); diff --git a/web/ffi.mbt b/web/ffi.mbt index 2c04404..048655b 100644 --- a/web/ffi.mbt +++ b/web/ffi.mbt @@ -155,7 +155,7 @@ extern "js" fn fetch_text(url : String, f : (Bool, String) -> Unit) -> Unit = ///| /// Measure the viewport and the home grid (into `window.__m`); false without a grid. extern "js" fn measure() -> Bool = - #|() => { const s = document.querySelector(".slots"), h = document.querySelector(".home"); if (!s || !h) return false; const r = s.getBoundingClientRect(); window.__m = [innerWidth, innerHeight, r.left, r.top, r.width, parseFloat(getComputedStyle(h).paddingBottom) || 0]; return true; } + #|() => { const s = document.querySelector(".slots"), h = document.querySelector(".home"); if (!s || !h) return false; const r = s.getBoundingClientRect(); window.__m = [innerWidth, innerHeight, r.left, r.top, r.width, parseFloat(getComputedStyle(h).paddingBottom) || 0, window.scrollY || 0]; return true; } ///| /// Measurement i: viewport width, height, grid left, top, width, the home's bottom padding. diff --git a/web/main.mbt b/web/main.mbt index a472072..2aea1fc 100644 --- a/web/main.mbt +++ b/web/main.mbt @@ -214,11 +214,10 @@ fn render() -> Unit { } ///| -fn after_render() -> Unit { +fn sync_measure() -> Unit { let st = state.val - fill_icons() if measure() { - let key = "\{measured(0)},\{measured(1)},\{measured(2)},\{measured(3)},\{measured(4)},\{measured(5)}" + let key = "\{measured(0)},\{measured(1)},\{measured(2)},\{measured(3)},\{measured(4)},\{measured(5)},\{measured(6)}" if key != st.measured { st.measured = key dispatch( @@ -229,10 +228,18 @@ fn after_render() -> Unit { grid_top=measured(3), grid_w=measured(4), bottom_pad=measured(5), + scroll_y=measured(6), ), ) } } +} + +///| +fn after_render() -> Unit { + let st = state.val + fill_icons() + sync_measure() if is_android() { place() cover() @@ -381,6 +388,7 @@ fn is_dragging() -> Bool { fn wire_events() -> Unit { listen("document", "pointerdown", true, fn(e) { if ev_primary(e) { + sync_measure() feed(Down(x=ev_x(e), y=ev_y(e), chain=parse_chain(ev_chain(e)))) } }) @@ -439,9 +447,12 @@ fn wire_events() -> Unit { }) listen("window", "resize", true, fn(_) { schedule_render() }) listen("window", "scroll", true, fn(_) { - if is_android() { - request_frame(place) - } + request_frame(fn() { + sync_measure() + if is_android() { + place() + } + }) }) } @@ -459,8 +470,14 @@ fn expose_api() -> Unit { expose0("home", fn() { dispatch(GoHome) }) expose0("back", fn() { dispatch(Back) }) expose1("widgetAdded", fn(id) { dispatch(WidgetAdded(id)) }) - expose1("widgetMenu", fn(id) { dispatch(WidgetMenu(id)) }) - expose1("widgetGrab", fn(id) { dispatch(WidgetGrab(id)) }) + expose1("widgetMenu", fn(id) { + sync_measure() + dispatch(WidgetMenu(id)) + }) + expose1("widgetGrab", fn(id) { + sync_measure() + dispatch(WidgetGrab(id)) + }) expose_dd("widgetDrag", fn(x, y) { dispatch(NativeDrag(x, y)) }) expose_b("widgetDrop", fn(moved) { dispatch(NativeDrop(moved)) }) expose0("place", fn() { diff --git a/web/style.css b/web/style.css index 0873f8b..8d819f8 100644 --- a/web/style.css +++ b/web/style.css @@ -157,25 +157,37 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t up or resized (or while its native view is away, e.g. another widget is being resized). */ .widget-slot[data-wid]:not(.lifted):not(.resizing) { background: none; border-color: transparent; } -/* A widget being resized: handles sit just outside its right and bottom edges, where the - native widget view doesn't cover them; the bottom one sits in the gap below the row. */ +/* A widget being resized: generous 36-40px handles straddle the widget border (inset enough + to stay inside the viewport on full-width widgets); WidgetView passes edge touches through. */ .widget-slot { position: relative; } .widget-slot.resizing { z-index: 2; outline: 2px solid rgb(255 255 255 / .85); outline-offset: 3px; transition: none; } .resize-handle { position: absolute; z-index: 2; touch-action: none; cursor: nwse-resize; } .resize-handle::after { content: ""; position: absolute; border-radius: 999px; background: #fff; - box-shadow: 0 1px 6px rgb(0 0 0 / .45); } -.resize-handle[data-edge="r"] { top: 0; bottom: 0; right: -16px; width: 16px; cursor: ew-resize; } -.resize-handle[data-edge="r"]::after { top: 50%; left: 6px; width: 6px; height: 2.5rem; transform: translateY(-50%); } -.resize-handle[data-edge="b"] { left: 0; right: 0; bottom: -1rem; height: 1rem; cursor: ns-resize; } -.resize-handle[data-edge="b"]::after { left: 50%; top: 5px; width: 2.5rem; height: 6px; transform: translateX(-50%); } -.resize-handle[data-edge="rb"] { right: -16px; bottom: -1rem; width: 2.75rem; height: 1rem; } -.resize-handle[data-edge="rb"]::after { right: 4px; top: 1px; width: 14px; height: 14px; border-radius: 4px; } + box-shadow: 0 1px 6px rgb(0 0 0 / .45); + transition: background-color .1s, box-shadow .1s; } +.resize-handle.active::after, .resize-handle:active::after { + background: #93c5fd; + box-shadow: 0 0 0 4px rgb(147 197 253 / .35), 0 2px 8px rgb(0 0 0 / .55); +} +.resize-handle[data-edge="l"] { top: 12px; bottom: 12px; left: -14px; width: 36px; cursor: ew-resize; } +.resize-handle[data-edge="l"]::after { top: 50%; left: 7px; width: 6px; height: 2.25rem; transform: translateY(-50%); } +.resize-handle[data-edge="r"] { top: 12px; bottom: 12px; right: -14px; width: 36px; cursor: ew-resize; } +.resize-handle[data-edge="r"]::after { top: 50%; right: 7px; width: 6px; height: 2.25rem; transform: translateY(-50%); } +.resize-handle[data-edge="t"] { left: 12px; right: 12px; top: -14px; height: 36px; cursor: ns-resize; } +.resize-handle[data-edge="t"]::after { left: 50%; top: 7px; width: 2.25rem; height: 6px; transform: translateX(-50%); } +.resize-handle[data-edge="b"] { left: 12px; right: 12px; bottom: -14px; height: 36px; cursor: ns-resize; } +.resize-handle[data-edge="b"]::after { left: 50%; bottom: 7px; width: 2.25rem; height: 6px; transform: translateX(-50%); } +.resize-handle[data-edge="rb"] { right: -14px; bottom: -14px; width: 40px; height: 40px; z-index: 3; cursor: nwse-resize; } +.resize-handle[data-edge="rb"]::after { right: 3px; bottom: 3px; width: 16px; height: 16px; border-radius: 5px; } .resize-bar { position: fixed; left: 50%; bottom: calc(var(--bottom) + 1rem); z-index: 15; transform: translateX(-50%); - display: flex; align-items: center; gap: .5rem; padding: .4rem .4rem .4rem 1rem; border-radius: 999px; - background: rgb(0 0 0 / .8); color: #fff; font-size: .875rem; white-space: nowrap; + display: flex; align-items: center; gap: .5rem; padding: .4rem .4rem .4rem .75rem; border-radius: 999px; + background: rgb(0 0 0 / .82); color: #fff; font-size: .875rem; white-space: nowrap; animation: ui-fade .15s; } .resize-bar { max-width: calc(100vw - 1rem); } +.resize-size { flex: none; padding: .15rem .5rem; border-radius: 999px; + background: rgb(255 255 255 / .16); font-size: .75rem; font-weight: 600; + font-variant-numeric: tabular-nums; } .resize-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; } .resize-bar .btn { flex: none; } .resize-bar .btn.ghost { color: #fff; }