Audio-Nama

 view release on metacpan or  search on metacpan

lib/Audio/Nama/Entry.pm  view on Meta::CPAN


Returns the current entry position, in terms of characters within the text.

=cut

# generated accessor

=head2 set_position

   $entry->set_position( $position );

Set the text entry position, moving the cursor

=cut

method set_position
{
   my ( $pos_ch ) = @_;

   $pos_ch = 0 if $pos_ch < 0;
   $pos_ch = length $_text if $pos_ch > length $_text;

   $self->reposition_cursor( $pos_ch );
}

=head1 METHODS

=cut

=head2 bind_keys

   $entry->bind_keys( $keystr => $value, ... );

Associate methods or CODE references with keypresses. On receipt of a the key
the method or CODE reference will be invoked, being passed the stringified key
representation and the underlying C<Term::TermKey::Key> structure.

   $ret = $entry->method( $keystr, $key );
   $ret = $coderef->( $entry, $keystr, $key );

This method takes a hash of keystring/value pairs. Binding a value of C<undef>
will remove it.

=cut

method bind_keys
{
   while( @_ ) {
      my $str   = shift;
      my $value = shift;

      if( defined $value ) {
         $_keybindings{$str} = $value;
      }
      else {
         delete $_keybindings{$str};
      }
   }
}

=head2 make_popup_at_cursor

   $win = $entry->make_popup_at_cursor( $top_offset, $left_offset, $lines, $cols );

I<Since version 0.33.>

Creates a new popup window, as if calling L<Tickit::Window/make_popup> on the
widget's main window, but with an offset relative to the current cursor
position.

An offet of (0, 0) will position the popup window's top left corner exactly over
the cursor; this is likely not what you want.

To position the popup just below the widget, use a top offset of +1:

   $win = $entry->make_popup_at_cursor( +1, 0, $lines, $cols );

To position the popup just above the widget, use a top offset of negative the
number of lines:

   $win = $entry->make_popup_at_cursor( -$lines, 0, $lines, $cols );

=cut

method make_popup_at_cursor
{
   my ( $topoff, $leftoff, $lines, $cols ) = @_;

   $self->window or
      croak "Cannot ->make_popup_at_cursor on an Entry widget with no window";

   my $pos_x = $self->char2col( $_pos_ch ) - $_scrolloffs_co;

   return $self->window->make_popup( $topoff, $pos_x + $leftoff, $lines, $cols );
}

=head1 TEXT MODEL METHODS

These methods operate on the text input buffer directly, updating the stored
text and changing the rendered display to reflect the changes. They can be
used by a program to directly manipulate the text.

=cut

=head2 text

   $text = $entry->text;

Returns the currently entered text.

=cut

# generated accessor

=head2 set_text

   $entry->set_text( $text );

Replace the text in the entry box. This completely redraws the widget's
window. It is largely provided for initialisation; for normal edits (such as
from keybindings), it is preferable to use C<text_insert>, C<text_delete> or
C<text_splice>.

=cut

method set_text
{
   my ( $text ) = @_;

   $_text = $text;
   $_pos_ch = length $text if $_pos_ch > length $text;

   $self->redraw;
}

=head2 text_insert

   $entry->text_insert( $text, $pos_ch );

Insert the given text at the given character position.

=cut

method text_insert
{
   my ( $text, $pos_ch ) = @_;

   $self->text_splice( $pos_ch, 0, $text );
}

=head2 text_delete

   $deleted = $entry->text_delete( $pos_ch, $len_ch );



( run in 1.538 second using v1.01-cache-2.11-cpan-364913b4093 )