mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 00:20:07 +00:00
Scale canvas on HiPPI screens
This commit is contained in:
@@ -5,13 +5,30 @@ LiteGraph.node_images_path = "../nodes_data/";
|
||||
var editor = new LiteGraph.Editor("main",{miniwindow:false});
|
||||
window.graphcanvas = editor.graphcanvas;
|
||||
window.graph = editor.graph;
|
||||
window.addEventListener("resize", function() { editor.graphcanvas.resize(); } );
|
||||
updateEditorHiPPICanvas();
|
||||
window.addEventListener("resize", function() {
|
||||
editor.graphcanvas.resize();
|
||||
updateEditorHiPPICanvas();
|
||||
} );
|
||||
//window.addEventListener("keydown", editor.graphcanvas.processKey.bind(editor.graphcanvas) );
|
||||
window.onbeforeunload = function(){
|
||||
var data = JSON.stringify( graph.serialize() );
|
||||
localStorage.setItem("litegraphg demo backup", data );
|
||||
}
|
||||
|
||||
function updateEditorHiPPICanvas() {
|
||||
const ratio = window.devicePixelRatio;
|
||||
if(ratio == 1) { return }
|
||||
const rect = editor.canvas.parentNode.getBoundingClientRect();
|
||||
const { width, height } = rect;
|
||||
editor.canvas.width = width * ratio;
|
||||
editor.canvas.height = height * ratio;
|
||||
editor.canvas.style.width = width + "px";
|
||||
editor.canvas.style.height = height + "px";
|
||||
editor.canvas.getContext("2d").scale(ratio, ratio);
|
||||
return editor.canvas;
|
||||
}
|
||||
|
||||
//enable scripting
|
||||
LiteGraph.allow_scripts = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user