Re: Operate only on the visible lines in a text window

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Operate only on the visible lines in a text window
De : ralfixx (at) *nospam* gmx.de (Ralf Fassel)
Groupes : comp.lang.tcl
Date : 10. Jul 2024, 09:59:00
Autres entêtes
Message-ID : <ygaikxdy65n.fsf@akutech.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
* 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'

Date Sujet#  Auteur
10 Jul 24 * Operate only on the visible lines in a text window5Shaun Deacon
10 Jul 24 +- Re: Operate only on the visible lines in a text window1et99
10 Jul 24 +- Operate only on the visible lines in a text window1clt.to.davebr
10 Jul 24 `* Re: Operate only on the visible lines in a text window2Ralf Fassel
10 Jul 24  `- Re: Operate only on the visible lines in a text window1Shaun Deacon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal