Created
May 24, 2023 06:48
-
-
Save radames/f79935961f269a0631a41208e60ecb48 to your computer and use it in GitHub Desktop.
Amethyst Custom Layout Simple Square Grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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