Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make thumbnails grid- and flexbox-compatible #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexisthual opened this issue Jan 12, 2022 · 5 comments · Fixed by #906
Closed

Make thumbnails grid- and flexbox-compatible #905

alexisthual opened this issue Jan 12, 2022 · 5 comments · Fixed by #906

Comments

@alexisthual
Copy link
Contributor

alexisthual commented Jan 12, 2022

At the moment, sphinx-gallery generates a div for each gallery item.
These divs are float: left and have a pre-determined width, which does not render very nicely on most screen sizes or for long titles.

I suggest that for each subsection of the gallery, we add a parent div to these item divs.
This would allow users to either use css grid or flex (which we could also implement here directly).
It boils down to adding a new div before iterating through each gallery item and closing this div after:

entries_text = []
costs = []
build_target_dir = os.path.relpath(target_dir, gallery_conf['src_dir'])
iterator = sphinx_compatibility.status_iterator(
sorted_listdir,
'generating gallery for %s... ' % build_target_dir,
length=len(sorted_listdir))
for fname in iterator:
intro, title, cost = generate_file_rst(
fname, target_dir, src_dir, gallery_conf, seen_backrefs)
src_file = os.path.normpath(os.path.join(src_dir, fname))
costs.append((cost, src_file))

Also, maybe we could use sphinx-design to handle the grid for us, but this would add a new dependency.

Happy to here what you think about this!

@GaelVaroquaux
Copy link
Contributor

GaelVaroquaux commented Jan 12, 2022 via email

@larsoner
Copy link
Contributor

Agreed. At the very least, adding a parent div with a new class is a good start. If CSS flex can be added on top in a way that can be overridden/disabled easily in downstream CSS, then that sounds good, too. If it can't easily be disabled, we could still consider adding it -- but the chances of breaking user sites (in a way that's hard to fix) goes up, so we'd have to think harder about the tradeoffs.

@larsoner
Copy link
Contributor

... regarding a new dependency, maybe that could be opt-in, like pip install sphinx-gallery[design], and then people can do in conf.py:

sphinx_gallery_conf = {
    ...
    'use_sphinx_design': True,
}

or something. But I am no expert here, happy to hear what you (and others) think @alexisthual !

@alexisthual
Copy link
Contributor Author

I tried something locally:

  • adding the new div is easy and does most of the job
  • designing a responsive grid also works great, appart from the fact that some unexpected divs appear in the DOM due to sphinx; we'll need a fix for this issue, otherwise we can't use grids

My take is that we don't need sphinx-design in the end.

However, I'd be in favour of doing a small refactoring the thumbnail. Currently, the div's height won't scale to it's content's height. I guess this is because html figure captions don't play well with divs. It seems that a min-height is set to fix this, but it's not the right way of doing this.

The following structure would make sense to me:

<a class="sphx-glr-thumbcontainer">
  <img />
  <div class="sphx-glr-thumb-title">title</div>
</a>

as opposed to the current structure:

<div class="sphx-glr-thumbcontainer">
  <figure class="align-default">
    <img />
    <figcaption>
      <p><span class="caption-text"><a class="reference internal"><span class="std std-ref">title</span></a> 
      </span><a class="headerlink" title="Permalink to this image"></a></p>
    </figcaption>
  </figure>
</div>

I tested it and it feels much nicer. This could potentially break some css added by users on top of sphinx-gallery, but I think they added this code mostly to fix the issue mentioned above.

What do you think? 🙂

@larsoner
Copy link
Contributor

I tested it and it feels much nicer. This could potentially break some css added by users on top of sphinx-gallery, but I think they added this code mostly to fix the issue mentioned above.

I agree that this is most likely the case. If we can git image + caption to fit without any trickery, and make some clear note about how to adjust CSS to deal with the change, I think it can be considered a bugfix and released without a deprecation cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants