Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-23 01:08:53 +00:00
1 parent dccbfd7d86
commit 17f81c60c8
20 files changed
+636 -447

No files matched your search

+111 -31
View File
@@ -32,9 +32,18 @@ struct Sim {
///|
fn Sim::new() -> Sim {
let m = Model::new()
let s = { m, tree: [], table: [], log: [], last_x: 0.0, last_y: 0.0 }
let s = { m, tree: [], table: [], log: [], last_x: 0.0, last_y: 0.0, }
s.run(update(m, Restore(saved=None, legacy=None)))
s.send(Measured(vw=390, vh=800, grid_left=16.0, grid_top=150.0, grid_w=358.0, bottom_pad=24.0))
s.send(
Measured(
vw=390,
vh=800,
grid_left=16.0,
grid_top=150.0,
grid_w=358.0,
bottom_pad=24.0,
),
)
s.send(AppsLoaded(Some(apps_json)))
s
}
@@ -71,11 +80,11 @@ fn text_of(n : @vdom.Node[Msg]) -> String {
fn Sim::chain_where(
self : Sim,
pred : (@vdom.Element[Msg]) -> Bool,
from? : Int = 0,
) -> Array[Int]? {
from~ : Int32 = 0,
) -> Array[Int32]? {
let mut counter = 0
let mut found : Array[Int]? = None
let stack : Array[Int] = []
let mut found : Array[Int32]? = None
let stack : Array[Int32] = []
fn walk(n : @vdom.Node[Msg]) -> Unit {
if found is Some(_) {
return
@@ -128,9 +137,9 @@ fn walk_count(n : @vdom.Node[Msg], bump : () -> Unit) -> Unit {
fn Sim::chain(
self : Sim,
class : String,
label? : String = "",
from? : Int = 0,
) -> Array[Int] {
label~ : String = "",
from~ : Int32 = 0,
) -> Array[Int32] {
match
self.chain_where(from~, fn(e) {
e.classes.contains(class) &&
@@ -147,7 +156,12 @@ fn Sim::feed(self : Sim, inp : @gesture.Input) -> Unit {
}
///|
fn Sim::press(self : Sim, chain : Array[Int], x? : Double = 0.0, y? : Double = 0.0) -> Unit {
fn Sim::press(
self : Sim,
chain : Array[Int32],
x~ : Double = 0.0,
y~ : Double = 0.0,
) -> Unit {
self.feed(Down(x~, y~, chain~))
self.last_x = x
self.last_y = y
@@ -180,15 +194,20 @@ fn Sim::release(self : Sim) -> Unit {
fn Sim::tap(
self : Sim,
class : String,
label? : String = "",
from? : Int = 0,
label~ : String = "",
from~ : Int32 = 0,
) -> Unit {
self.press(self.chain(class, label~, from~))
self.release()
}
///|
fn Sim::long_press(self : Sim, chain : Array[Int], x? : Double = 0.0, y? : Double = 0.0) -> Unit {
fn Sim::long_press(
self : Sim,
chain : Array[Int32],
x~ : Double = 0.0,
y~ : Double = 0.0,
) -> Unit {
self.press(chain, x~, y~)
self.hold()
self.release()
@@ -223,7 +242,7 @@ fn Sim::has_effect(self : Sim, e : Effect) -> Bool {
///|
/// Centre of the cell (col, row) in viewport px.
fn cell_center(col : Int, row : Int) -> (Double, Double) {
fn cell_center(col : Int32, row : Int32) -> (Double, Double) {
(
16.0 + col.to_double() * (65.2 + 8.0) + 32.6,
150.0 + row.to_double() * 72.0 + 32.0,
@@ -321,7 +340,12 @@ test "search filters the drawer; Enter opens the first match" {
assert_eq(names().length(), 6)
let input_chain = s.chain("input")
s.run(typed(s.m, s.table, input_chain, "ca"))
assert_eq(names(), ["Calculator", "Calendar", "Camera".to_string()].filter(fn(x) { x != "Camera" }))
assert_eq(
names(),
["Calculator", "Calendar", "Camera".to_string()].filter(fn(x) {
x != "Camera"
}),
)
s.run(typed(s.m, s.table, input_chain, " CAL"))
assert_eq(names(), ["Calculator", "Calendar"])
s.run(key(s.m, s.table, input_chain, Enter))
@@ -383,7 +407,13 @@ test "uninstall asks the shell; the slot goes when the app leaves the list" {
s.tap("sheet-item", label="Uninstall")
assert_true(s.has_effect(Uninstall("c.gmail/.Main")))
assert_eq(s.home_names(), ["Gmail"])
s.send(AppsLoaded(Some("{\"apps\":[{\"label\":\"Chrome\",\"component\":\"c.chrome/.Main\",\"icon\":\"\"}]}")))
s.send(
AppsLoaded(
Some(
"{\"apps\":[{\"label\":\"Chrome\",\"component\":\"c.chrome/.Main\",\"icon\":\"\"}]}",
),
),
)
assert_eq(s.m.home.length(), 0)
}
@@ -437,8 +467,8 @@ test "an app dropped in an empty cell stays there; the rest stay packed" {
assert_eq(s.home_names(), ["Chrome", "Gmail", "Phone"])
assert_eq((s.m.home[2].x, s.m.home[2].y), (3, 2))
let cells = s.m.packed().cells
assert_eq(cells[0], Some({ col: 0, row: 0, w: 1, h: 1 }))
assert_eq(cells[2], Some({ col: 3, row: 2, w: 1, h: 1 }))
assert_eq(cells[0], Some({ col: 0, row: 0, w: 1, h: 1, }))
assert_eq(cells[2], Some({ col: 3, row: 2, w: 1, h: 1, }))
// and it survives a save and a load
let back = load_json(save_json(s.m.home), Ref::new(1)).unwrap()
assert_eq((back[2].x, back[2].y), (3, 2))
@@ -452,7 +482,7 @@ test "dropping a pinned app onto another pinned one moves that one on" {
let from = cell_center(0, 0) // Gmail flows up into the first cell once Chrome is pinned
let (fx, fy) = from
let (tx, ty) = cell_center(col, row)
s.press(s.chain("tile", label=label), x=fx, y=fy)
s.press(s.chain("tile", label~), x=fx, y=fy)
s.hold()
s.move_to(tx, ty)
s.release()
@@ -495,7 +525,11 @@ test "add a widget: picker search, choose, shell adds it" {
s.run(typed(s.m, s.table, c, "zzz"))
assert_true(s.sheet_html().contains("No widgets match."))
s.run(typed(s.m, s.table, c, ""))
s.press(s.chain_where(fn(e) { e.tag == "li" && text_of(El(e)).contains("Clock") }).unwrap())
s.press(
s
.chain_where(fn(e) { e.tag == "li" && text_of(El(e)).contains("Clock") })
.unwrap(),
)
s.release()
assert_true(s.has_effect(AddWidget("c.clock/.W")))
s.send(WidgetAdded(100))
@@ -504,7 +538,12 @@ test "add a widget: picker search, choose, shell adds it" {
assert_eq(s.m.home[1].rows, 2) // 140px: two rows
assert_true(s.has_effect(QueryLimits(100)))
// its natural width sets the starting columns: 110px wide = 2 columns
s.send(LimitsKnown(100, Some("{\"w\":110,\"minW\":110,\"minH\":80,\"h\":true,\"v\":true}")))
s.send(
LimitsKnown(
100,
Some("{\"w\":110,\"minW\":110,\"minH\":80,\"h\":true,\"v\":true}"),
),
)
assert_eq(s.m.home[1].w, 2)
let html = @vdom.to_html(s.tree[0])
assert_true(html.contains("data-wid=\"100\""))
@@ -530,7 +569,12 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
s.send(WidgetsLoaded(Some(widgets_json)))
s.send(ChooseWidget(0))
s.send(WidgetAdded(100))
s.send(LimitsKnown(100, Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}")))
s.send(
LimitsKnown(
100,
Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"),
),
)
assert_eq(s.m.home[0].w, 0)
let (wx, wy) = cell_center(2, 0)
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
@@ -538,9 +582,15 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
assert_eq(s.m.sheet, NoSheet)
let html = @vdom.to_html(s.tree[0])
assert_true(html.contains("resize-handle"))
assert_true(@vdom.to_html(s.tree[1]).contains("Drag to move, or drag the handles to resize"))
assert_true(
@vdom.to_html(s.tree[1]).contains(
"Drag to move, or drag the handles to resize",
),
)
// drag the bottom handle down to the fourth row
let hc = s.chain_where(fn(e) { e.attrs.contains(("data-edge", "b")) }).unwrap()
let hc = s
.chain_where(fn(e) { e.attrs.contains(("data-edge", "b")) })
.unwrap()
s.press(hc, x=100.0, y=150.0 + 2.0 * 72.0 + 70.0)
assert_true(s.has_effect(QueryLimits(100)))
s.move_to(100.0, 150.0 + 3.0 * 72.0 + 40.0)
@@ -548,7 +598,9 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
assert_eq(s.m.home[0].rows, 4)
assert_eq(s.m.resizing, 0) // handles stay
// the right handle to three columns (the widget starts the full row)
let rc = s.chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) }).unwrap()
let rc = s
.chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) })
.unwrap()
s.press(rc, x=370.0, y=170.0)
let (c3x, _) = cell_center(2, 0)
s.move_to(c3x + 36.0, 170.0)
@@ -574,10 +626,19 @@ test "resizing stays within the widget's limits" {
s.send(WidgetsLoaded(Some(widgets_json)))
s.send(ChooseWidget(0))
s.send(WidgetAdded(100))
s.send(LimitsKnown(100, Some("{\"w\":0,\"minW\":200,\"maxW\":220,\"minH\":64,\"h\":true,\"v\":false}")))
s.send(
LimitsKnown(
100,
Some(
"{\"w\":0,\"minW\":200,\"maxW\":220,\"minH\":64,\"h\":true,\"v\":false}",
),
),
)
let (wx, wy) = cell_center(2, 0)
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
let rc = s.chain_where(fn(e) { e.attrs.contains(("data-edge", "rb")) }).unwrap()
let rc = s
.chain_where(fn(e) { e.attrs.contains(("data-edge", "rb")) })
.unwrap()
s.press(rc, x=370.0, y=250.0)
s.move_to(60.0, 600.0) // far left and down
s.release()
@@ -592,7 +653,12 @@ test "a native widget view lifts, drags and drops its slot" {
s.send(WidgetsLoaded(Some(widgets_json)))
s.send(ChooseWidget(2))
s.send(WidgetAdded(7))
s.send(LimitsKnown(7, Some("{\"w\":130,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}")))
s.send(
LimitsKnown(
7,
Some("{\"w\":130,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"),
),
)
assert_eq(s.m.home[0].w, 2)
s.send(WidgetMenu(7))
assert_eq(s.m.lifted, 0)
@@ -675,7 +741,10 @@ test "the old WebView build's home screen is brought over once" {
let slots = legacy_import(legacy, next)
assert_eq(slots.length(), 2)
assert_eq((slots[0].kind, slots[0].str), (App, "c.chrome/.Main"))
assert_eq((slots[1].wid, slots[1].w, slots[1].rows, slots[1].x, slots[1].y), (12, 3, 2, 1, 2))
assert_eq(
(slots[1].wid, slots[1].w, slots[1].rows, slots[1].x, slots[1].y),
(12, 3, 2, 1, 2),
)
assert_eq(legacy_import("{}", Ref::new(1)).length(), 0)
assert_eq(legacy_import("garbage", Ref::new(1)).length(), 0)
let s = Sim::new()
@@ -684,7 +753,15 @@ test "the old WebView build's home screen is brought over once" {
assert_true(s.log.contains(SaveHome(save_json(s.m.home)))) // saved in the new format
// a saved layout wins over the old one
let s2 = Sim::new()
s2.run(update(s2.m, Restore(saved=Some(save_json([slot_app("c.gmail/.Main")])), legacy=Some(legacy))))
s2.run(
update(
s2.m,
Restore(
saved=Some(save_json([slot_app("c.gmail/.Main")])),
legacy=Some(legacy),
),
),
)
assert_eq(s2.m.home.length(), 1)
}
@@ -697,7 +774,10 @@ fn slot_app(c : String) -> @grid.Slot {
test "load_json rejects what is not a layout and drops nameless slots" {
assert_true(load_json("nope", Ref::new(1)) is None)
assert_true(load_json("{}", Ref::new(1)) is None)
let r = load_json("{\"slots\":[{\"kind\":\"app\"},{\"kind\":\"app\",\"str\":\"a\"}]}", Ref::new(1)).unwrap()
let r = load_json(
"{\"slots\":[{\"kind\":\"app\"},{\"kind\":\"app\",\"str\":\"a\"}]}",
Ref::new(1),
).unwrap()
assert_eq(r.length(), 1)
}