Selkie--Widget--Text
NAME
Selkie::Widget::Text - Static styled text with word-wrap
SYNOPSIS
use Selkie::Widget::Text;
use Selkie::Style;
use Selkie::Sizing;
my $header = Selkie::Widget::Text.new(
text => ' My App',
sizing => Sizing.fixed(1),
style => Selkie::Style.new(fg => 0x7AA2F7, bold => True),
);
# Mutate later
$header.set-text(' My App ā logged in as Alice');DESCRIPTION
A block of text rendered onto a single plane. Word-wraps automatically when the text exceeds the widget's width ā words longer than the line are hard-broken at the character level.
Styled via the optional style attribute. If omitted, inherits the theme's text slot. Pass theme-slot for framework-built text that should follow a semantic theme slot such as overlay-title.
Text implements render-region(offset, height), so it plays correctly with Selkie::Widget::ScrollView for long content.
EXAMPLES
A header and footer
$vbox.add: Selkie::Widget::Text.new(
text => 'Selkie App',
sizing => Sizing.fixed(1),
style => Selkie::Style.new(fg => 0x7AA2F7, bold => True),
);
$vbox.add: $main-content;
$vbox.add: Selkie::Widget::Text.new(
text => 'Ctrl+Q: quit ā ?: help',
sizing => Sizing.fixed(1),
style => Selkie::Style.new(fg => 0x888888),
);Driven by the store
Set up a subscription that updates the text whenever state changes:
my $status = Selkie::Widget::Text.new(text => '', sizing => Sizing.fixed(1));
$app.store.subscribe-with-callback(
'status-line',
-> $s { "{$s.get-in('user', 'name') // 'guest'} ā {$s.get-in('messages').elems} unread" },
-> $text { $status.set-text($text) },
$status,
);SEE ALSO
Selkie::Widget::RichText ā styled spans within one block of text
Selkie::Widget::TextStream ā append-only log with ring buffer and auto-scroll
has Str $.text
The text to render. Can include newlines ā each line is wrapped independently.
has Selkie::Style $.style
Optional style override. If undefined, the theme's text slot is used.
has Str $.theme-slot
Optional theme slot name to use when style is not set.
method set-text
method set-text(
Str:D $t
) returns MuReplace the displayed text. Re-wraps and marks the widget dirty.
method set-style
method set-style(
Selkie::Style $s
) returns MuReplace the style override. Pass an undefined Selkie::Style to revert to the theme default.
method set-theme-slot
method set-theme-slot(
Str $slot
) returns MuReplace the semantic theme slot used when style is not set.
method logical-height
method logical-height() returns UIntNumber of lines the text wraps to at the current width. Used by ScrollView to compute scrollable extent.
method render-region
method render-region(
Int :$offset where { ... },
Int :$height where { ... }
) returns MuRender only a slice of the wrapped lines, starting at offset and going for height rows. Used by ScrollView for partial-viewport rendering.