diff --git a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java index 6144662..b11869c 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -482,8 +482,9 @@ public class MainActivity extends Activity { } /** - * How far a placed widget may be resized, in CSS px: {"minW", "minH", "maxW", "maxH" - * (0 = no limit), "h", "v" (whether it resizes horizontally / vertically)}. + * A placed widget's natural width and how far it may be resized, in CSS px: {"w", + * "minW", "minH", "maxW", "maxH" (0 = no limit), "h", "v" (whether it resizes + * horizontally / vertically)}. */ private String widgetLimits(int id) { AppWidgetProviderInfo w = widgets.getAppWidgetInfo(id); @@ -499,7 +500,8 @@ public class MainActivity extends Activity { maxW = w.maxResizeWidth; maxH = w.maxResizeHeight; } - o.put("minW", Math.round(minW / d)).put("minH", Math.round(minH / d)) + o.put("w", Math.round(w.minWidth / d)) + .put("minW", Math.round(minW / d)).put("minH", Math.round(minH / d)) .put("maxW", Math.round(maxW / d)).put("maxH", Math.round(maxH / d)) .put("h", (w.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) .put("v", (w.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0); diff --git a/web/app.py b/web/app.py index 3b90049..76f836f 100644 --- a/web/app.py +++ b/web/app.py @@ -102,6 +102,7 @@ RESIZE: Const[i32] = 40 # arg: columns * 4096 + height in px for the widg RESIZE_DONE: Const[i32] = 41 GRAB: Const[i32] = 42 # arg: the widget slot showing handles, picked up by its body CHECK_UPDATES: Const[i32] = 43 +WIDGET_COLS: Const[i32] = 44 # arg: columns for the widget just added (0: the whole row) CAP: Const[i32] = 512 HOME_CAP: Const[i32] = 200 @@ -539,6 +540,10 @@ def update(msg: i32, arg: i32) -> None: if chosen >= 0 and nh < HOME_CAP: push_slot(WIDGET, s_dup(wlabels[chosen]), arg, wheights[chosen]) chosen = -1 + elif msg == WIDGET_COLS: + if nh > 0 and hkind[nh - 1] == WIDGET: + hw[nh - 1] = arg + save_home() elif msg == REMOVE: resizing = -1 remove_slot(arg) diff --git a/web/app.wasm b/web/app.wasm index e45e33e..099ad36 100644 Binary files a/web/app.wasm and b/web/app.wasm differ diff --git a/web/index.html b/web/index.html index f8a3dd9..dfc91d7 100644 --- a/web/index.html +++ b/web/index.html @@ -133,7 +133,7 @@ // Messages the shell and the gestures below send (keep in sync with app.py). const RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6, - WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40, GRAB = 42; + WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40, GRAB = 42, WIDGET_COLS = 44; // Dragging a home slot. A long press lifts it (app.py marks it .lifted); moving the // finger then slides it to the slot under the finger, and letting go drops it there. @@ -238,11 +238,24 @@ }, true); addEventListener("touchmove", (e) => { if (rs && e.cancelable) e.preventDefault(); }, { passive: false }); + // A new widget starts as many columns wide as its natural width needs (widgetLimits + // "w", CSS px), like its height starts at whole rows; 0 is the whole row. + const widgetCols = (id) => { + let lim = {}; + try { lim = JSON.parse(host.widgetLimits?.(id) || "{}"); } catch {} + const slots = document.querySelector(".slots"); + if (!lim.w || !slots) return 0; + const cs = getComputedStyle(slots), cols = cs.gridTemplateColumns.split(" ").map(parseFloat); + const gap = parseFloat(cs.columnGap) || 0; + const k = Math.max(1, Math.ceil((lim.w + gap - 8) / (cols[0] + gap))); + return k >= cols.length ? 0 : k; + }; + window.ultraHome = { reload: () => app.dispatch(RELOAD, 0), home: () => { app.dispatch(HOME, 0); window.scrollTo({ top: 0, behavior: "smooth" }); }, back: () => app.dispatch(BACK, 0), - widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id), + widgetAdded: (id) => { app.dispatch(WIDGET_ADDED, id); app.dispatch(WIDGET_COLS, widgetCols(id)); }, widgetMenu: (id) => app.dispatch(WIDGET_MENU, id), widgetGrab: (id) => { const li = document.querySelector(`.widget-slot.resizing[data-wid="${id}"]`); if (li) app.dispatch(GRAB, +li.dataset.slot); },