diff --git a/tests/e2e.cjs b/tests/e2e.cjs index 646d2cc..874dea2 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -115,7 +115,7 @@ const BASE = process.env.BASE || "http://localhost:8000"; await p.mouse.up(); await settle(); 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, 250, "snapped to half rows"); + assert.equal(h1, Math.round(2 * tile.height + 20), "snapped to two whole rows of tiles"); 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"))); @@ -132,6 +132,14 @@ const BASE = process.env.BASE || "http://localhost:8000"; await p.mouse.move(first.x + first.width / 2, first.y + first.height / 2, { steps: 8 }); await settle(); await p.mouse.up(); await settle(); assert.equal((await order())[0], "W", "dragged to the front"); + // the apps flow into the cells beside it: a 2x2 widget leaves room for all four + const beside = await p.$eval(".widget-slot", (w) => { + const r = w.getBoundingClientRect(); + return [...document.querySelectorAll(".slots .tile")].filter((t) => { + const b = t.getBoundingClientRect(); return b.top >= r.top - 1 && b.bottom <= r.bottom + 1; + }).length; + }); + assert.equal(beside, 4, "apps fill the cells beside the widget"); assert.ok(await p.$(".widget-slot.resizing"), "it keeps its handles after the move"); assert.ok(!(await p.$(".sheet"))); await p.click(".resize-bar >> text=Remove"); await settle(); diff --git a/web/app.py b/web/app.py index 7c2b0e6..4acaa44 100644 --- a/web/app.py +++ b/web/app.py @@ -12,8 +12,9 @@ from ui import btn_open, input_open, alert # A long press on a home app or widget picks it up: drag it to move it, or let go # without moving to get its menu (index.html does the dragging). Letting go of a # widget that way shows resize handles on its right and bottom edges instead: -# dragging them snaps the widget to the grid, within the sizes it allows, and -# dragging the widget itself moves it, staying in that mode once let go. +# dragging them snaps the widget to whole grid columns and rows of app tiles, +# within the sizes it allows, and dragging the widget itself moves it, staying +# in that mode once let go. Apps flow into the free cells beside widgets. # # The native shell (android/) serves this folder in a WebView, answers # apps.json and widgets.json, hosts the widgets as native views over the @@ -621,6 +622,14 @@ def view_resize_bar() -> None: end() +def widget_rows(h: i32) -> i32: + """Rows of app tiles nearest to a widget height in CSS px, at least one.""" + k: i32 = (h + 20 + 54) // 108 + if k < 1: + k = 1 + return k + + def view_home_slot(i: i32) -> None: row: i32 if hkind[i] == WIDGET: @@ -630,14 +639,12 @@ def view_home_slot(i: i32) -> None: cls_if("lifted", i == lifted) cls_if("resizing", i == resizing) attr_num("data-slot", i) + # Its height spans whole rows of app tiles (88px rows, 20px gaps; style.css). + s_set(scratch, "grid-row:span ") + s_add_num(scratch, widget_rows(hh[i])) if hw[i] > 0: - s_set(scratch, "grid-column:span ") + s_add(scratch, ";grid-column:span ") s_add_num(scratch, hw[i]) - s_add(scratch, ";height:") - else: - s_set(scratch, "height:") - s_add_num(scratch, hh[i]) - s_add(scratch, "px") attr_ref("style", scratch) # The native widget view is laid over slots marked live, so only mark # them while nothing covers the home screen. While one is resized the diff --git a/web/app.wasm b/web/app.wasm index 157c2fb..5542223 100644 Binary files a/web/app.wasm and b/web/app.wasm differ diff --git a/web/index.html b/web/index.html index 184191a..f8a3dd9 100644 --- a/web/index.html +++ b/web/index.html @@ -186,9 +186,8 @@ // Resizing a widget. Holding a widget and letting go without moving shows handles on // its right edge, bottom edge and corner (app.py). Dragging one snaps the widget to - // whole grid columns and half rows, within the shell's limits for that widget + // whole grid columns and rows, within the shell's limits for that widget // (widgetLimits, CSS px: min/max size, 0 = no max, and whether it resizes h and v). - const CELL = 88; // a row of app tiles let rs = null, swallowClick = false; const span = (k, size, gap) => k * size + (k - 1) * gap; const fit = (want, lo, hi, size, gap, min, max) => { @@ -210,6 +209,7 @@ const r = li.getBoundingClientRect(); rs = { li, edge: h.dataset.edge, left: r.left, top: r.top, lim, n: cols.length, colW: cols[0], gap: parseFloat(cs.columnGap) || 0, rgap: parseFloat(cs.rowGap) || 0, + cell: parseFloat(cs.gridAutoRows) || 88, // a row of app tiles cols: Math.round((r.width + (parseFloat(cs.columnGap) || 0)) / (cols[0] + (parseFloat(cs.columnGap) || 0))), h: Math.round(r.height) }; dragged = true; @@ -217,14 +217,13 @@ }, true); addEventListener("pointermove", (e) => { if (!rs) return; - const { lim, n, colW, gap, rgap } = rs, half = (CELL + rgap) / 2; + const { lim, n, colW, gap, rgap, cell } = rs; let cols = rs.cols, h = rs.h; if (rs.edge !== "b" && lim.h !== false) cols = fit(e.clientX - rs.left, 1, n, colW, gap, lim.minW || 0, lim.maxW || 0); if (rs.edge !== "r" && lim.v !== false) { - // half-row steps: 2 halves are one row of tiles, 4 are two rows with the gap between - const k = fit(e.clientY - rs.top + rgap, 2, 40, half, 0, (lim.minH || 0) + rgap, lim.maxH ? lim.maxH + rgap : 0); - h = Math.round(k * half - rgap); + const k = fit(e.clientY - rs.top, 1, 20, cell, rgap, lim.minH || 0, lim.maxH || 0); + h = Math.round(span(k, cell, rgap)); } if (cols === rs.cols && h === rs.h) return; rs.cols = cols; rs.h = h; diff --git a/web/style.css b/web/style.css index a6854b9..b948fde 100644 --- a/web/style.css +++ b/web/style.css @@ -36,6 +36,10 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .windows-glyph::after { inset: .3rem 0 0 .3rem; background: rgb(255 255 255 / .15); } .slots, .apps { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.25rem .5rem; grid-template-columns: repeat(4, minmax(0, 1fr)); } +/* Home rows are all one height, so a widget spans whole rows of app tiles, and apps + fill the cells beside a widget rather than leaving holes (dense packing). Keep + --cell and the gap in sync with widget_rows in app.py. */ +.slots { grid-auto-rows: 5.5rem; grid-auto-flow: row dense; } @media (min-width: 480px) { .slots, .apps { grid-template-columns: repeat(5, minmax(0, 1fr)); } } .tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .35rem .15rem; border-radius: calc(var(--radius) + 4px); cursor: pointer; } @@ -46,7 +50,7 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .name { max-width: 100%; font-size: .75rem; line-height: 1.2; text-align: center; text-shadow: var(--shadow-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -/* A widget takes a whole row. On a phone the native widget view covers the slot; +/* A widget takes whole rows. On a phone the native widget view covers the slot; the label only shows while the slot is not live (or in a desktop browser). */ .widget-slot { grid-column: 1 / -1; display: grid; place-items: center; box-sizing: border-box; border-radius: 1.25rem; background: rgb(255 255 255 / .1); @@ -57,19 +61,19 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .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 extra margin keeps the next row clear. */ + native widget view doesn't cover them; the bottom one sits in the gap below the row. */ .widget-slot { position: relative; } -.widget-slot.resizing { margin-bottom: 1.75rem; outline: 2px solid rgb(255 255 255 / .85); +.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: -1.75rem; height: 1.75rem; cursor: ns-resize; } -.resize-handle[data-edge="b"]::after { left: 50%; top: 8px; width: 2.5rem; height: 6px; transform: translateX(-50%); } -.resize-handle[data-edge="rb"] { right: -16px; bottom: -1.75rem; width: 2.75rem; height: 1.75rem; } -.resize-handle[data-edge="rb"]::after { right: 4px; top: 6px; width: 14px; height: 14px; border-radius: 4px; } +.resize-handle[data-edge="b"] { left: 0; right: 0; bottom: -1.25rem; height: 1.25rem; cursor: ns-resize; } +.resize-handle[data-edge="b"]::after { left: 50%; top: 7px; width: 2.5rem; height: 6px; transform: translateX(-50%); } +.resize-handle[data-edge="rb"] { right: -16px; bottom: -1.25rem; width: 2.75rem; height: 1.25rem; } +.resize-handle[data-edge="rb"]::after { right: 4px; top: 3px; width: 14px; height: 14px; border-radius: 4px; } .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;