NAME

Term::Fabulous::Event::TextClick - A mouse button pressed on a character of a text

SYNOPSIS

use Term::Fabulous::Termbox qw(TB_KEY_MOUSE_RIGHT);

$panel->on( TextClick => sub ($event) {
	my $word = $event->word // return;    # undef on a blank
	show_definition($word) if $event->button == TB_KEY_MOUSE_RIGHT;
	return;
} );

DESCRIPTION

Term::Fabulous fires TextClick on a Term::Fabulous::Widget::Text (a Term::Fabulous::Widget::RichText too) when a mouse button is pressed on one of its characters: the topmost thing painted in the cell under the pointer in the last frame is a line of the text, and the cell holds a character (not the empty rest of the line). Drags, releases and the wheel fire none.

It comes after the Mouse event of the same press, which goes to the widget around the text as always (see "MOUSE" in Term::Fabulous::Manual::Events), and it bubbles from the text to its ancestors, so a container can listen for clicks on any text inside it: $event->target is the text widget. A left press on a link of a RichText fires LinkActivate after it.

The event is a Clay::UI::Events::Event whose name is TextClick.

CONSTRUCTOR

new

my $event = Term::Fabulous::Event::TextClick->new(
	button => TB_KEY_MOUSE_LEFT,
	x      => 12,
	y      => 3,
	offset => 4,
);

The text widget builds these events (see "click_at" in Term::Fabulous::Widget::Text); build one yourself only to test your listeners. Unknown parameters die, as do the values named below. The name and bubble_mode parameters of Clay::UI::Events::Event are accepted.

button

Required. TB_KEY_MOUSE_LEFT, TB_KEY_MOUSE_MIDDLE or TB_KEY_MOUSE_RIGHT.

x, y

Required. The cell of the pointer, counted from 0 at the top left corner of the terminal.

offset

Required. Where the clicked character is in the widget's text, in characters from 0. For a character made of several code points (a letter with a combining accent) it is the offset of the first one.

word, word_start, word_end

The word the character belongs to, the run of non-blank characters around it, with its offset and the offset after its last character. Given together or not at all; undef when the clicked character is blank.

spans

The spans of a RichText that cover the character, as "spans" in Term::Fabulous::Widget::RichText gives them. Default: [].

The target of the RichText's link the character lies in, and the link's index among the widget's links (see "links" in Term::Fabulous::Widget::RichText). Given together or not at all; default undef.

METHODS

button

my $button = $event->button;

The button that was pressed: TB_KEY_MOUSE_LEFT, TB_KEY_MOUSE_MIDDLE or TB_KEY_MOUSE_RIGHT.

x

my $column = $event->x;

The column of the pointer.

y

my $row = $event->y;

The row of the pointer.

offset

my $offset = $event->offset;

The offset of the clicked character in the text.

word

my $word = $event->word;    # or undef

The word under the pointer: the run of non-blank characters the clicked character belongs to, with any punctuation in it ("Foo::Bar,"). undef on a blank.

word_start

my $start = $event->word_start;    # or undef

The offset of the word's first character.

word_end

my $end = $event->word_end;    # or undef

The offset after the word's last character.

spans

foreach my $span ( @{ $event->spans } ) {
	my ( $start, $end, $style ) = @$span;
	...
}

The spans of a RichText that cover the clicked character, in the order they apply: [ $start, $end, $style ] with the normalized style hash. Empty for a plain Text. The result is a copy.

my $target = $event->link;    # or undef

The target of the link under the pointer: whatever the program gave the link (a string from markup). undef when the character lies in no link.

my $index = $event->link_index;    # or undef

The index of that link among the widget's links, or undef.

SEE ALSO

"click_at" in Term::Fabulous::Widget::Text, Term::Fabulous::Event::LinkActivate, Term::Fabulous::Event::Mouse, Term::Fabulous::Manual::Events, and the recipe "React to a click on a word (TextClick)" in Term::Fabulous::Cookbook::KeyboardAndMouse, which shows every field of the event.