Start a new widget at its natural width in whole columns
The shell's widgetLimits now reports the provider's natural width ("w"), and
when a widget is added the page turns it into grid columns (WIDGET_COLS), so a
small widget takes the columns it needs instead of the whole row. Resizing
still snaps to whole columns and rows.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYASJ6JNxhYwNNJK7ypK2V
This commit is contained in:
4 files changed
+25
-5
No files matched your search
@@ -482,8 +482,9 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How far a placed widget may be resized, in CSS px: {"minW", "minH", "maxW", "maxH"
|
* A placed widget's natural width and how far it may be resized, in CSS px: {"w",
|
||||||
* (0 = no limit), "h", "v" (whether it resizes horizontally / vertically)}.
|
* "minW", "minH", "maxW", "maxH" (0 = no limit), "h", "v" (whether it resizes
|
||||||
|
* horizontally / vertically)}.
|
||||||
*/
|
*/
|
||||||
private String widgetLimits(int id) {
|
private String widgetLimits(int id) {
|
||||||
AppWidgetProviderInfo w = widgets.getAppWidgetInfo(id);
|
AppWidgetProviderInfo w = widgets.getAppWidgetInfo(id);
|
||||||
@@ -499,7 +500,8 @@ public class MainActivity extends Activity {
|
|||||||
maxW = w.maxResizeWidth;
|
maxW = w.maxResizeWidth;
|
||||||
maxH = w.maxResizeHeight;
|
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("maxW", Math.round(maxW / d)).put("maxH", Math.round(maxH / d))
|
||||||
.put("h", (w.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0)
|
.put("h", (w.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0)
|
||||||
.put("v", (w.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0);
|
.put("v", (w.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0);
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ RESIZE: Const[i32] = 40 # arg: columns * 4096 + height in px for the widg
|
|||||||
RESIZE_DONE: Const[i32] = 41
|
RESIZE_DONE: Const[i32] = 41
|
||||||
GRAB: Const[i32] = 42 # arg: the widget slot showing handles, picked up by its body
|
GRAB: Const[i32] = 42 # arg: the widget slot showing handles, picked up by its body
|
||||||
CHECK_UPDATES: Const[i32] = 43
|
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
|
CAP: Const[i32] = 512
|
||||||
HOME_CAP: Const[i32] = 200
|
HOME_CAP: Const[i32] = 200
|
||||||
@@ -539,6 +540,10 @@ def update(msg: i32, arg: i32) -> None:
|
|||||||
if chosen >= 0 and nh < HOME_CAP:
|
if chosen >= 0 and nh < HOME_CAP:
|
||||||
push_slot(WIDGET, s_dup(wlabels[chosen]), arg, wheights[chosen])
|
push_slot(WIDGET, s_dup(wlabels[chosen]), arg, wheights[chosen])
|
||||||
chosen = -1
|
chosen = -1
|
||||||
|
elif msg == WIDGET_COLS:
|
||||||
|
if nh > 0 and hkind[nh - 1] == WIDGET:
|
||||||
|
hw[nh - 1] = arg
|
||||||
|
save_home()
|
||||||
elif msg == REMOVE:
|
elif msg == REMOVE:
|
||||||
resizing = -1
|
resizing = -1
|
||||||
remove_slot(arg)
|
remove_slot(arg)
|
||||||
|
|||||||
Binary file not shown.
+15
-2
@@ -133,7 +133,7 @@
|
|||||||
|
|
||||||
// Messages the shell and the gestures below send (keep in sync with app.py).
|
// 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,
|
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
|
// 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.
|
// finger then slides it to the slot under the finger, and letting go drops it there.
|
||||||
@@ -238,11 +238,24 @@
|
|||||||
}, true);
|
}, true);
|
||||||
addEventListener("touchmove", (e) => { if (rs && e.cancelable) e.preventDefault(); }, { passive: false });
|
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 = {
|
window.ultraHome = {
|
||||||
reload: () => app.dispatch(RELOAD, 0),
|
reload: () => app.dispatch(RELOAD, 0),
|
||||||
home: () => { app.dispatch(HOME, 0); window.scrollTo({ top: 0, behavior: "smooth" }); },
|
home: () => { app.dispatch(HOME, 0); window.scrollTo({ top: 0, behavior: "smooth" }); },
|
||||||
back: () => app.dispatch(BACK, 0),
|
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),
|
widgetMenu: (id) => app.dispatch(WIDGET_MENU, id),
|
||||||
widgetGrab: (id) => { const li = document.querySelector(`.widget-slot.resizing[data-wid="${id}"]`);
|
widgetGrab: (id) => { const li = document.querySelector(`.widget-slot.resizing[data-wid="${id}"]`);
|
||||||
if (li) app.dispatch(GRAB, +li.dataset.slot); },
|
if (li) app.dispatch(GRAB, +li.dataset.slot); },
|
||||||
|
|||||||
Reference in new issue
Block a user