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