Deutsch English Français Italiano |
<v6mgts$20kdd$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Shaun Deacon <sdeacon@us.socionext.com> Newsgroups: comp.lang.tcl Subject: Re: Operate only on the visible lines in a text window Date: Wed, 10 Jul 2024 10:38:03 -0700 Organization: A noiseless patient Spider Lines: 47 Message-ID: <v6mgts$20kdd$1@dont-email.me> References: <v6kmal$1jhpc$1@dont-email.me> <ygaikxdy65n.fsf@akutech.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 10 Jul 2024 19:38:05 +0200 (CEST) Injection-Info: dont-email.me; posting-host="db322dc0cb279ba3e16fe8c0158af72d"; logging-data="2118061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/UcUXl8cBYF6k/l+Xye1h" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.18.2 Cancel-Lock: sha1:gGdac2DioFX6n8DafDnwAPDc1A0= In-Reply-To: <ygaikxdy65n.fsf@akutech.de> Bytes: 2834 Ralf Fassel wrote: > * Shaun Deacon <sdeacon@us.socionext.com> > | The obvious solution to me is to just highlight the currently visible > | lines (or a range of lines spanning the current view - say 1000 or so) > | and when the user scrolls the window, highlight the new set of lines. >> > | Suggestions on the best way to find the indexes for the currently > | visible lines when the widget has been scrolled would be great. >> > | Can someone please point me in the right direction ? > > You could try 'text yview' and derive the displayed lines from that: > > grid [text .t -yscrollcommand {recalc {.s set}}] -sticky ewns -row 0 -column 0 > grid [scrollbar .s -command {recalc {.t yview}} -orient vertical] -sticky ns -row 0 -column 1 > grid [label .l] - -sticky ewns > grid rowconfigure . 0 -weight 1 > grid columnconfigure . 0 -weight 1 > for {set l 1} {$l < 1000} {incr l} { > .t insert end "Line $l\n" > } > > proc recalc {cmd args} { > # scroll if required > if {$cmd ne ""} { > {*}$cmd {*}$args > } > # Determine the visible range > lassign [.t yview] start end > # Get line count > set lines [lindex [split [.t index end] "."] 0] > # Get first and last line displayed. > # Here you need to determine what to do with the partially displayed lines > set first [format %.1f [expr {$start*$lines+1}]] > set last [format %.1f [expr {$end*$lines}]] > > .l configure -text "visible Lines $first ... $last" > } > bind . <Configure> [list recalc ""] > > HTH > R' > Thanks Ralf, this looks promising to me. Shaun