Skip to content

Instantly share code, notes, and snippets.

@radames
Created May 24, 2023 06:48
Show Gist options
  • Save radames/f79935961f269a0631a41208e60ecb48 to your computer and use it in GitHub Desktop.
Save radames/f79935961f269a0631a41208e60ecb48 to your computer and use it in GitHub Desktop.
Amethyst Custom Layout Simple Square Grid
function layout() {
return {
name: "Grid",
getFrameAssignments: (windows, screenFrame) => {
const numWindows = windows.length;
const numRows = Math.floor(Math.sqrt(numWindows));
const numCols = Math.ceil(Math.sqrt(numWindows));
const cellWidth = screenFrame.width / numCols;
const cellHeight = screenFrame.height / numRows;
const frames = windows.map((window, index) => {
const row = Math.floor(index / numCols);
const col = index % numCols;
const frame = {
x: screenFrame.x + (cellWidth * col),
y: screenFrame.y + (cellHeight * row),
width: cellWidth,
height: cellHeight
};
return { [window.id]: frame };
});
return frames.reduce((frames, frame) => ({ ...frames, ...frame }), {});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment