added dark mode and margin changes

This commit is contained in:
David Meincke
2022-03-22 22:14:38 +01:00
parent 31722d4bf4
commit f25f3daf7f
8 changed files with 92 additions and 15 deletions
+1 -1
View File
@@ -6,6 +6,6 @@
<code-editor style="min-width: 50%; max-width: 50%;"></code-editor> <code-editor style="min-width: 50%; max-width: 50%;"></code-editor>
<output-frame></output-frame> <output-frame></output-frame>
</div> </div>
<div class="flex-shrink section bottom">methods: rect, box, center, width, height</div> <div class="flex-shrink section bottom">methods: rect, box, center, width, height, rand</div>
</div> </div>
<notification-bubbles></notification-bubbles> <notification-bubbles></notification-bubbles>
+21 -1
View File
@@ -60,7 +60,27 @@ body {
} }
.section.bottom { .section.bottom {
padding: 10px;
border-top: 1px solid #c2c2c2; border-top: 1px solid #c2c2c2;
font-size: 16px; font-size: 14px;
text-align: right; text-align: right;
} }
@media (prefers-color-scheme: dark) {
body {
background: #1e1e1e;
}
.section {
color: white;
background: #2e2e2e;
}
.section.top {
border-color: #292929;
}
.section.bottom {
border-color: #292929;
}
}
@@ -13,6 +13,7 @@ export class CodeEditor extends BaseElement {
this.initWorkers(); this.initWorkers();
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
var editor = monaco.editor.create(this, { var editor = monaco.editor.create(this, {
value: this.input, value: this.input,
@@ -22,7 +23,8 @@ export class CodeEditor extends BaseElement {
minimap: { minimap: {
enabled: false enabled: false
}, },
autoIndent: "full" autoIndent: "full",
theme: prefersDarkScheme.matches ? 'vs-dark' : 'vs-white'
}); });
monaco.languages.registerCompletionItemProvider("javascript", { monaco.languages.registerCompletionItemProvider("javascript", {
@@ -1,20 +1,20 @@
var myDiv = document.createElement("div"); const myDiv = document.createElement("div");
myDiv.innerText = "hello moto"; myDiv.innerText = "hello moto";
document.body.appendChild(myDiv); document.body.appendChild(myDiv);
var i = 0; let i = 0;
while (i < 10) { while (i < 10) {
console.log("hello " + i); console.log("hello " + i);
i++; i++;
} }
var obj = { hello: true, moto: "enabled" }; const obj = { hello: true, moto: "enabled" };
console.log(obj); console.log(obj);
rect(10, 10, 100, 100); rect(10, 10, 100, 100);
rect(rand(10, 30), rand(10, 30), 100, 100); rect(rand(20, 70), rand(20, 70), 100, 100);
rect(30, 30, 100, 100); rect(80, 80, 100, 100);
@@ -36,3 +36,34 @@ notification-bubble.syntax-error {
font-size: 22px; font-size: 22px;
padding: 30px; padding: 30px;
} }
@media (prefers-color-scheme: dark) {
notification-bubble {
color: white;
}
notification-bubble.log {
background-color: #242424;
border-color: #202020;
}
notification-bubble.info {
background-color: #77772e;
border-color: #66662f;
}
notification-bubble.warn {
background-color: #928800;
border-color: #857c00;
}
notification-bubble.error {
background-color: #920000;
border-color: #7c0000;
}
notification-bubble.syntax-error {
background-color: #470000;
background-color: #2b0000;
}
}
+9 -1
View File
@@ -11,6 +11,14 @@ html, body {
body { body {
font-family: "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; font-family: "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif;
margin: 10px;
background-color: #f0f0f0;
}
background-color: #e3e3e3;
@media (prefers-color-scheme: dark) {
body {
background-color: #272727;
color: white;
}
} }
@@ -18,3 +18,11 @@ render-canvas canvas {
border: 1px solid #c2c2c2; border: 1px solid #c2c2c2;
background-color: white; background-color: white;
} }
@media (prefers-color-scheme: dark) {
render-canvas canvas {
background-color: #2c2c2c;
border-color: #3a3a3a;
}
}
@@ -11,10 +11,13 @@ export class RenderCanvas extends BaseElement {
heigt: 400 heigt: 400
} }
public prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
onInit(): void { onInit(): void {
this.canvas = document.createElement("canvas"); this.canvas = document.createElement("canvas");
this.ctx = <CanvasRenderingContext2D>this.canvas.getContext("2d"); this.ctx = <CanvasRenderingContext2D>this.canvas.getContext("2d");
this.appendChild(this.canvas); this.appendChild(this.canvas);
this.canvas.style.display = "none";
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
this.handleCanvasResize(); this.handleCanvasResize();
@@ -25,8 +28,8 @@ export class RenderCanvas extends BaseElement {
private handleCanvasResize() { private handleCanvasResize() {
if (this.parentElement && this.canvas) { if (this.parentElement && this.canvas) {
this.width = this.parentElement.clientWidth; this.width = this.parentElement.clientWidth - 20;
this.height = this.parentElement.clientHeight; this.height = this.parentElement.clientHeight - 20;
var smallest = Math.min(this.width, this.height); var smallest = Math.min(this.width, this.height);
@@ -38,9 +41,10 @@ export class RenderCanvas extends BaseElement {
} }
drawPoly(points: { x: number, y: number }[]) { drawPoly(points: { x: number, y: number }[]) {
if (this.ctx) { if (this.ctx && this.canvas) {
this.canvas.style.display = "block";
this.ctx.fillStyle = "rgba(0,0,0,0)"; this.ctx.fillStyle = "rgba(0,0,0,0)";
this.ctx.strokeStyle = "rgba(0,0,0,1)"; this.ctx.strokeStyle = this.getColor();
this.ctx.beginPath(); this.ctx.beginPath();
for (var i = 0; i < points.length; i++) { for (var i = 0; i < points.length; i++) {
@@ -60,12 +64,16 @@ export class RenderCanvas extends BaseElement {
} }
} }
getColor() {
return this.prefersDarkScheme.matches ? 'rgba(255,255,255,1)' : 'rgba(0,0,0,1)';
}
drawRect(x: number, y: number, width: number, height: number) { drawRect(x: number, y: number, width: number, height: number) {
this.drawPoly([{ x: x, y: y }, { x: x + width, y: y }, { x: x + width, y: y + height }, { x: x, y: y + height }]); this.drawPoly([{ x: x, y: y }, { x: x + width, y: y }, { x: x + width, y: y + height }, { x: x, y: y + height }]);
} }
unitsToPx(unitNumber: number) { unitsToPx(unitNumber: number) {
var newPPU = (this.width / this.units.width); var newPPU = Math.min(this.width, this.height) / this.units.width;
return unitNumber * newPPU; return unitNumber * newPPU;
} }