The first public release of Fabled Minstrel #158
@@ -6,6 +6,7 @@ import {
|
||||
refreshedLabel,
|
||||
shelfMeta,
|
||||
shelfTileWidth,
|
||||
MAX_TILE_GROWTH,
|
||||
songsLikeArtist,
|
||||
washTone
|
||||
} from './shelf.js';
|
||||
@@ -148,9 +149,14 @@ describe('shelfTileWidth', () => {
|
||||
expect(cols * w + (cols - 1) * 16).toBeGreaterThan(1000 - cols);
|
||||
});
|
||||
|
||||
test('a short shelf splits the whole width between its items', () => {
|
||||
expect(shelfTileWidth(1000, 2, 150, 16)).toBe(492);
|
||||
test('a short shelf splits the width between its items', () => {
|
||||
expect(shelfTileWidth(400, 2, 150, 16)).toBe(192);
|
||||
expect(shelfTileWidth(1000, 3, 300, 16)).toBe(322);
|
||||
});
|
||||
|
||||
test('a tile on a near-empty shelf stops growing at twice its minimum', () => {
|
||||
expect(shelfTileWidth(1400, 1, 144, 16)).toBe(144 * MAX_TILE_GROWTH);
|
||||
expect(shelfTileWidth(1000, 2, 150, 16)).toBe(150 * MAX_TILE_GROWTH);
|
||||
});
|
||||
|
||||
test('a narrow window still gets one tile at the min', () => {
|
||||
|
||||
@@ -123,13 +123,17 @@ function fromHsl(h: number, s: number, l: number): { r: number; g: number; b: nu
|
||||
};
|
||||
}
|
||||
|
||||
// How wide each tile on a shelf is, so the shelf's tiles always fill its
|
||||
// width: as many columns as fit at `min` pixels, each grown to share the
|
||||
// width. A shelf with fewer items than that splits the whole width between
|
||||
// the items it has, so no shelf ends partway across the page.
|
||||
// How wide each tile on a shelf is, so the shelf's tiles fill its width: as
|
||||
// many columns as fit at `min` pixels, each grown to share the width. A shelf
|
||||
// with fewer items than that splits the width between the items it has, but
|
||||
// no tile grows past MAX_TILE_GROWTH times `min`: a lone album on a wide
|
||||
// window would otherwise become a cover the size of the page.
|
||||
export const MAX_TILE_GROWTH = 2;
|
||||
|
||||
export function shelfTileWidth(width: number, count: number, min: number, gap: number): number {
|
||||
if (width <= 0) return min;
|
||||
let cols = Math.max(1, Math.floor((width + gap) / (min + gap)));
|
||||
if (count > 0 && count < cols) cols = count;
|
||||
return Math.max(min, Math.floor((width - (cols - 1) * gap) / cols));
|
||||
const shared = Math.floor((width - (cols - 1) * gap) / cols);
|
||||
return Math.max(min, Math.min(shared, min * MAX_TILE_GROWTH));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user