« blib/lib/Term/Fabulous/Widget/Table/Grid.pm
↑ Summary
blib/lib/Term/Fabulous/Widget/Table/Model.pm »
| 1 | package Term::Fabulous::Widget::Table::HeaderView; | ||
| 2 | |||
| 3 | use v5.32; | ||
| 4 | use warnings; | ||
| 5 | use feature 'signatures'; | ||
| 6 | no warnings 'experimental::signatures'; | ||
| 7 | |||
| 8 | our $VERSION = '0.03'; | ||
| 9 | |||
| 10 | use Object::Pad 0.825; | ||
| 11 | |||
| 12 | use Term::Fabulous::Widget::Box; | ||
| 13 | |||
| 14 | class Term::Fabulous::Widget::Table::HeaderView :isa(Term::Fabulous::Widget::Box) :strict(params) { | ||
| 15 | use Scalar::Util qw(weaken); | ||
| 16 | |||
| 17 | # The scroll container whose horizontal position the header follows. | ||
| 18 | field $follows :param; | ||
| 19 | |||
| 20 | ADJUST { | ||
| 21 | die "Term::Fabulous::Widget::Table::HeaderView: follows must be a scroll container" | ||
| 22 | unless defined $follows && $follows->DOES('Clay::UI::Role::Layout::HasScroll'); | ||
| 23 | weaken $follows; | ||
| 24 | } | ||
| 25 | |||
| 26 | # Clips the header at its own width and shifts it by the horizontal | ||
| 27 | # scroll position the scroll container has in this frame (Clay has | ||
| 28 | # applied the wheel before the layout starts). | ||
| 29 | method contribute_clip ($config) { | ||
| 30 | my $ui = $self->ui; | ||
| 31 | my $state = defined $ui && defined $follows ? $ui->scroll_state($follows) : undef; | ||
| 32 | $config->{clip} = { horizontal => 1, vertical => 0, child_offset => { x => defined $state ? $state->{position}{x} : 0, y => 0 } }; | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ |