toshas commited on
Commit
bd654b5
·
1 Parent(s): 7f9dd32

make layout tightening less intrusive

Browse files
Files changed (1) hide show
  1. gradio_dualvision/app_template.py +18 -14
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 !== "undefined") {{
229
- const images = document.querySelectorAll('.slider img');
230
- window.parentIFrame.getPageInfo((info) => {{
231
- const parentHeight = info.clientHeight;
232
- images.forEach((img) => {{
233
- img.style.maxHeight = `${{(parentHeight * {squeeze_viewport_height_pct}) / 100}}px`;
234
- window.parentIFrame.size(0, null); // tighten the layout
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
- let img = document.querySelector(".slider img");
244
- if (img) {{
245
  if (img.complete) {{
246
  window.dispatchEvent(new Event('resize'));
247
  }} else {{
248
- img.onload = () => window.dispatchEvent(new Event('resize'));
 
 
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>