Fix widget resizing handles, edge anchoring, scroll sync, and axis limits
This commit is contained in:
1 parent
216c80252d
commit
bb978fd6de
13 files changed
+538
-76
No files matched your search
+183
-3
@@ -42,6 +42,7 @@ fn Sim::new() -> Sim {
|
||||
grid_top=150.0,
|
||||
grid_w=358.0,
|
||||
bottom_pad=24.0,
|
||||
scroll_y=0.0,
|
||||
),
|
||||
)
|
||||
s.send(AppsLoaded(Some(apps_json)))
|
||||
@@ -600,8 +601,10 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
|
||||
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
|
||||
assert_eq(s.m.resizing, 0) // no item menu for a widget: handles
|
||||
assert_eq(s.m.sheet, NoSheet)
|
||||
assert_true(s.has_effect(QueryLimits(100))) // queried immediately on entering resize mode
|
||||
let html = @vdom.to_html(s.tree[0])
|
||||
assert_true(html.contains("resize-handle"))
|
||||
assert_true(@vdom.to_html(s.tree[1]).contains("5 × 2"))
|
||||
assert_true(
|
||||
@vdom.to_html(s.tree[1]).contains(
|
||||
"Drag to move, or drag the handles to resize",
|
||||
@@ -612,10 +615,10 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
|
||||
.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)
|
||||
s.release()
|
||||
assert_eq(s.m.home[0].rows, 4)
|
||||
assert_true(@vdom.to_html(s.tree[1]).contains("5 × 4"))
|
||||
assert_eq(s.m.resizing, 0) // handles stay
|
||||
// the right handle to three columns (the widget starts the full row)
|
||||
let rc = s
|
||||
@@ -626,6 +629,7 @@ test "a widget: hold opens resize handles; drag the handles; Done" {
|
||||
s.move_to(c3x + 36.0, 170.0)
|
||||
s.release()
|
||||
assert_eq(s.m.home[0].w, 3)
|
||||
assert_true(@vdom.to_html(s.tree[1]).contains("3 × 4"))
|
||||
// pressing the widget's body picks it up at once; letting go keeps the handles
|
||||
let wc = s.chain("widget-slot")
|
||||
s.press(wc, x=wx, y=wy)
|
||||
@@ -656,10 +660,19 @@ test "resizing stays within the widget's limits" {
|
||||
)
|
||||
let (wx, wy) = cell_center(2, 0)
|
||||
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
|
||||
let html = @vdom.to_html(s.tree[0])
|
||||
assert_true(
|
||||
html.contains("data-edge=\"l\"") && html.contains("data-edge=\"r\""),
|
||||
)
|
||||
assert_true(
|
||||
!html.contains("data-edge=\"t\"") &&
|
||||
!html.contains("data-edge=\"b\"") &&
|
||||
!html.contains("data-edge=\"rb\""),
|
||||
)
|
||||
let rc = s
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "rb")) })
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) })
|
||||
.unwrap()
|
||||
s.press(rc, x=370.0, y=250.0)
|
||||
s.press(rc, x=370.0, y=200.0)
|
||||
s.move_to(60.0, 600.0) // far left and down
|
||||
s.release()
|
||||
assert_eq(s.m.home[0].w, 3) // 3 columns = 204px, the nearest to 200 within the limit
|
||||
@@ -990,3 +1003,170 @@ test "top-level view nodes have distinct non-zero keys" {
|
||||
}
|
||||
assert_eq(keys, [1, 2, 3, 4, 6])
|
||||
}
|
||||
|
||||
///|
|
||||
test "left/right/top/bottom resize anchors opposite edge and pins unpinned widget" {
|
||||
let s = Sim::new()
|
||||
s.add_apps(["Chrome", "Gmail", "Phone"])
|
||||
s.send(PickWidget)
|
||||
s.send(WidgetsLoaded(Some(widgets_json)))
|
||||
s.send(ChooseWidget(0))
|
||||
s.send(WidgetAdded(100))
|
||||
s.send(
|
||||
LimitsKnown(
|
||||
100,
|
||||
Some("{\"w\":130,\"minW\":64,\"minH\":64,\"h\":true,\"v\":true}"),
|
||||
),
|
||||
)
|
||||
// Unpinned 2x2 widget starts at (3, 0) beside the 3 apps; resizing Right pins it at (3, 0)
|
||||
// and widening past the right edge caps at 5 - 3 = 2 columns without shifting x or jumping rows
|
||||
assert_eq((s.m.home[3].x, s.m.home[3].y, s.m.home[3].w), (-1, -1, 2))
|
||||
let (wx, wy) = cell_center(3, 0)
|
||||
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
|
||||
let rc = s
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "r")) })
|
||||
.unwrap()
|
||||
s.press(rc, x=374.0, y=200.0)
|
||||
s.move_to(520.0, 200.0)
|
||||
s.release()
|
||||
assert_eq((s.m.home[3].x, s.m.home[3].y, s.m.home[3].w), (3, 0, 2))
|
||||
|
||||
// Place widget at (2, 2) and test Left + Top handles keeping right/bottom anchored
|
||||
s.m.home[3].x = 2
|
||||
s.m.home[3].y = 2
|
||||
s.m.home[3].w = 2
|
||||
s.m.home[3].rows = 2
|
||||
s.refresh()
|
||||
let lc = s
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "l")) })
|
||||
.unwrap()
|
||||
let (c1x, c2y) = cell_center(1, 2)
|
||||
s.press(lc, x=c1x + 40.0, y=c2y)
|
||||
s.move_to(c1x - 32.0, c2y) // grow left by 1 col -> (1, 2), w=3 (right_col stays 4)
|
||||
assert_eq((s.m.home[3].x, s.m.home[3].w), (1, 3))
|
||||
s.move_to(-100.0, c2y) // clamp at col 0 -> (0, 2), w=4 (right_col stays 4)
|
||||
assert_eq((s.m.home[3].x, s.m.home[3].w), (0, 4))
|
||||
let (c2x, _) = cell_center(2, 2)
|
||||
s.move_to(c2x + 40.0, c2y) // shrink back to 1 col -> (3, 2), w=1 (right_col stays 4)
|
||||
s.release()
|
||||
assert_eq((s.m.home[3].x, s.m.home[3].w), (3, 1))
|
||||
|
||||
let tc = s
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "t")) })
|
||||
.unwrap()
|
||||
let (c3x, c1y) = cell_center(3, 1)
|
||||
s.press(tc, x=c3x, y=150.0 + 2.0 * 72.0)
|
||||
s.move_to(c3x, c1y - 24.0) // grow up by 1 row -> row 1, rows=3 (bottom_row stays 4)
|
||||
assert_eq((s.m.home[3].y, s.m.home[3].rows), (1, 3))
|
||||
s.move_to(c3x, -50.0) // clamp at row 0 -> row 0, rows=4 (bottom_row stays 4)
|
||||
assert_eq((s.m.home[3].y, s.m.home[3].rows), (0, 4))
|
||||
let (_, c3y) = cell_center(3, 3)
|
||||
s.move_to(c3x, c3y - 24.0) // shrink down to 1 row -> row 3, rows=1 (bottom_row stays 4)
|
||||
s.release()
|
||||
assert_eq((s.m.home[3].y, s.m.home[3].rows), (3, 1))
|
||||
}
|
||||
|
||||
///|
|
||||
test "holding a resize handle for 500ms does not lift widget or corrupt resize state" {
|
||||
let s = Sim::new()
|
||||
s.send(PickWidget)
|
||||
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}"),
|
||||
),
|
||||
)
|
||||
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", "r")) })
|
||||
.unwrap()
|
||||
s.press(rc, x=370.0, y=170.0)
|
||||
s.hold()
|
||||
assert_eq(s.m.resizing, 0)
|
||||
assert_eq(s.m.lifted, -1)
|
||||
assert_true(s.m.resize is Some(_))
|
||||
let (c2x, _) = cell_center(1, 0)
|
||||
s.move_to(c2x + 36.0, 170.0)
|
||||
s.release()
|
||||
assert_eq(s.m.home[0].w, 2)
|
||||
assert_eq(s.m.resizing, 0)
|
||||
assert_eq(s.m.lifted, -1)
|
||||
assert_eq(s.m.sheet, NoSheet)
|
||||
}
|
||||
|
||||
///|
|
||||
test "scrolled Measured keeps nrows constant and resizes in viewport coordinates" {
|
||||
let s = Sim::new()
|
||||
s.send(PickWidget)
|
||||
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}"),
|
||||
),
|
||||
)
|
||||
let unscrolled_rows = s.m.nrows
|
||||
// Scrolled down 200px: grid_top in viewport moved from 150 to -50
|
||||
s.send(
|
||||
Measured(
|
||||
vw=390,
|
||||
vh=800,
|
||||
grid_left=16.0,
|
||||
grid_top=-50.0,
|
||||
grid_w=358.0,
|
||||
bottom_pad=24.0,
|
||||
scroll_y=200.0,
|
||||
),
|
||||
)
|
||||
assert_eq(s.m.nrows, unscrolled_rows)
|
||||
let (wx, wy) = cell_center(2, 0)
|
||||
s.long_press(s.chain("widget-slot"), x=wx, y=wy - 200.0)
|
||||
let bc = s
|
||||
.chain_where(fn(e) { e.attrs.contains(("data-edge", "b")) })
|
||||
.unwrap()
|
||||
s.press(bc, x=100.0, y=-50.0 + 2.0 * 72.0)
|
||||
s.move_to(100.0, -50.0 + 3.0 * 72.0 - 8.0) // 3 rows in scrolled viewport coords
|
||||
s.release()
|
||||
assert_eq(s.m.home[0].rows, 3)
|
||||
}
|
||||
|
||||
///|
|
||||
test "only supported resize handles render per widget resizeMode" {
|
||||
let s = Sim::new()
|
||||
s.send(PickWidget)
|
||||
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\":false,\"v\":true}"),
|
||||
),
|
||||
)
|
||||
let (wx, wy) = cell_center(2, 0)
|
||||
s.long_press(s.chain("widget-slot"), x=wx, y=wy)
|
||||
let v_only = @vdom.to_html(s.tree[0])
|
||||
assert_true(
|
||||
v_only.contains("data-edge=\"t\"") && v_only.contains("data-edge=\"b\""),
|
||||
)
|
||||
assert_true(
|
||||
!v_only.contains("data-edge=\"l\"") &&
|
||||
!v_only.contains("data-edge=\"r\"") &&
|
||||
!v_only.contains("data-edge=\"rb\""),
|
||||
)
|
||||
s.send(
|
||||
LimitsKnown(
|
||||
100,
|
||||
Some("{\"w\":0,\"minW\":64,\"minH\":64,\"h\":false,\"v\":false}"),
|
||||
),
|
||||
)
|
||||
s.refresh()
|
||||
let none_html = @vdom.to_html(s.tree[0])
|
||||
assert_true(!none_html.contains("resize-handle"))
|
||||
}
|
||||
Reference in new issue
Block a user