Hi artemave,

zentara is correct; you could easily do this by using the bbox method of a Tk::Text object.

Here's an example program:

#!/usr/bin/perl -w + use strict; use warnings; use Tk; + # Globals my @filler = qw( just a bunch of filler words ... ); + # Main program my $mw = new MainWindow(-title => 'Detect_if_text_visible'); my @opts = (-bg => 'peachpuff', -width => 32, -height => 16); push @opts, -wrap => "none"; my $txt = $mw->Scrolled('Text', @opts, -scrollbars => "osoe"); $txt->tagConfigure('white', -background => 'white'); $txt->tagConfigure('target', -background => 'red'); $txt->pack(-expand => 1, -fill => 'both'); insert_filler(20); $txt->insert("end", 'TARGET is to the right ==============> ', 'white' +); $txt->insert("end", "X", 'target'); $txt->insert("end", ' <=============== TARGET is to the left', 'white' +); $txt->insert("end", "\n"); insert_filler(20); $mw->repeat(1000 => \&idle_loop); $mw->bind("<Escape>" => sub { $mw->destroy() }); MainLoop; + + # Subroutines sub insert_filler { my ($nlines) = @_; for (my $i = 0; $i < $nlines; $i++) { my $line = (join(" ", @filler) . " ") x 4; my $word = shift @filler; push @filler, $word; $txt->insert("end", "$line\n"); } } + + sub idle_loop { my $index = $txt->index("target.first"); my $bbox = $txt->bbox($index); if ($bbox) { print "Index '$index' is VISIBLE\n"; } else { print "Index '$index' NOT visible\n"; } }

It creates a Tk::Text window filled with a bunch of lines.  The middle line is highlighted in white to make it easier to see, and approximately in the middle of the line is a red 'X'.

When you first run the program, the 'X' is NOT visible, but you can scroll in either direction to make the 'X' come into view.

Every second the idle_loop is called, which will report whether the 'X' is visible or not, depending on the results of bbox.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Tk::Text. How to find out if char is visible? by liverpole
in thread Tk::Text. How to find out if char is visible? by artemave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.