Make the home grid run to the bottom of the screen with cells you drop into
The page measures how many rows fit down to the bottom of the screen (GRID) and app.py lays the grid out with that many, so the empty space is real cells. Each slot can be pinned to a cell (hx, hy, saved); dragging pins every slot where it shows, carries the lifted one to the cell under the finger (MOVE_CELL), and on drop moves whatever it covers to the first free cells. Unpinned slots (new apps, displaced ones) flow densely into free cells. The Move earlier/later menu items go, since order no longer sets the place. 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
+193
-90
No files matched your search
+107
-56
@@ -9,12 +9,14 @@ from ui import btn_open, input_open, alert
|
||||
|
||||
# An Android home screen. The home starts blank: you add apps and widgets to it
|
||||
# with a long press. Swiping down opens the drawer with every app and a search.
|
||||
# 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
|
||||
# The home grid runs to the bottom of the screen. A long press on a home app or
|
||||
# widget picks it up: drag it to any cell to move it there (what it lands on
|
||||
# moves to the first free cells), 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 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.
|
||||
# in that mode once let go. New apps flow into the first free cells.
|
||||
#
|
||||
# The native shell (android/) serves this folder in a WebView, answers
|
||||
# apps.json and widgets.json, hosts the widgets as native views over the
|
||||
@@ -86,14 +88,13 @@ PICK_APPS: Const[i32] = 24
|
||||
PICK_WIDGET: Const[i32] = 25
|
||||
CHOOSE_WIDGET: Const[i32] = 26 # arg: row in the widget list
|
||||
REMOVE: Const[i32] = 27 # arg: home slot
|
||||
MOVE: Const[i32] = 28 # arg: home slot; moves it one earlier
|
||||
INFO: Const[i32] = 29 # arg: home slot
|
||||
SETTINGS: Const[i32] = 30
|
||||
WALLPAPER: Const[i32] = 31
|
||||
NOTICE_DONE: Const[i32] = 32
|
||||
RECENTS: Const[i32] = 33
|
||||
LIFT: Const[i32] = 34 # arg: home slot (long press picks it up)
|
||||
DRAG_TO: Const[i32] = 35 # arg: home slot the lifted one is dragged over
|
||||
MOVE_CELL: Const[i32] = 35 # arg: row * 64 + column the lifted slot is dragged to
|
||||
DROP: Const[i32] = 36 # arg: 1 if it was dragged, 0 if just held (opens its menu)
|
||||
WQUERY: Const[i32] = 37 # widget picker search
|
||||
WCLEAR: Const[i32] = 38
|
||||
@@ -103,6 +104,8 @@ 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)
|
||||
GRID: Const[i32] = 45 # arg: columns * 4096 + rows that fit on the screen
|
||||
PIN: Const[i32] = 46 # arg: slot * 65536 + row * 64 + column it shows at now
|
||||
|
||||
CAP: Const[i32] = 512
|
||||
HOME_CAP: Const[i32] = 200
|
||||
@@ -136,7 +139,13 @@ hwid: i32[512] = empty(512, dtype=int32)
|
||||
hh: i32[512] = empty(512, dtype=int32)
|
||||
hw: i32[512] = empty(512, dtype=int32)
|
||||
hkey: i32[512] = empty(512, dtype=int32)
|
||||
# The grid cell a slot is pinned to (column hx, row hy, from 0), or -1: placed
|
||||
# by the grid's dense flow into the first free cells that fit it.
|
||||
hx: i32[512] = empty(512, dtype=int32)
|
||||
hy: i32[512] = empty(512, dtype=int32)
|
||||
nh: i32 = 0
|
||||
ncols: i32 = 5 # grid columns, and rows that fill the screen (index.html measures them)
|
||||
nrows: i32 = 0
|
||||
next_key: i32 = 1
|
||||
# Widget providers, for the picker.
|
||||
wlabels: i32[512] = empty(512, dtype=int32)
|
||||
@@ -185,6 +194,8 @@ def init() -> None:
|
||||
hwid[nh] = load_i32_at("ultra.home.wid", i, 0)
|
||||
hh[nh] = load_i32_at("ultra.home.h", i, 120)
|
||||
hw[nh] = load_i32_at("ultra.home.w", i, 0)
|
||||
hx[nh] = load_i32_at("ultra.home.x", i, -1)
|
||||
hy[nh] = load_i32_at("ultra.home.y", i, -1)
|
||||
hkey[nh] = next_key
|
||||
next_key += 1
|
||||
nh += 1
|
||||
@@ -202,6 +213,8 @@ def save_home() -> None:
|
||||
store_i32_at("ultra.home.wid", i, hwid[i])
|
||||
store_i32_at("ultra.home.h", i, hh[i])
|
||||
store_i32_at("ultra.home.w", i, hw[i])
|
||||
store_i32_at("ultra.home.x", i, hx[i])
|
||||
store_i32_at("ultra.home.y", i, hy[i])
|
||||
|
||||
|
||||
def say(msg: str) -> None:
|
||||
@@ -342,6 +355,8 @@ def push_slot(kind: i32, s: i32, wid: i32, h: i32) -> None:
|
||||
hwid[nh] = wid
|
||||
hh[nh] = h
|
||||
hw[nh] = 0
|
||||
hx[nh] = -1
|
||||
hy[nh] = -1
|
||||
hkey[nh] = next_key
|
||||
next_key += 1
|
||||
nh += 1
|
||||
@@ -370,45 +385,55 @@ def remove_slot(at: i32) -> None:
|
||||
hwid[j] = hwid[j + 1]
|
||||
hh[j] = hh[j + 1]
|
||||
hw[j] = hw[j + 1]
|
||||
hx[j] = hx[j + 1]
|
||||
hy[j] = hy[j + 1]
|
||||
hkey[j] = hkey[j + 1]
|
||||
nh -= 1
|
||||
save_home()
|
||||
|
||||
|
||||
def swap_slots(a: i32, b: i32) -> None:
|
||||
t: i32
|
||||
t = hkind[a]
|
||||
hkind[a] = hkind[b]
|
||||
hkind[b] = t
|
||||
t = hstr[a]
|
||||
hstr[a] = hstr[b]
|
||||
hstr[b] = t
|
||||
t = hwid[a]
|
||||
hwid[a] = hwid[b]
|
||||
hwid[b] = t
|
||||
t = hh[a]
|
||||
hh[a] = hh[b]
|
||||
hh[b] = t
|
||||
t = hw[a]
|
||||
hw[a] = hw[b]
|
||||
hw[b] = t
|
||||
t = hkey[a]
|
||||
hkey[a] = hkey[b]
|
||||
hkey[b] = t
|
||||
def slot_w(i: i32) -> i32:
|
||||
"""Columns slot i spans."""
|
||||
if hkind[i] == APP:
|
||||
return 1
|
||||
if hw[i] <= 0 or hw[i] > ncols:
|
||||
return ncols
|
||||
return hw[i]
|
||||
|
||||
|
||||
def slot_h(i: i32) -> i32:
|
||||
"""Rows slot i spans."""
|
||||
if hkind[i] == APP:
|
||||
return 1
|
||||
return widget_rows(hh[i])
|
||||
|
||||
|
||||
def clear_cells(i: i32) -> None:
|
||||
"""Unpin the slots under pinned slot i, so they flow into free cells."""
|
||||
j: i32
|
||||
for j in range(nh):
|
||||
if j != i and hx[j] >= 0 and hx[j] < hx[i] + slot_w(i) and hx[i] < hx[j] + slot_w(j) \
|
||||
and hy[j] < hy[i] + slot_h(i) and hy[i] < hy[j] + slot_h(j):
|
||||
hx[j] = -1
|
||||
hy[j] = -1
|
||||
|
||||
|
||||
def pin_slot(i: i32, col: i32, row: i32) -> None:
|
||||
"""Pin slot i with its top left at col, row (kept on the grid). It may cover others
|
||||
while it is carried; clear_cells moves them off once it is put down."""
|
||||
x: i32 = col
|
||||
y: i32 = row
|
||||
if x + slot_w(i) > ncols:
|
||||
x = ncols - slot_w(i)
|
||||
if x < 0:
|
||||
x = 0
|
||||
if y < 0:
|
||||
y = 0
|
||||
hx[i] = x
|
||||
hy[i] = y
|
||||
save_home()
|
||||
|
||||
|
||||
def move_slot(a: i32, b: i32) -> None:
|
||||
"""Take slot a out and put it back at b, shifting the slots between."""
|
||||
i: i32 = a
|
||||
while i < b:
|
||||
swap_slots(i, i + 1)
|
||||
i += 1
|
||||
while i > b:
|
||||
swap_slots(i, i - 1)
|
||||
i -= 1
|
||||
|
||||
|
||||
def slot_of_widget(wid: i32) -> i32:
|
||||
i: i32
|
||||
for i in range(nh):
|
||||
@@ -430,7 +455,7 @@ def close_all() -> None:
|
||||
|
||||
# ---- Update
|
||||
def update(msg: i32, arg: i32) -> None:
|
||||
global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab
|
||||
global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab, ncols, nrows
|
||||
i: i32
|
||||
if msg == LOADED:
|
||||
load_apps(arg)
|
||||
@@ -493,11 +518,22 @@ def update(msg: i32, arg: i32) -> None:
|
||||
resizing = -1
|
||||
regrab = 1
|
||||
lifted = arg
|
||||
elif msg == DRAG_TO:
|
||||
if lifted >= 0 and arg >= 0 and arg < nh and arg != lifted:
|
||||
move_slot(lifted, arg)
|
||||
lifted = arg
|
||||
elif msg == MOVE_CELL:
|
||||
if lifted >= 0 and (hx[lifted] != arg % 64 or hy[lifted] != arg // 64):
|
||||
pin_slot(lifted, arg % 64, arg // 64)
|
||||
elif msg == GRID:
|
||||
ncols = arg // 4096
|
||||
nrows = arg % 4096
|
||||
elif msg == PIN:
|
||||
i = arg // 65536
|
||||
if i >= 0 and i < nh:
|
||||
hx[i] = arg % 64
|
||||
hy[i] = (arg % 65536) // 64
|
||||
save_home()
|
||||
elif msg == DROP:
|
||||
if lifted >= 0 and hx[lifted] >= 0:
|
||||
clear_cells(lifted)
|
||||
save_home()
|
||||
if lifted >= 0 and (arg == 0 or regrab == 1):
|
||||
if hkind[lifted] == WIDGET:
|
||||
resizing = lifted
|
||||
@@ -510,6 +546,9 @@ def update(msg: i32, arg: i32) -> None:
|
||||
if resizing >= 0:
|
||||
hw[resizing] = arg // 4096
|
||||
hh[resizing] = arg % 4096
|
||||
if hx[resizing] >= 0:
|
||||
pin_slot(resizing, hx[resizing], hy[resizing])
|
||||
clear_cells(resizing)
|
||||
save_home()
|
||||
elif msg == RESIZE_DONE:
|
||||
resizing = -1
|
||||
@@ -549,11 +588,6 @@ def update(msg: i32, arg: i32) -> None:
|
||||
remove_slot(arg)
|
||||
sheet = NONE
|
||||
item = -1
|
||||
elif msg == MOVE:
|
||||
if arg > 0:
|
||||
swap_slots(arg, arg - 1)
|
||||
sheet = NONE
|
||||
item = -1
|
||||
elif msg == INFO:
|
||||
app_info(hstr[arg])
|
||||
sheet = NONE
|
||||
@@ -635,6 +669,24 @@ def widget_rows(h: i32) -> i32:
|
||||
return k
|
||||
|
||||
|
||||
def view_cell(i: i32) -> None:
|
||||
"""Slot i's place on the grid: its pinned cell if it fits, and its span."""
|
||||
s_clear(scratch)
|
||||
if hx[i] >= 0 and hx[i] + slot_w(i) <= ncols:
|
||||
s_add(scratch, "grid-column:")
|
||||
s_add_num(scratch, hx[i] + 1)
|
||||
s_add(scratch, ";grid-row:")
|
||||
s_add_num(scratch, hy[i] + 1)
|
||||
s_add(scratch, "/")
|
||||
else:
|
||||
s_add(scratch, "grid-row:")
|
||||
s_add(scratch, "span ")
|
||||
s_add_num(scratch, slot_h(i))
|
||||
s_add(scratch, ";grid-column-end:span ")
|
||||
s_add_num(scratch, slot_w(i))
|
||||
attr_ref("style", scratch)
|
||||
|
||||
|
||||
def view_home_slot(i: i32) -> None:
|
||||
row: i32
|
||||
if hkind[i] == WIDGET:
|
||||
@@ -645,12 +697,7 @@ def view_home_slot(i: i32) -> None:
|
||||
cls_if("resizing", i == resizing)
|
||||
attr_num("data-slot", i)
|
||||
# Its height spans whole rows of app tiles (72px rows, 12px gaps; style.css).
|
||||
s_set(scratch, "grid-row:span ")
|
||||
s_add_num(scratch, widget_rows(hh[i]))
|
||||
if hw[i] > 0:
|
||||
s_add(scratch, ";grid-column:span ")
|
||||
s_add_num(scratch, hw[i])
|
||||
attr_ref("style", scratch)
|
||||
view_cell(i)
|
||||
# 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
|
||||
# others step aside, so nothing native covers its handles.
|
||||
@@ -675,6 +722,8 @@ def view_home_slot(i: i32) -> None:
|
||||
cls("tile")
|
||||
cls_if("lifted", i == lifted)
|
||||
attr_num("data-slot", i)
|
||||
if hx[i] >= 0:
|
||||
view_cell(i)
|
||||
on_click(OPEN_HOME, i)
|
||||
on_longpress(LIFT, i)
|
||||
view_icon(icons[row])
|
||||
@@ -721,6 +770,12 @@ def view_home() -> None:
|
||||
el("ul")
|
||||
cls("slots")
|
||||
cls_if("dragging", lifted >= 0)
|
||||
if nrows > 0 and nh > 0:
|
||||
# Rows down to the bottom of the screen, so empty cells there take apps too.
|
||||
s_set(scratch, "grid-template-rows:repeat(")
|
||||
s_add_num(scratch, nrows)
|
||||
s_add(scratch, ",4.5rem)")
|
||||
attr_ref("style", scratch)
|
||||
for i in range(nh):
|
||||
view_home_slot(i)
|
||||
end()
|
||||
@@ -836,10 +891,6 @@ def view_sheet() -> None:
|
||||
if row >= 0:
|
||||
text_ref(labels[row])
|
||||
end()
|
||||
if item > 0:
|
||||
sheet_btn("Move earlier", MOVE, item)
|
||||
if item < nh - 1:
|
||||
sheet_btn("Move later", MOVE, item + 1)
|
||||
if hkind[item] == APP:
|
||||
sheet_btn("App info", INFO, item)
|
||||
sheet_btn("Remove from home", REMOVE, item)
|
||||
|
||||
Reference in new issue
Block a user