forked from Blendman974/faceclaw
Add partial rows and a bounce effect to menus
This commit is contained in:
1 parent
c801bd5185
commit
f66e0b025f
14 files changed
+259
-85
No files matched your search
@@ -168,11 +168,13 @@ test('setItems keeps the index by default, takes an explicit one, and holds the
|
||||
assert.equal(menu.selectedIndex, 1, 'an out-of-range index clamps');
|
||||
});
|
||||
|
||||
test('variable heights: the layout follows getHeight and partial rows are hidden', () => {
|
||||
test('variable heights: the layout follows getHeight and partial rows are clipped', () => {
|
||||
const heights = { a: 10, b: 30, c: 15, d: 40, e: 5 };
|
||||
const { menu, paint } = stringMenu({ getHeight: (item) => heights[item] });
|
||||
let rows = paint();
|
||||
assert.deepEqual(rows.map((r) => [r.item, r.y, r.height]), [['a', 0, 10], ['b', 15, 30], ['c', 45, 15]]);
|
||||
assert.deepEqual(rows.map((r) => [r.item, r.y, r.height, r.scratch]),
|
||||
[['a', 0, 10, true], ['b', 15, 30, false], ['c', 45, 15, false], ['d', 0, 40, true]],
|
||||
'd is drawn in a scratch image and clipped to the viewport');
|
||||
menu.select(3);
|
||||
rows = paint();
|
||||
assert.equal(menu.scrollTop, 40, 'aligned to the top of row c');
|
||||
@@ -180,6 +182,16 @@ test('variable heights: the layout follows getHeight and partial rows are hidden
|
||||
assert.equal(menu.overflows, true);
|
||||
});
|
||||
|
||||
test('a partially visible row shows only its top, hinting at more rows', () => {
|
||||
const menu = new Menu({ items: ['a', 'b', 'c', 'd'], getHeight: () => 20,
|
||||
draw: ({ image, x, y, width, height }) => image.fillRect(x, y, width, height, 200) });
|
||||
const image = new GrayImage(20, 60);
|
||||
menu.paint(image, { x: 0, y: 5, width: 20, height: 50 }, true);
|
||||
const column = Array.from({ length: 60 }, (_, y) => image.pixels[y * 20]);
|
||||
assert.deepEqual(column.slice(25, 55), new Array(30).fill(200), 'rows b and the top half of c');
|
||||
assert.deepEqual(column.slice(55), new Array(5).fill(0), 'nothing below the box');
|
||||
});
|
||||
|
||||
test('a selected row taller than the box is drawn from its top', () => {
|
||||
const { menu, paint } = stringMenu({ getHeight: (item) => (item === 'c' ? 90 : 20) });
|
||||
menu.select(2);
|
||||
|
||||
Reference in new issue
Block a user