Skip to content

Implement AppLayout widget #2333

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

Merged
merged 39 commits into from
Apr 9, 2019
Merged

Conversation

btel
Copy link
Contributor

@btel btel commented Mar 4, 2019

Request for review

This PR implements specialised layouts based on GridBox widget (using CSS Grid specification).

These are three reusable layouts:

  • TwoByTwoLayout - simple 2x2 grid (locations: top left, bottom left, top right, bottom right) with auto-merging capabilities (if a box is empty, it will be merged with the neighbour)

image

  • AppLayout - more flexible, application-like layout with a footer, a header, two sidebars and a central pane. If some of them are not occupied, they will be merged, giving much flexibility to this layout.

image

  • GridspecLayout - a NxM grid of widgets with a Pythonic indexing/slicing interface. Grid cells can be easily merged by using the slice notation. Very flexible layout, useful also for multi-panel graphs.

image

Example of usage:

import ipywidgets as widgets
app = widgets.TwoByTwoLayout(top_left=widgets.Button(), top_right=widgets.Button(),
                        bottom_left=widgets.Button(), bottom_right=widgets.Button())
display(app)

These template widgets are implemented in widget_templates.py and unit tests in test_widget_templates.py. There is also a new section in the docs written in jupyter notebook Layout Templates.ipynb (it's rather heavy in terms of number of lines, because of the widgets being embeded in the notebook).

@SylvainCorlay
Copy link
Member

Thanks for getting starting witht this!

@btel
Copy link
Contributor Author

btel commented Mar 4, 2019 via email

@maartenbreddels
Copy link
Member

Nice work Bartosz! Absolutely love the AppLayout widget.

Trying out I noticed the following (chrome on osx):
image
Can the scrollbar be avoided in the second example?

@btel
Copy link
Contributor Author

btel commented Mar 6, 2019

@maartenbreddels Thanks for spotting this! The problem seems to be related to the way the size is calculated, i.e. height=100% does not include the margins, so the "Bottom right" button overflows.

I created a minimal example in HTML/CSS reproducing this problem: https://jsfiddle.net/j6xv45sn/

The solution is to set height of the button to 'auto'. I will update the examples.

Copy link
Member

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, found a minor issue with 'merge'.

For the bqplot example, I think this behaves better:

max_slider = FloatSlider(min=0, max=10, description="Max: ",
                         layout=Layout(width='300px', height='20px'))
min_slider = FloatSlider(min=-1, max=10, description="Min: ",
                         layout=Layout(width='300px', height='20px'))

@btel btel changed the title WIP Implement AppLayout widget Implement AppLayout widget Mar 8, 2019
Copy link
Member

@SylvainCorlay SylvainCorlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brilliant! I left a few comments on the way as I am still looking at it.

Great example notebooks!

@SylvainCorlay
Copy link
Member

@btel thanks very much. This is really clean code, and we were not able to "break it" with more complex examples.

@jasongrout we have been reviewing this with @maartenbreddels and I am happy to merge as it is now.

@SylvainCorlay SylvainCorlay merged commit 3fb98db into jupyter-widgets:master Apr 9, 2019
@SylvainCorlay
Copy link
Member

🎉

@maartenbreddels
Copy link
Member

Great work @btel !

@jasongrout jasongrout added this to the 7.5 milestone Jul 29, 2019
@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants