Compare commits

..

5 commits

Author SHA1 Message Date
f973c30ddc
feat: highlight format and version info 2024-07-11 20:39:02 +04:00
4ed6418c28
fix: set max gap to scale/2 - 1 2024-07-11 20:17:48 +04:00
326844fe1c
feat: best scale auto-choose 2024-07-11 20:08:26 +04:00
a0259cc51d
fix: apply max-width including padding to all body>div-s
btw the fix doesn't work
so it's just a code cleanup
2024-07-11 20:01:23 +04:00
a6f1c1f49a
fix: correct description for gap
`gap=1px` means 1px around each module,
i.e. 2px between modules, not 1px.
yep, i know, such a bad name for this parameter,
but who cares?
2024-07-11 19:44:30 +04:00
3 changed files with 44 additions and 9 deletions

View file

@ -34,7 +34,7 @@
<label for="gap"> <label for="gap">
<span>Grid gap:</span> <span>Grid gap:</span>
<input id="gap" type="number" min="0" value="0"> <input id="gap" type="number" min="0" value="0">
px between modules px around
</label> </label>
<button id="gen-btn">Generate</button> <button id="gen-btn">Generate</button>
</div> </div>

View file

@ -64,7 +64,9 @@ addEventListener('DOMContentLoaded', () => {
const mask = options.mask.value const mask = options.mask.value
const size = Number(options.size.value) const size = Number(options.size.value)
const scale = Number(options.scale.value) const scale = Number(options.scale.value)
const gap = Math.min(Number(options.gap.value), scale) // not more than 1 module scaled size // not more than (half of 1 scaled module size) - 1
// at gap=scale/2 squares disappear
const gap = Math.min(Number(options.gap.value), intDiv(scale, 2) - 1)
const wh = scale - gap * 2 // width&height for 1 module with grid gap const wh = scale - gap * 2 // width&height for 1 module with grid gap
@ -122,14 +124,48 @@ addEventListener('DOMContentLoaded', () => {
} }
{ // format info { // format info
// TODO // ctx.fillStyle = "rgba(63, 149, 224, 0.5)"
ctx.fillStyle = "rgba(63, 203, 224, 0.5)"
ctx.fillRect(0, idSize, idSize, scale)
ctx.fillRect(idSize, 0, scale, idSize + scale)
ctx.fillRect(idSize, canvas.height - idSize, scale, idSize)
ctx.fillRect(canvas.width - idSize, idSize, idSize, scale)
}
if (ver >= 7) { // version info
ctx.fillStyle = "rgba(63, 224, 171, 0.5)"
const verWidth = 3 * scale
const verHeight = 6 * scale
const verBeginPos = canvas.width - idSize - verWidth
ctx.fillRect(verBeginPos, 0, verWidth, verHeight)
ctx.fillRect(0, verBeginPos, verHeight, verWidth)
} }
}) })
{ // Choose best scale for screen height { // Choose best scale for screen height
const height = document.documentElement.clientHeight; let padding = getComputedStyle(document.body).paddingBottom
const padding = getComputedStyle(document.body).paddingTop; // remove `px` at the end and convert to number
// TODO padding = Number(padding.slice(0, padding.length - 2))
// compute available height
const height =
document.documentElement.clientHeight
- canvas.offsetTop // substract height of everything above canvas
- padding // substract body padding
const width =
document.documentElement.clientWidth
- padding * 2
options.scale.value = Math.max(
intDiv(
width < height ? width : height,
25, // divide least dimension by QR version 2 size
),
10, // minimum scale for this auto-detect algorithm
)
} }
{ // QR version related stuff { // QR version related stuff

View file

@ -6,14 +6,13 @@ body {
body > div { body > div {
width: fit-content; width: fit-content;
margin: auto; margin: auto;
max-width: calc(100vw - 0.5rem * 2);
} }
body > div#options { #options {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: 0.25rem; row-gap: 0.25rem;
max-width: calc(100vw - 0.5rem * 2);
} }
select, input, button { select, input, button {