Skip to content

Commit

Permalink
🎨 Added active highlight to pattern btns
Browse files Browse the repository at this point in the history
  • Loading branch information
typio committed Mar 7, 2024
1 parent 68836b5 commit e6b9865
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ const setCanvasDimensions = () => {

window.addEventListener("resize", setCanvasDimensions)

EXAMPLE_PATTERNS.forEach((p) => {
EXAMPLE_PATTERNS.forEach((p, i) => {
const patternButtonElement = document.createElement("button")
if (i == 0) {
patternButtonElement.style.outline = "2px solid white"
}
patternButtonElement.classList.add("btn")
patternButtonElement.innerText = p.name
patternButtonElement.addEventListener("click", () => {
// TODO: There's definitely a better way to do this w/o allocating
// cause I just copy it into the same fixed buffer
// cause I just copy it into the same wasm fixed buffer
const rleBuffer = Uint8Array.from(
Array.from(p.rle).map((letter) => letter.charCodeAt(0)),
)
Expand All @@ -85,8 +88,13 @@ EXAMPLE_PATTERNS.forEach((p) => {
mem.set(new Uint8Array(rleBuffer))

instance.exports.select_pattern(ptr)
console.log(p.rle, p.rle.length)

for (const button of patternPaletteElement.children) {
button.style.outline = "none"
}
patternButtonElement.style.outline = "2px solid white"
})

patternPaletteElement.appendChild(patternButtonElement)
})

Expand Down

0 comments on commit e6b9865

Please sign in to comment.