Skip to content

Commit 73827e9

Browse files
committed
Fix scroll jank when loading demo page
1 parent 21983f0 commit 73827e9

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"haha",
88
"Hilight",
99
"iframes",
10+
"jank",
1011
"janky",
1112
"jspaint",
1213
"LOGFONTW",

demo/demo.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $(()=> {
6363
$menubar.appendTo("#menubar-example");
6464

6565
var $app_window_1 = new $Window({title: "Application Window", resizable: true});
66-
$app_window_1.$content.append($("#app-window-example-content"));
66+
$app_window_1.$content.append($("#app-window-example-content").attr("hidden", null));
6767

6868
$app_window_1.$Button("Open Another Window", ()=> {
6969
var $new_window = new $Window({title: "Testing, Testing, 123"});
@@ -74,7 +74,7 @@ $(()=> {
7474
});
7575

7676
var $tool_window_1 = new $Window({ title: "Tool Window", toolWindow: true });
77-
$tool_window_1.$content.append($("#tool-window-example-content"));
77+
$tool_window_1.$content.append($("#tool-window-example-content").attr("hidden", null));
7878
$tool_window_1.on("close", (event) => {
7979
event.preventDefault();
8080
});
@@ -196,4 +196,18 @@ InfoWindow=255 255 225
196196
// });
197197
}
198198

199+
// Users of library: DON'T WORRY ABOUT THIS STUFF
200+
// This is just for the demo page, to prevent scroll jank when loading the page.
201+
// This is only needed because of all the dynamic content that is interspersed with text.
202+
// Usually you would have floating windows, that aren't trying to also fit into a document.
203+
let static_styles = "";
204+
for (selector of window_list.map(([, el_id]) => `#${el_id}`).concat([
205+
"#scrollbar-demos",
206+
"#menubar-example",
207+
])) {
208+
const el = $(selector)[0];
209+
static_styles += `${selector} { width: ${el.offsetWidth}px; height: ${el.offsetHeight}px; }\n`;
210+
}
211+
window.static_styles = static_styles; // export these static styles to the demo's HTML (manually)
212+
199213
});

demo/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,19 @@
8484
}
8585

8686
body {
87-
overflow: scroll;
87+
overflow: scroll; /* show off the custom scrollbars :) */
8888
}
89+
90+
/*
91+
These styles are generated by demo.js, exported via window.static_styles,
92+
in order to reduce jank when the demo is loaded.
93+
*/
94+
#app-window-example { width: 200px; height: 135px; }
95+
#tool-window-example { width: 195px; height: 107px; }
96+
#app-window-2-positioner { width: 227px; height: 231px; }
97+
#tool-window-2-positioner { width: 218px; height: 95px; }
98+
#scrollbar-demos { width: 1240px; height: 557px; }
99+
#menubar-example { width: 1240px; height: 21px; }
89100
</style>
90101
</head>
91102
<body>
@@ -97,7 +108,7 @@
97108
<main>
98109
<h1>os-gui.js</h1>
99110
<h2>Scrollbars</h2>
100-
<div>
111+
<div id="scrollbar-demos">
101112
<div class="scrollbar-demo">
102113
<div class="scrollbar-button decrement horizontal" style="display: inline-block;"></div><div class="scrollbar-button increment horizontal" style="display: inline-block;"></div>
103114
<div class="scrollbar-button decrement vertical"></div>
@@ -125,14 +136,14 @@ <h2>MenuBar</h2>
125136
<h2>Application Window</h2>
126137
<div>
127138
<div id="app-window-example"></div>
128-
<div id="app-window-example-content">
139+
<div id="app-window-example-content" hidden>
129140
<p>Hello World!</p>
130141
</div>
131142
</div>
132143
<h2>Tool Window</h2>
133144
<div>
134145
<div id="tool-window-example"></div>
135-
<div id="tool-window-example-content">
146+
<div id="tool-window-example-content" hidden>
136147
<p>I am a tool window.</p>
137148
</div>
138149
</div>

0 commit comments

Comments
 (0)