Finish a list item with a tap, edit it with a swipe right and delete it with a swipe left, as in 1List

This commit is contained in:
waozi committed 2026-10-23 01:38:28 -03:00
1 parent cac3fb7498
commit 58d683882c
15 files changed
+87 -123

No files matched your search

+45 -42
View File
@@ -18,8 +18,8 @@
#import "button_props"
#import "button_widget"
#import "control_props"
#import "checkbox_props"
#import "checkbox_widget"
#import "swipe_row_props"
#import "swipe_row"
#import "tab_bar_props"
#import "tab_bar_widget"
#import "scroll_props"
@@ -31,6 +31,7 @@
#import "drawing_props"
#import "tree"
#import "icon"
EditIcon :: #import "mingcute/mingcute_regular_edit_2";
#import, file "../../src/cells/lists_ui_types.zi";
#import, file "../../src/cells/lists_types.zi";
@@ -75,6 +76,19 @@ undo_until: float64;
SHARE_ICON :: "S1.8rr:M9 4.5C10.93 4.5 12.5 6.07 12.5 8C12.5 9.93 10.93 11.5 9 11.5C7.07 11.5 5.5 9.93 5.5 8C5.5 6.07 7.07 4.5 9 4.5ZM3 20C3 16.7 5.7 14 9 14C12.3 14 15 16.7 15 20M19 8V14M16 11H22"
// The same trash can as Photos and Lumi.
TRASH_ICON :: "S1.6rr:M3 6H21M9 6V3H15V6M5 6L6 21H18L19 6M10 10V17M14 10V17"
// As in 1List, a tap on an item finishes it, a swipe right edits it and a
// swipe left deletes it; Undo brings a deleted item back.
row_swipe: SwipeRowState;
EditSwipe :: () -> SwipeRowAction {
return SwipeRowAction.{.fill = Color.{58, 110, 165, 255},
.icon_shape = EditIcon.Shape, .icon_color = Color.{255, 255, 255, 255}}
}
DeleteSwipe :: () -> SwipeRowAction {
return SwipeRowAction.{.fill = Color.{198, 52, 52, 255},
.icon_shape = TRASH_ICON, .icon_color = Color.{255, 255, 255, 255}, .removes = true}
}
Scale :: (pixels: s32) -> s32 {
return cast(s32)(cast(float32)pixels * frame.scale)
@@ -762,12 +776,7 @@ ListsPage :: () {
.wrap = cast(TextWrap)TextWrapAuto})
return
}
editing_row := state.editing_item >= 0 && state.editing_item < state.item_count
field_width := width - Scale(96)
if editing_row {
field_width -= Scale(52)
}
committed := Field(Bounds(x, y, field_width, Scale(44)),
committed := Field(Bounds(x, y, width - Scale(96), Scale(44)),
ListsLocaleHost(ifx state.editing_item >= 0 then "elist_item_name_placeholder" else "elist_add_item_placeholder"), blocked)
if Button(frame.session, ButtonProps.{.key = cast(u64)6507,
.label = ListsLocaleHost(ifx state.editing_item >= 0 then "done_button" else "elist_add_item"),
@@ -777,23 +786,6 @@ ListsPage :: () {
Mutation(LISTS_COMMIT, -1)
return
}
// While an item is in Edit, a trash can beside Done deletes it and
// leaves Edit with an empty field; Undo brings the item back.
if editing_row {
if Button(frame.session, ButtonProps.{.key = cast(u64)6516,
.label = ListsLocaleHost("elist_delete_item"),
.bounds = Bounds(x + field_width + Scale(8), y, Scale(44), Scale(44)),
.icon_shape = TRASH_ICON, .icon_only = true,
.tone = cast(ButtonTone)ButtonToneDanger,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisGhost, .disabled = blocked}) != 0 {
editing := state.editing_item
RememberDeleted(ReadListsRowHost(editing, true))
Mutation(LISTS_DELETE_ITEM, editing)
state.editing_item = -1
state.reset_input = true
return
}
}
y += Scale(56)
// One small line under the field: filter the finished items, or take
// back the last deletion.
@@ -863,31 +855,42 @@ ListsPage :: () {
if row_y + Scale(64) > cast(s32)scroll.viewport.y &&
row_y < cast(s32)(scroll.viewport.y + scroll.viewport.height) {
row := ReadListsRowHost(index, true)
key := cast(u64)(7000 + index * 4)
checked := Checkbox(frame.session, CheckboxProps.{.key = key,
.bounds = Bounds(x, row_y + Scale(10), Scale(44), Scale(44)),
.checked = row.done != 0, .disabled = blocked})
if checked.changed {
state.done = ifx checked.checked then 1 else 0
Mutation(LISTS_SET_DONE, index)
End(frame.session)
return
}
text_width := row_right - (x + Scale(52)) - Scale(52)
Text(frame.session, TextProps.{.bounds = Bounds(x + Scale(52), row_y,
swiped := SwipeRow(frame.session, SwipeRowProps.{.key = cast(u64)(7000 + index * 4),
.bounds = Bounds(x, row_y, row_right - x, Scale(64)),
.label = row.title, .now = state.now, .scale = frame.scale,
.start = EditSwipe(), .end = DeleteSwipe(), .disabled = blocked},
row_swipe)
row_swipe = swiped.state
text_x := x + Scale(12) + cast(s32)swiped.offset
text_width := row_right - x - Scale(24)
Text(frame.session, TextProps.{.bounds = Bounds(text_x, row_y,
text_width, ifx row.comment.count > 0 then Scale(30) else Scale(64)),
.text = row.title, .vertical_align = cast(TextAlign)TextAlignCenter,
.strikethrough = row.done != 0})
if row.comment.count > 0 {
Text(frame.session, TextProps.{.bounds = Bounds(x + Scale(52), row_y + Scale(34),
Text(frame.session, TextProps.{.bounds = Bounds(text_x, row_y + Scale(34),
text_width, Scale(24)), .text = row.comment})
}
if Button(frame.session, ButtonProps.{.key = key + cast(u64)1,
.bounds = Bounds(row_right - Scale(44), row_y + Scale(10), Scale(44), Scale(44)),
.label = ListsLocaleHost("elist_rename"), .icon_type = cast(s32)IconEdit,
.icon_only = true, .disabled = blocked}) != 0 {
if swiped.clicked {
state.done = ifx row.done != 0 then 0 else 1
Mutation(LISTS_SET_DONE, index)
End(frame.session)
return
}
if swiped.swiped_start {
BeginInput(index, row.title)
}
if swiped.swiped_end {
// Deleting leaves Edit, since the items after it move up.
RememberDeleted(row)
Mutation(LISTS_DELETE_ITEM, index)
if state.editing_item >= 0 {
state.editing_item = -1
state.reset_input = true
}
End(frame.session)
return
}
}
row_y += Scale(72)
}
-3
View File
@@ -7399,9 +7399,6 @@ Smazat seznam
[elist_delete_list_confirm]
Klepnutím znovu smažete tento seznam
---
[elist_delete_item]
Smazat položku
---
[elist_undo]
Vrátit smazání
---
-3
View File
@@ -7393,9 +7393,6 @@ Liste löschen
[elist_delete_list_confirm]
Nochmal tippen, um die Liste zu löschen
---
[elist_delete_item]
Eintrag löschen
---
[elist_undo]
Löschen rückgängig
---
-3
View File
@@ -7417,9 +7417,6 @@ Delete list
[elist_delete_list_confirm]
Tap again to delete this list
---
[elist_delete_item]
Delete item
---
[elist_undo]
Undo delete
---
-3
View File
@@ -7393,9 +7393,6 @@ Eliminar lista
[elist_delete_list_confirm]
Toca otra vez para eliminar esta lista
---
[elist_delete_item]
Eliminar elemento
---
[elist_undo]
Deshacer
---
-3
View File
@@ -7381,9 +7381,6 @@ Supprimer la liste
[elist_delete_list_confirm]
Touchez encore pour supprimer cette liste
---
[elist_delete_item]
Supprimer l'élément
---
[elist_undo]
Annuler la suppression
---
-3
View File
@@ -7382,9 +7382,6 @@ Hapus daftar
[elist_delete_list_confirm]
Ketuk lagi untuk menghapus daftar ini
---
[elist_delete_item]
Hapus item
---
[elist_undo]
Urungkan hapus
---
-3
View File
@@ -7382,9 +7382,6 @@ Elimina elenco
[elist_delete_list_confirm]
Tocca di nuovo per eliminare questo elenco
---
[elist_delete_item]
Elimina voce
---
[elist_undo]
Annulla eliminazione
---
-3
View File
@@ -7378,9 +7378,6 @@ Inner Breeze がバージョン %s に更新されました。
[elist_delete_list_confirm]
もう一度タップするとこのリストを削除します
---
[elist_delete_item]
項目を削除
---
[elist_undo]
削除を元に戻す
---
-3
View File
@@ -7388,9 +7388,6 @@ Inner Breeze가 %s 버전으로 업데이트되었어요.
[elist_delete_list_confirm]
한 번 더 누르면 이 목록이 삭제됩니다
---
[elist_delete_item]
항목 삭제
---
[elist_undo]
삭제 취소
---
-3
View File
@@ -7391,9 +7391,6 @@ Excluir lista
[elist_delete_list_confirm]
Toque de novo para excluir esta lista
---
[elist_delete_item]
Excluir item
---
[elist_undo]
Desfazer exclusão
---
-3
View File
@@ -7387,9 +7387,6 @@ Inner Breeze обновлён до версии %s.
[elist_delete_list_confirm]
Нажмите ещё раз, чтобы удалить список
---
[elist_delete_item]
Удалить пункт
---
[elist_undo]
Отменить удаление
---
-3
View File
@@ -7393,9 +7393,6 @@ Inner Breeze 已更新至 %s 版本。
[elist_delete_list_confirm]
再次点按以删除此列表
---
[elist_delete_item]
删除项目
---
[elist_undo]
撤销删除
---
+28 -31
View File
@@ -136,54 +136,51 @@ with contextlib.ExitStack() as stack:
shown = [label for label in driver.labels() if ALARMING.search(label)]
assert not shown, f"FAIL {message}: {shown} ({TEST_DIR})"
def alerts_quiet(seconds=2.0):
"""Achievement alerts open one after another over the field's right
end, where Done and Delete are; wait until none has shown a while."""
quiet_since = time.monotonic()
deadline = quiet_since + 60
while time.monotonic() - quiet_since < seconds:
if driver.find(contains="Achievement unlocked", visible=True):
quiet_since = time.monotonic()
assert time.monotonic() < deadline, f"FAIL achievement alerts kept showing ({TEST_DIR})"
time.sleep(0.05)
# Undo follows the real bundle and typed persistence bridge, preserving
# the original completed item and its comment rather than creating a copy.
def row_control(title, kind):
row = driver.wait(label=title)
controls = [node for node in driver.tree() if node["kind"] == kind and node["visible"] and
(kind != "button" or node["label"] == "Rename")]
control = min(controls, key=lambda node: abs(node["y"] - row["y"]))
assert abs(control["y"] - row["y"]) < 64, (row, control)
return control["key"]
# As in 1List, a tap on an item finishes it, a swipe right edits it and
# a swipe left deletes it. Undo follows the real bundle and typed
# persistence bridge, preserving the original completed item and its
# comment rather than creating a copy.
def swipe(title, share):
"""Drag the item's row sideways by this share of its width."""
row = driver.wait(label=title, role="button")
x, y = UiDriver.center(row)
driver.drag((x, y), (x + row["visible_width"] * share, y), steps=10)
driver.wait_idle(frames=3, timeout=2)
original = sql("SELECT id,comment,sort_order FROM elist_items WHERE title='Fresh fruit' AND deleted_at=0")
driver.press(key=row_control("Fresh fruit", "checkbox"))
assert not driver.find(role="checkbox", visible=True), "items still have checkboxes"
assert not [node for node in driver.tree() if node["visible"] and node["label"] == "Rename" and node["y"] > 160], \
"items still have edit buttons"
driver.press(label="Fresh fruit", role="button")
wait_for(lambda: sql("SELECT done FROM elist_items WHERE id=?", (original[0],)) == 1,
"the undo fixture was not completed")
"a tap did not finish the item")
driver.press(label="All", role="tab")
driver.press(key=row_control("Fresh fruit", "button"))
# A short swipe slides back and changes nothing.
swipe("Fresh fruit", -0.2)
swipe("Fresh fruit", 0.2)
assert driver.find(role="text_field", value="", visible=True), "a short swipe right began editing"
assert sql("SELECT deleted_at FROM elist_items WHERE id=?", (original[0],)) == 0, "a short swipe left deleted"
swipe("Fresh fruit", 0.6)
driver.wait(role="text_field", value="Fresh fruit")
alerts_quiet()
delete = driver.wait(label="Delete item", role="button")
assert delete["width"] <= delete["height"] * 1.2, f"Delete is not a trash icon: {delete}"
driver.press(label="Delete item", role="button")
driver.wait(label="Done", role="button")
assert not driver.find(label="Delete item", role="button", visible=True), "Edit still shows a delete button"
swipe("Fresh fruit", -0.6)
wait_for(lambda: sql("SELECT deleted_at FROM elist_items WHERE id=?", (original[0],)) > 0,
"the item was not deleted")
"a swipe left did not delete the item")
# Deleting leaves Edit: the field is empty again, ready to add.
driver.wait(label="Add", role="button")
assert not driver.find(label="Delete item", role="button", visible=True), "Delete stayed after deleting"
assert driver.find(role="text_field", value="", visible=True), \
f"the deleted item's name stayed in the field: {driver.find(role='text_field')}"
assert not driver.find(label="Fresh fruit", role="button", visible=True), "the deleted item is still listed"
driver.press(label="Undo delete", role="button")
wait_for(lambda: sql("SELECT deleted_at FROM elist_items WHERE id=?", (original[0],)) == 0,
"Undo did not restore the item")
restored = sql("SELECT id,comment,sort_order,done FROM elist_items WHERE title='Fresh fruit' AND deleted_at=0")
assert restored == (*original, 1), ("Undo changed the item", original, restored)
assert sql("SELECT COUNT(*) FROM elist_items WHERE title='Fresh fruit'") == 1, "Undo made a duplicate"
driver.press(key=row_control("Fresh fruit", "checkbox"))
driver.press(label="Fresh fruit", role="button")
wait_for(lambda: sql("SELECT done FROM elist_items WHERE id=?", (original[0],)) == 0,
"the original completion state was not restored")
"a second tap did not reopen the item")
driver.press(label="Weekend", role="tab")
add("Weekend task")
+14 -14
View File
@@ -28,7 +28,7 @@
},
{
"commit": "1cb9df183089a77c8a16448a556186f30b261a98",
"dependencies": {"kryon": "p7c9cab047dc7384e"},
"dependencies": {"kryon": "p443f6238630e97c6"},
"id": "p1b13dda539ed2a39",
"name": "Kss",
"ref": "master",
@@ -36,7 +36,7 @@
},
{
"commit": "bad2caaa84ef3eae61e40c99bf572d2b060d0ca2",
"dependencies": {"kryon": "p7c9cab047dc7384e"},
"dependencies": {"kryon": "p443f6238630e97c6"},
"id": "p20eb23d3e6db3711",
"name": "Game2D",
"ref": "master",
@@ -44,12 +44,20 @@
},
{
"commit": "622db7474127fc47432f3786b856e505c6645b3a",
"dependencies": {"crypto": "pf039d7a776333200", "kryon": "p7c9cab047dc7384e"},
"dependencies": {"crypto": "pf039d7a776333200", "kryon": "p443f6238630e97c6"},
"id": "p424eeb497051c0eb",
"name": "Apps",
"ref": "master",
"url": "https://github.com/waozixyz/apps.git"
},
{
"commit": "884bc1108d52d542406f53472ed8bb1ab3f06454",
"dependencies": {"raylib": "p5a77c9c35110e925"},
"id": "p443f6238630e97c6",
"name": "kryon",
"ref": "master",
"url": "https://github.com/kryonlabs/kryon.git"
},
{
"commit": "e1f480f382d9443c4412133b55948374c77a5c21",
"dependencies": {},
@@ -76,14 +84,6 @@
"ref": "master",
"url": "https://github.com/ziranlang/oqs.git"
},
{
"commit": "e169a7ee6541c3fadc2ba4c2eaa2105f0bb164f7",
"dependencies": {"raylib": "p5a77c9c35110e925"},
"id": "p7c9cab047dc7384e",
"name": "kryon",
"ref": "master",
"url": "https://github.com/kryonlabs/kryon.git"
},
{
"commit": "f5f0a19a5dc6c14a49adb3cd63ea79a60f6ba77b",
"dependencies": {},
@@ -95,7 +95,7 @@
},
{
"commit": "efe0ac0d83ec9c2ecb15a20a320994ca6fc347d2",
"dependencies": {"daochi_client": "p0cff069893bdc938", "kryon": "p7c9cab047dc7384e", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"},
"dependencies": {"daochi_client": "p0cff069893bdc938", "kryon": "p443f6238630e97c6", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"},
"id": "pabca5e1965868141",
"name": "Entity",
"ref": "master",
@@ -120,7 +120,7 @@
},
{
"commit": "4b0e25bd2df86b54a8f5af3db48282bd41daab1a",
"dependencies": {"kryon": "p7c9cab047dc7384e"},
"dependencies": {"kryon": "p443f6238630e97c6"},
"id": "pe8e21a1f2b5ff52c",
"name": "plot",
"ref": "master",
@@ -145,7 +145,7 @@
}
],
"root": {
"dependencies": {"apps": "p424eeb497051c0eb", "crypto": "pf039d7a776333200", "curl": "pd4bcd11b7d623073", "daochi_client": "p0cff069893bdc938", "entity": "pabca5e1965868141", "game2d": "p20eb23d3e6db3711", "kryon": "p7c9cab047dc7384e", "kss": "p1b13dda539ed2a39", "liboqs": "p4b0a50b49959e674", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pe8e21a1f2b5ff52c", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"},
"dependencies": {"apps": "p424eeb497051c0eb", "crypto": "pf039d7a776333200", "curl": "pd4bcd11b7d623073", "daochi_client": "p0cff069893bdc938", "entity": "pabca5e1965868141", "game2d": "p20eb23d3e6db3711", "kryon": "p443f6238630e97c6", "kss": "p1b13dda539ed2a39", "liboqs": "p4b0a50b49959e674", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pe8e21a1f2b5ff52c", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"},
"name": "Inbe"
},
"toolchain": {