Skip to content

Commit

Permalink
Expose text layout for SelectableIcon and Button constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Stepanov committed Sep 5, 2023
1 parent 7ea051d commit 0b0b5ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion urwid/widget/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
markup,
align: Literal["left", "center", "right"] | Align = Align.LEFT,
wrap: Literal["space", "any", "clip", "ellipsis"] | WrapMode = WrapMode.SPACE,
layout=None,
layout: text_layout.TextLayout | None = None,
) -> None:
"""
:param markup: content of text widget, one of:
Expand Down
11 changes: 9 additions & 2 deletions urwid/widget/wimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from typing_extensions import Literal, Self

from urwid.canvas import TextCanvas
from urwid.text_layout import TextLayout

_T = typing.TypeVar("_T")

Expand All @@ -53,6 +54,7 @@ def __init__(
cursor_position: int = 0,
align: Literal["left", "center", "right"] | Align = Align.LEFT,
wrap: Literal["space", "any", "clip", "ellipsis"] | WrapMode = WrapMode.SPACE,
layout: TextLayout | None = None,
) -> None:
"""
:param text: markup for this widget; see :class:`Text` for
Expand All @@ -63,12 +65,14 @@ def __init__(
:type align: text alignment mode
:param wrap: typically ``'space'``, ``'any'``, ``'clip'`` or ``'ellipsis'``
:type wrap: text wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
This is a text widget that is selectable. A cursor
displayed at a fixed location in the text when in focus.
This widget has no special handling of keyboard or mouse input.
"""
super().__init__(text, align=align, wrap=wrap)
super().__init__(text, align=align, wrap=wrap, layout=layout)
self._cursor_position = cursor_position

def render(self, size: tuple[int], focus: bool = False) -> TextCanvas | CompositeCanvas:
Expand Down Expand Up @@ -508,6 +512,7 @@ def __init__(
*,
align: Literal["left", "center", "right"] | Align = Align.LEFT,
wrap: Literal["space", "any", "clip", "ellipsis"] | WrapMode = WrapMode.SPACE,
layout: TextLayout | None = None,
) -> None:
"""
:param label: markup for button label
Expand All @@ -518,6 +523,8 @@ def __init__(
:type align: label alignment mode
:param wrap: typically ``'space'``, ``'any'``, ``'clip'`` or ``'ellipsis'``
:type wrap: label wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
Signals supported: ``'click'``
Expand All @@ -542,7 +549,7 @@ def __init__(
>>> wrapped_button.render((7,), focus=False).text[0].decode('utf-8')
'< Lo… >'
"""
self._label = SelectableIcon(label, 0, align=align, wrap=wrap)
self._label = SelectableIcon(label, 0, align=align, wrap=wrap, layout=layout)
cols = Columns(
[
(Sizing.FIXED, 1, self.button_left),
Expand Down

0 comments on commit 0b0b5ec

Please sign in to comment.