Skip to content

Commit

Permalink
Make max width and height global functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Feb 11, 2022
1 parent 4840176 commit bf37ba6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions view/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ function circuit_empty(circuit) {
return true;
}

const $window = $(window);
function max_dialog_width() {
return $window.width() * 0.9;
}
function max_dialog_height() {
return $window.height() * 0.9;
}

class LuaRunner {
#djs
#runners
Expand Down Expand Up @@ -599,13 +607,11 @@ class DigitalJS {
const svg = div.find('svg');
id = this.#subcircuit_tracker.add(title, svg[0], type);
}
const maxWidth = () => $(window).width() * 0.9;
const maxHeight = () => $(window).height() * 0.9;
const observer = new ResizeObserver(() => {
const mw = maxWidth();
const mw = max_dialog_width();
if (div.width() > mw)
div.dialog("option", "width", mw);
const mh = maxHeight();
const mh = max_dialog_height();
if (div.height() > mh)
div.dialog("option", "height", mh);
});
Expand All @@ -615,8 +621,8 @@ class DigitalJS {
const dialog = div.dialog({
width: 'auto',
height: 'auto',
maxWidth: maxWidth(),
maxHeight: maxHeight(),
maxWidth: max_dialog_width(),
maxHeight: max_dialog_height(),
resizable: type !== "Memory",
close: () => {
if (id !== undefined)
Expand Down

0 comments on commit bf37ba6

Please sign in to comment.