Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile friendly ish #9

Merged
merged 5 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>WebGL Testing</title>
</head>
<body>
Expand Down
28 changes: 27 additions & 1 deletion apps/web/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,34 @@ aside canvas {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.open-picker-button {
display: none;
}

@media (max-width: 800px) {
body {
flex-direction: column;
flex-direction: column-reverse;
overflow: hidden;
}
.open-picker-button {
display: inherit;
}
body.picker-open .open-picker-button {
display: none;
}
aside {
padding-bottom: 0;
}
aside canvas {
display: none;
}
body.picker-open aside {
flex: 1;
}
body.picker-open aside canvas {
display: block;
}
body.picker-open main {
display: none;
}
}
4 changes: 4 additions & 0 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ const baseUrl = process.env.BASE_URL ?? "/"
export default defineConfig({
base: baseUrl.startsWith("/") ? baseUrl : `/${baseUrl}`,
plugins: [plainText(["**/*.glsl"], { namedExport: false })],
// bind on any IP address
server: {
host: true,
},
})
8 changes: 8 additions & 0 deletions libs/color-picker/src/lib/ColorPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ export class ColorPicker {
this.onChange = onChange
const { canvas, gl } = this.createCanvas()
this.root.appendChild(canvas)
const openPickerButton = document.createElement("button")
openPickerButton.classList.add("open-picker-button")
openPickerButton.innerText = "color picker"
this.root.appendChild(openPickerButton)

this.program = new GradientColorProgram(gl)
this.program.draw()

openPickerButton.addEventListener("click", () => {
document.body.classList.toggle("picker-open")
})
canvas.addEventListener("click", (e) => {
const color = this.getCanvasColor(e)
this.onChange(color)
document.body.classList.remove("picker-open")
})
}

Expand Down
15 changes: 12 additions & 3 deletions libs/webgl/src/WebDrawingApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ export class WebDrawingApp {
}

private addEventListeners() {
this.addListener("pointerdown", ({ position }) => {
this.addListener("pointerdown", ({ position, event }) => {
if (event.isPrimary === false) {
return
}
this.engine.setPressed(true, position)
this.canvas.style.setProperty("cursor", "none")
})
this.addListener("pointermove", ({ position }) => {
this.addListener("pointermove", ({ position, event }) => {
if (event.isPrimary === false) {
return
}
this.engine.addPosition(position)
})
this.addListener("pointerup", ({ position }) => {
this.addListener("pointerup", ({ position, event }) => {
if (event.isPrimary === false) {
return
}
this.engine.setPressed(false, position)
this.canvas.style.removeProperty("cursor")
})
Expand Down