Skip to content

Commit

Permalink
Allow setting horizontal and vertical alignment separately (#2072)
Browse files Browse the repository at this point in the history
* Add ability to declare horizontal and vertical alignment separately

* Add docs
  • Loading branch information
philippjfr committed Mar 10, 2021
1 parent 01869de commit 3dfcb7d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
39 changes: 39 additions & 0 deletions examples/user_guide/Customization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,45 @@
" pn.Column(pn.widgets.Button(name='Run', margin=(25, 50, 75, 100)), background='#f0f0f0'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ``align``\n",
"\n",
"The `align` parameter controls how components align vertically and horizontally. It supports 'start', 'center', and 'end' values and can be set for both horizontal and vertical directions at once or for each separately by passing in a tuple of the form `(horizontal, vertical)`.\n",
"\n",
"One common use-case where alignment is important is when placing multiple items with different heights in a `Row`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pn.Row(pn.widgets.IntSlider(name='Test'), pn.widgets.IntSlider(align='end'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In a grid you may also have to specify the horizontal and vertical alignment separately to achieve the layout you are after:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pn.GridBox(\n",
" pn.widgets.IntSlider(name='Test'), pn.widgets.IntSlider(align='end'),\n",
" pn.widgets.TextInput(name='Test', width=150), pn.widgets.TextInput(width=150, align=('start', 'end')),\n",
" ncols=2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
7 changes: 4 additions & 3 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class Layoutable(param.Parameterized):
for all Panel components with a visual representation.
"""

align = param.ObjectSelector(default='start',
objects=['start', 'end', 'center'], doc="""
align = param.ClassSelector(default='start',
class_=(str, tuple), doc="""
Whether the object should be aligned with the start, end or
center of its container""")
center of its container. If set as a tuple it will declare
(vertical, horizontal) alignment.""")

aspect_ratio = param.Parameter(default=None, doc="""
Describes the proportional relationship between component's
Expand Down

0 comments on commit 3dfcb7d

Please sign in to comment.