Spaces:
Running
Running
make layout tightening less intrusive
Browse files
gradio_dualvision/app_template.py
CHANGED
@@ -157,6 +157,9 @@ class DualVisionApp(gr.Blocks):
|
|
157 |
</script>
|
158 |
"""
|
159 |
self.css = f"""
|
|
|
|
|
|
|
160 |
.sliderrow {{ /* center the slider */
|
161 |
display: flex;
|
162 |
justify-content: center;
|
@@ -225,29 +228,30 @@ class DualVisionApp(gr.Blocks):
|
|
225 |
<script>
|
226 |
// fixes vertical size of the component when used inside of iframeResizer (on spaces)
|
227 |
function squeezeViewport() {{
|
228 |
-
if (typeof window.parentIFrame
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
}});
|
236 |
}});
|
237 |
-
}}
|
238 |
}}
|
239 |
window.addEventListener('resize', squeezeViewport);
|
240 |
-
|
241 |
// fixes gradio-imageslider wrong position behavior when using fitting to content by triggering resize
|
242 |
let observer = new MutationObserver((mutationsList) => {{
|
243 |
-
|
244 |
-
|
245 |
if (img.complete) {{
|
246 |
window.dispatchEvent(new Event('resize'));
|
247 |
}} else {{
|
248 |
-
img.onload = () =>
|
|
|
|
|
249 |
}}
|
250 |
-
}}
|
251 |
}});
|
252 |
observer.observe(document.body, {{ childList: true, subtree: true }});
|
253 |
</script>
|
|
|
157 |
</script>
|
158 |
"""
|
159 |
self.css = f"""
|
160 |
+
body {{ /* tighten the layout */
|
161 |
+
flex-grow: 0 !important;
|
162 |
+
}}
|
163 |
.sliderrow {{ /* center the slider */
|
164 |
display: flex;
|
165 |
justify-content: center;
|
|
|
228 |
<script>
|
229 |
// fixes vertical size of the component when used inside of iframeResizer (on spaces)
|
230 |
function squeezeViewport() {{
|
231 |
+
if (typeof window.parentIFrame === "undefined") return;
|
232 |
+
const images = document.querySelectorAll('.slider img');
|
233 |
+
window.parentIFrame.getPageInfo((info) => {{
|
234 |
+
images.forEach((img) => {{
|
235 |
+
const imgMaxHeightNew = (info.clientHeight * {squeeze_viewport_height_pct}) / 100;
|
236 |
+
img.style.maxHeight = `${{imgMaxHeightNew}}px`;
|
237 |
+
// window.parentIFrame.size(0, null); // tighten the layout; body's flex-grow: 0 is less intrusive
|
|
|
238 |
}});
|
239 |
+
}});
|
240 |
}}
|
241 |
window.addEventListener('resize', squeezeViewport);
|
242 |
+
|
243 |
// fixes gradio-imageslider wrong position behavior when using fitting to content by triggering resize
|
244 |
let observer = new MutationObserver((mutationsList) => {{
|
245 |
+
const images = document.querySelectorAll('.slider img');
|
246 |
+
images.forEach((img) => {{
|
247 |
if (img.complete) {{
|
248 |
window.dispatchEvent(new Event('resize'));
|
249 |
}} else {{
|
250 |
+
img.onload = () => {{
|
251 |
+
window.dispatchEvent(new Event('resize'));
|
252 |
+
}}
|
253 |
}}
|
254 |
+
}});
|
255 |
}});
|
256 |
observer.observe(document.body, {{ childList: true, subtree: true }});
|
257 |
</script>
|