Skip to content

Commit 5c6be7f

Browse files
committed
Move various Input/ files to TextContent
* Labeled can now safely make the label TextContent:D * SimpleClickable's decendents handle full TextContent in labels * SimpleClickable itself passes full TextContent to its descendents, but still smashes to plain-text before writing to the grid
1 parent 69de09b commit 5c6be7f

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

lib/Terminal/Widgets/Input/Button.rakumod

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Terminal::Capabilities;
44
constant Uni1 = Terminal::Capabilities::SymbolSet::Uni1;
55

6+
use Terminal::Widgets::TextContent;
67
use Terminal::Widgets::Input::SimpleClickable;
78

89

@@ -17,13 +18,18 @@ class Terminal::Widgets::Input::Button
1718

1819
#| Content (text inside framing)
1920
method content-text($label) {
21+
my $terminal = self.terminal;
22+
my $symbol-set = $terminal.caps.symbol-set;
23+
my $has-Uni1 = $symbol-set >= Uni1;
24+
my $locale = $terminal.locale;
25+
2026
my $has-border = self.layout.computed.has-border;
21-
my $symbol-set = self.terminal.caps.symbol-set;
22-
my $string = $label // '';
27+
my @string = $locale.flat-string-spans($label // '');
2328

24-
$has-border ?? $string !!
25-
$symbol-set >= Uni1 ?? '' ~ $string ~ '' !!
26-
'[' ~ $string ~ ']'
29+
my @spans = $has-border ?? @string !!
30+
$has-Uni1 ?? (string-span(''), |@string, string-span('')) !!
31+
(string-span('['), |@string, string-span(']'));
32+
span-tree(|@spans);
2733
}
2834

2935
#| Process a click event

lib/Terminal/Widgets/Input/Checkbox.rakumod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ABSTRACT: A single checkbox, optionally labeled
22

3+
use Terminal::Widgets::TextContent;
34
use Terminal::Widgets::Input::Boolean;
45

56

@@ -21,11 +22,14 @@ class Terminal::Widgets::Input::Checkbox
2122
Uni1 => « ☐ ☒ »,
2223
Uni7 => « 🞏 🞕 »;
2324

24-
$caps.best-symbol-choice(%boxes)
25+
# XXXX: Hoist string-span up into constant?
26+
$caps.best-symbol-choice(%boxes).map({ string-span($_) })
2527
}
2628

2729
#| Content (text inside framing)
2830
method content-text($label) {
29-
self.checkboxes()[+$.state] ~ (' ' ~ $label if $label)
31+
my @label-spans = $.terminal.locale.flat-string-spans($label // '');
32+
my $box-span = self.checkboxes()[+$.state];
33+
span-tree($box-span, |(pad-span(1), |@label-spans if $label))
3034
}
3135
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# ABSTRACT: Role for inputs that have a label 'attached' to them, such as radio buttons
22

3+
use Terminal::Widgets::TextContent;
4+
35
role Terminal::Widgets::Input::Labeled {
4-
# XXXX: Need a 'defined textual content' type constraint
5-
has $.label = '';
6+
has TextContent:D $.label = '';
67

78
method set-label($!label) { self.full-refresh }
89
}

lib/Terminal/Widgets/Input/RadioButton.rakumod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ABSTRACT: A single radio button, optionally labeled
22

3+
use Terminal::Widgets::TextContent;
34
use Terminal::Widgets::Input::Boolean;
45

56

@@ -21,11 +22,14 @@ class Terminal::Widgets::Input::RadioButton
2122
Uni1 => « ○ ⊙ »,
2223
Uni7 => « 🞅 🞊 »;
2324

24-
$caps.best-symbol-choice(%buttons)
25+
# XXXX: Hoist string-span up into constant?
26+
$caps.best-symbol-choice(%buttons).map({ string-span($_) })
2527
}
2628

2729
#| Content (text inside framing)
2830
method content-text($label) {
29-
self.buttons()[+$.state] ~ (' ' ~ $label if $label)
31+
my @label-spans = $.terminal.locale.flat-string-spans($label // '');
32+
my $button-span = self.buttons()[+$.state];
33+
span-tree($button-span, |(pad-span(1), |@label-spans if $label))
3034
}
3135
}

lib/Terminal/Widgets/Input/SimpleClickable.rakumod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ does Terminal::Widgets::Input::Labeled {
2727
my $y = $layout.top-correction;
2828

2929
# XXXX: Temporary hack
30-
my $label = $.terminal.locale.plain-text($.label);
30+
my $text = $.terminal.locale.plain-text(self.content-text($.label));
3131

32-
$.grid.set-span($x, $y, self.content-text($label), self.current-color);
32+
$.grid.set-span($x, $y, $text, self.current-color);
3333
}
3434

3535
#| Handle minimal keyboard events

lib/Terminal/Widgets/Input/ToggleButton.rakumod

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Terminal::Capabilities;
44
constant Uni1 = Terminal::Capabilities::SymbolSet::Uni1;
55

6-
use Terminal::Widgets::SpanStyle;
6+
use Terminal::Widgets::TextContent;
77
use Terminal::Widgets::Input::Boolean;
88

99

@@ -15,21 +15,23 @@ class Terminal::Widgets::Input::ToggleButton
1515
my $bw = %style<border-width>;
1616
my $has-border = $bw ~~ Positional ?? $bw.grep(?*) !! ?$bw;
1717
$locale.width($label) + 2 * !$has-border
18-
+ 2 # XXXX: Waiting on upgrade to content model
1918
}
2019

2120
#| Content (text inside framing)
2221
method content-text($label) {
22+
my $terminal = self.terminal;
23+
my $symbol-set = $terminal.caps.symbol-set;
24+
my $has-Uni1 = $symbol-set >= Uni1;
25+
my $locale = $terminal.locale;
26+
2327
my $has-border = self.layout.computed.has-border;
24-
my $symbol-set = self.terminal.caps.symbol-set;
25-
my $string = $label // '';
28+
my @string = $locale.flat-string-spans($label // '');
2629

27-
my $text = $has-border ?? $string !!
28-
$symbol-set >= Uni1 ?? '' ~ $string ~ '' !!
29-
'[' ~ $string ~ ']';
30+
my @spans = $has-border ?? @string !!
31+
$has-Uni1 ?? (string-span(''), |@string, string-span('')) !!
32+
(string-span('['), |@string, string-span(']'));
3033

31-
# XXXX: Waiting on upgrade to content model
32-
# $.state ?? span('white on_blue', $text) !! $text
33-
$.state ?? '>' ~ $text ~ '<' !! $text
34+
$.state ?? span-tree(color => 'white on_blue', |@spans)
35+
!! span-tree(|@spans)
3436
}
3537
}

0 commit comments

Comments
 (0)