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

Support high DPI screens #18

Merged
merged 1 commit into from
Nov 3, 2020
Merged
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
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const editor = document.getElementById('editor');
const comment = document.getElementById('comment');
const output = document.getElementById('output');
const context = output.getContext('2d');
const dpr = window.devicePixelRatio || 1;

let callback = function() {};
let startTime = new Date();
let code = '';

output.width = output.height = width;
output.width = output.height = width * dpr;
context.scale(dpr,dpr);
output.style.width = output.style.height = `${width}px`;
Copy link

@p01 p01 Nov 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: We should skip the line setting the output.style.foo, and instead size the canvas and form elements using vmin or similar viewport unit.

With this change the size of the canvas will adapt to the DPR but not the actual viewport size. Furthermore, it can end up having a different size than the labels and form inputs below.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the type of CSS change I mean,

style.styl

html {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 90%;
  background: #000;
  color: #fff;
}

body {
  margin: 0;
  width: 64vmin;
  height: 76vmin;
}

* {
  font-size: 2vmin;
  font-family: monospace;
  line-height: 2vmin;
}

canvas,form,input,label {
  padding: 0;
  background: transparent;
  width: 64vmin;
  display: block;
  margin: 0 auto;
  color: inherit;
  border: none; 
}

#output {
  height: 64vmin;
  margin-bottom: 4vmin;
  background: #222;
}

#comment * {
  color: #F24;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are great suggestions, but probably for a subsequent PR

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair
I filed the PR #19 ;)


const cells = [];

Expand Down Expand Up @@ -85,7 +88,8 @@ function render() {
return;
}

output.width = output.height = width;
output.width = output.height = width * dpr;
context.scale(dpr,dpr)
let index = 0;
for (let y = 1; y <= count; y++) {
for (let x = 1; x <= count; x++) {
Expand Down