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:
-
content_length(int) –Total scrollable content size.
-
position(int) –Current scroll offset within
content_length. -
viewport_length(int) –Visible window size; drives thumb proportion.
-
orientation(ScrollbarOrientationLike) –Which edge the scrollbar is drawn on.
-
thumb(str | None) –Optional thumb glyph.
-
track(str | None) –Optional track glyph.
-
begin(str | None) –Arrow symbol at the start;
Noneomits it. -
end(str | None) –Arrow symbol at the end;
Noneomits it. -
color('ColorLike | None') –Overall track and thumb style.
-
thumb_color('ColorLike | None') –Thumb foreground color.
-
track_color('ColorLike | None') –Track foreground color.
-
begin_color('ColorLike | None') –Begin-arrow color.
-
end_color('ColorLike | None') –End-arrow color.
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.
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
¶
Overall track and thumb style.
thumb_color
class-attribute
instance-attribute
¶
Thumb foreground color.
track_color
class-attribute
instance-attribute
¶
Track foreground color.
begin_color
class-attribute
instance-attribute
¶
Begin-arrow color.
end_color
class-attribute
instance-attribute
¶
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.
component_post_init
¶
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
ScrollHandlefor 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
Scrollbarthat readspositionfromhandle.
Source code in xnano/components/scrollbar.py
compose
¶
Compose scrollbar content with a native paint fallback.
Returns:
-
–
Interface-neutral content for this scrollbar.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> 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
compose_small
¶
compose_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is small (40–79 cols).
See :meth:compose_extra_small.
compose_medium
¶
compose_medium(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is medium (80–119 cols).
See :meth:compose_extra_small.
compose_large
¶
compose_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is large (120–159 cols).
See :meth:compose_extra_small.
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
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool