Skip to content

xnano.components.scrollbar

xnano.components.scrollbar

xnano.components.scrollbar


Display the position and visible range of scrollable content.

Classes:

  • Scrollbar

    Display the visible range of scrollable content.

Scrollbar dataclass

Scrollbar(
    content_length: int = 0,
    position: int = 0,
    viewport_length: int = 0,
    orientation: ScrollbarOrientationLike = "vertical_right",
    thumb: str | None = None,
    track: str | None = None,
    begin: str | None = None,
    end: str | None = None,
    color: "ColorLike | None" = None,
    thumb_color: "ColorLike | None" = None,
    track_color: "ColorLike | None" = None,
    begin_color: "ColorLike | None" = None,
    end_color: "ColorLike | None" = None,
    *,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True
)

Bases: Component

Display the visible range of scrollable content.

Lengths and position are clamped on every frame, so live updates cannot move the thumb outside the track.

Example

Scrollbar(content_length=200, viewport_length=25, position=50)

Attributes:

Methods:

  • component_post_init

    Clamp initial lengths and position.

  • from_scroll_handle

    Build a scrollbar bound to a field scroll handle.

  • compose

    Compose scrollbar content with a native paint fallback.

  • get_frame

    Optional frame/panel chrome around composed content.

  • get_size

    Return the preferred cell size of this component.

  • before_render

    Called before rendering; returns the effective render area.

  • after_render

    Called after rendering for optional post-paint work.

  • compose_extra_small

    Compose content when the viewport is extra small (< 40 cols).

  • compose_small

    Compose content when the viewport is small (40–79 cols).

  • compose_medium

    Compose content when the viewport is medium (80–119 cols).

  • compose_large

    Compose content when the viewport is large (120–159 cols).

  • compose_extra_large

    Compose content when the viewport is extra large (>= 160 cols).

  • handle_keyboard

    Optional keyboard handler while focused.

  • handle_paste

    Optional paste handler while focused.

content_length class-attribute instance-attribute

content_length: int = 0

Total scrollable content size.

position class-attribute instance-attribute

position: int = 0

Current scroll offset within content_length.

viewport_length class-attribute instance-attribute

viewport_length: int = 0

Visible window size; drives thumb proportion.

orientation class-attribute instance-attribute

orientation: ScrollbarOrientationLike = 'vertical_right'

Which edge the scrollbar is drawn on.

thumb class-attribute instance-attribute

thumb: str | None = None

Optional thumb glyph.

track class-attribute instance-attribute

track: str | None = None

Optional track glyph.

begin class-attribute instance-attribute

begin: str | None = None

Arrow symbol at the start; None omits it.

end class-attribute instance-attribute

end: str | None = None

Arrow symbol at the end; None omits it.

color class-attribute instance-attribute

color: 'ColorLike | None' = None

Overall track and thumb style.

thumb_color class-attribute instance-attribute

thumb_color: 'ColorLike | None' = None

Thumb foreground color.

track_color class-attribute instance-attribute

track_color: 'ColorLike | None' = None

Track foreground color.

begin_color class-attribute instance-attribute

begin_color: 'ColorLike | None' = None

Begin-arrow color.

end_color class-attribute instance-attribute

end_color: 'ColorLike | None' = None

End-arrow color.

visible class-attribute instance-attribute

visible: bool = dataclasses.field(
    default=True, kw_only=True
)

Whether this component paints at all.

z class-attribute instance-attribute

z: int = dataclasses.field(default=0, kw_only=True)

Stacking order among sibling content.

fit_content class-attribute instance-attribute

fit_content: bool = dataclasses.field(
    default=True, kw_only=True
)

When True, paint at natural size inside a larger slot.

focused property

focused: bool

Whether this component currently holds field focus.

component_post_init

component_post_init() -> None

Clamp initial lengths and position.

Source code in xnano/components/scrollbar.py
def component_post_init(self) -> None:
    """Clamp initial lengths and position."""
    self._clamp_state()

from_scroll_handle classmethod

from_scroll_handle(
    handle: "ScrollHandle",
    *,
    content_length: int | None = None,
    viewport_length: int | None = None,
    orientation: ScrollbarOrientationLike = "vertical_right",
    thumb: str | None = None,
    track: str | None = None,
    begin: str | None = None,
    end: str | None = None,
    color: "ColorLike | None" = None,
    thumb_color: "ColorLike | None" = None,
    track_color: "ColorLike | None" = None,
    begin_color: "ColorLike | None" = None,
    end_color: "ColorLike | None" = None,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True
) -> "Scrollbar"

Build a scrollbar bound to a field scroll handle.

The handle owns offset / follow mode. Callers (or the field controller) should pass the measured content and viewport lengths; the component never reaches into grid private dictionaries.

Parameters:

  • handle ('ScrollHandle') –

    Resolved ScrollHandle for a scrolled field.

  • content_length (int | None, default: None ) –

    Total scrollable content size when known.

  • viewport_length (int | None, default: None ) –

    Visible window size when known.

  • orientation (ScrollbarOrientationLike, default: 'vertical_right' ) –

    Scrollbar edge placement.

  • thumb (str | None, default: None ) –

    Optional thumb glyph.

  • track (str | None, default: None ) –

    Optional track glyph.

  • begin (str | None, default: None ) –

    Optional leading glyph.

  • end (str | None, default: None ) –

    Optional trailing glyph.

  • color ('ColorLike | None', default: None ) –

    Overall foreground color.

  • thumb_color ('ColorLike | None', default: None ) –

    Thumb foreground color.

  • track_color ('ColorLike | None', default: None ) –

    Track foreground color.

  • begin_color ('ColorLike | None', default: None ) –

    Leading glyph color.

  • end_color ('ColorLike | None', default: None ) –

    Trailing glyph color.

  • visible (bool, default: True ) –

    Whether the scrollbar paints.

  • z (int, default: 0 ) –

    Paint order relative to siblings.

  • fit_content (bool, default: True ) –

    Whether layout uses the natural scrollbar size.

Returns:

  • 'Scrollbar'

    A Scrollbar that reads position from handle.

Source code in xnano/components/scrollbar.py
@classmethod
def from_scroll_handle(
    cls,
    handle: "ScrollHandle",
    *,
    content_length: int | None = None,
    viewport_length: int | None = None,
    orientation: ScrollbarOrientationLike = "vertical_right",
    thumb: str | None = None,
    track: str | None = None,
    begin: str | None = None,
    end: str | None = None,
    color: "ColorLike | None" = None,
    thumb_color: "ColorLike | None" = None,
    track_color: "ColorLike | None" = None,
    begin_color: "ColorLike | None" = None,
    end_color: "ColorLike | None" = None,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True,
) -> "Scrollbar":
    """Build a scrollbar bound to a field scroll handle.

    The handle owns offset / follow mode. Callers (or the field
    controller) should pass the measured content and viewport lengths;
    the component never reaches into grid private dictionaries.

    Args:
        handle: Resolved ``ScrollHandle`` for a scrolled field.
        content_length: Total scrollable content size when known.
        viewport_length: Visible window size when known.
        orientation: Scrollbar edge placement.
        thumb: Optional thumb glyph.
        track: Optional track glyph.
        begin: Optional leading glyph.
        end: Optional trailing glyph.
        color: Overall foreground color.
        thumb_color: Thumb foreground color.
        track_color: Track foreground color.
        begin_color: Leading glyph color.
        end_color: Trailing glyph color.
        visible: Whether the scrollbar paints.
        z: Paint order relative to siblings.
        fit_content: Whether layout uses the natural scrollbar size.

    Returns:
        A ``Scrollbar`` that reads ``position`` from ``handle``.
    """
    instance = cls(
        content_length=content_length or 0,
        position=int(getattr(handle, "offset", 0) or 0),
        viewport_length=viewport_length or 0,
        orientation=orientation,
        thumb=thumb,
        track=track,
        begin=begin,
        end=end,
        color=color,
        thumb_color=thumb_color,
        track_color=track_color,
        begin_color=begin_color,
        end_color=end_color,
        visible=visible,
        z=z,
        fit_content=fit_content,
    )
    instance._scroll_handle = handle
    instance._handle_content_length = content_length
    instance._handle_viewport_length = viewport_length
    return instance

compose

compose(ctx: 'ComponentRenderContext')

Compose scrollbar content with a native paint fallback.

Returns:

  • Interface-neutral content for this scrollbar.

Source code in xnano/components/scrollbar.py
def compose(self, ctx: "ComponentRenderContext"):
    """Compose scrollbar content with a native paint fallback.

    Returns:
        Interface-neutral content for this scrollbar.
    """
    return self._compose_content()

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return None

compose_extra_small

compose_extra_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is extra small (< 40 cols).

Optional responsive counterpart to :meth:compose. When overridden, it is used instead of compose while the window is in this size tier. Overriding any compose_* variant opts the component into breakpoint dispatch; a component that overrides none pays no per-frame cost.

Source code in xnano/components/component.py
@responsive_noop
def compose_extra_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra small (< 40 cols).

    Optional responsive counterpart to :meth:`compose`. When
    overridden, it is used *instead of* ``compose`` while the window
    is in this size tier. Overriding any ``compose_*`` variant opts the
    component into breakpoint dispatch; a component that overrides none
    pays no per-frame cost.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_extra_large

compose_extra_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is extra large (>= 160 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False