Skip to content

Commit 8c50681

Browse files
committed
Teach all existing layout classes their builder-name
1 parent 69442b5 commit 8c50681

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

lib/Terminal/Widgets/Layout.rakumod

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ does Terminal::Widgets::Common {
172172

173173
#| A leaf node in the layout tree (no possible children)
174174
class Leaf does Dynamic {
175+
method builder-name() { 'leaf' }
176+
175177
multi method gist(Leaf:U:) {
176178
self.gist-name ~ ':U'
177179
}
@@ -207,6 +209,8 @@ class Node does Dynamic {
207209
.parent = self for @!children;
208210
}
209211

212+
method builder-name() { 'node' }
213+
210214
multi method gist(Node:U:) {
211215
self.gist-name ~ ':U'
212216
}
@@ -406,45 +410,67 @@ class Node does Dynamic {
406410

407411

408412
#| A space consumer around or between layout nodes
409-
class Spacer is Leaf { }
413+
class Spacer is Leaf {
414+
method builder-name() { 'spacer' }
415+
}
410416

411417
#| A visual divider (such as box-drawing lines) between layout nodes
412-
class Divider is Leaf { }
418+
class Divider is Leaf {
419+
method builder-name() { 'divider' }
420+
}
413421

414422
#| A horizontal scrollbar
415423
class HScrollBar is Leaf {
424+
method builder-name() { 'hscroll' }
425+
416426
method default-styles(:$show-end-arrows) {
417427
%( set-h => 1, min-w => 1 + ?$show-end-arrows )
418428
}
419429
}
420430

421431
#| A vertical scrollbar
422432
class VScrollBar is Leaf {
433+
method builder-name() { 'vscroll' }
434+
423435
method default-styles(:$show-end-arrows) {
424436
%( set-w => 1, min-h => 1 + ?$show-end-arrows )
425437
}
426438
}
427439

428440
#| A rich text viewer widget
429-
class RichText is Leaf { }
441+
class RichText is Leaf {
442+
method builder-name() { 'rich-text' }
443+
}
430444

431445
#| A tree viewer widget
432-
class TreeView is Leaf { }
446+
class TreeView is Leaf {
447+
method builder-name() { 'tree-view' }
448+
}
433449

434450
#| A multi-line auto-scrolling log viewer
435-
class LogViewer is Leaf { }
451+
class LogViewer is Leaf {
452+
method builder-name() { 'log-viewer' }
453+
}
436454

437455
#| A navigable tree viewer widget
438-
class TreeViewer is Leaf { }
456+
class TreeViewer is Leaf {
457+
method builder-name() { 'tree-viewer' }
458+
}
439459

440460
#| A navigable tree viewer widget, specialized for directory trees
441-
class DirTreeViewer is TreeViewer { }
461+
class DirTreeViewer is TreeViewer {
462+
method builder-name() { 'dir-tree-viewer' }
463+
}
442464

443465
#| A simple smoke chart visualization
444-
class SmokeChart is Leaf { }
466+
class SmokeChart is Leaf {
467+
method builder-name() { 'smoke-chart' }
468+
}
445469

446470
#| A minimal plain text container
447471
class PlainText is Leaf {
472+
method builder-name() { 'plain-text' }
473+
448474
method default-styles(:$locale!, :$text = '') {
449475
my @lines = $locale.plain-text($text).lines;
450476

@@ -455,6 +481,8 @@ class PlainText is Leaf {
455481

456482
#| A multi-line single-select menu
457483
class Menu is Leaf {
484+
method builder-name() { 'menu' }
485+
458486
method default-styles(:$locale!, :@items, :%icons) {
459487
my $max-icon = 0 max %icons.values.map({ $locale.width($_) }).max;
460488
my $spacing = 2 + ?$max-icon;
@@ -477,27 +505,33 @@ class SingleLineInput is Leaf {
477505

478506
#| A single button
479507
class Button is SingleLineInput {
480-
method input-class() { ::('Terminal::Widgets::Input::Button') }
508+
method builder-name() { 'button' }
509+
method input-class() { ::('Terminal::Widgets::Input::Button') }
481510
}
482511

483512
#| A single checkbox
484513
class Checkbox is SingleLineInput {
485-
method input-class() { ::('Terminal::Widgets::Input::Checkbox') }
514+
method builder-name() { 'checkbox' }
515+
method input-class() { ::('Terminal::Widgets::Input::Checkbox') }
486516
}
487517

488518
#| A single radio button
489519
class RadioButton is SingleLineInput {
490-
method input-class() { ::('Terminal::Widgets::Input::RadioButton') }
520+
method builder-name() { 'radio-button' }
521+
method input-class() { ::('Terminal::Widgets::Input::RadioButton') }
491522
}
492523

493524
#| A single toggle button (looks like a button, acts like a checkbox)
494525
class ToggleButton is SingleLineInput {
495-
method input-class() { ::('Terminal::Widgets::Input::ToggleButton') }
526+
method builder-name() { 'toggle-button' }
527+
method input-class() { ::('Terminal::Widgets::Input::ToggleButton') }
496528
}
497529

498530
#| A single-line text input field
499531
class TextInput is SingleLineInput {
500-
method input-class() { ::('Terminal::Widgets::Input::Text') }
532+
method builder-name() { 'text-input' }
533+
method input-class() { ::('Terminal::Widgets::Input::Text') }
534+
501535
method default-styles() { hash(set-h => 1) }
502536
}
503537

@@ -534,19 +568,27 @@ class Widget is Node {
534568

535569

536570
#| A structural node to associate a scrollable child with matched scrollbars
537-
class WithScrollbars is Node { }
571+
class WithScrollbars is Node {
572+
method builder-name() { 'with-scrollbars' }
573+
}
538574

539575

540576
# Structural nodes to generate centering node structures
541577

542578
#| A structural node to horizontally center its children
543-
class HCenter is Node { }
579+
class HCenter is Node {
580+
method builder-name() { 'hcenter' }
581+
}
544582

545583
#| A structural node to vertically center its children
546-
class VCenter is Node { }
584+
class VCenter is Node {
585+
method builder-name() { 'vcenter' }
586+
}
547587

548588
#| A structural node to center its children in both directions
549-
class Center is Node { }
589+
class Center is Node {
590+
method builder-name() { 'center' }
591+
}
550592

551593

552594
#| Helper class for building style/layout trees

0 commit comments

Comments
 (0)