• [Tk] text widget & "see" for yet-unmapped widgets.

    From Andreas Leitgeb@21:1/5 to All on Thu Aug 26 22:14:23 2021
    In my application I create text widgets, fill them with text-content,
    and eventually use ".text see ..." to make sure that a particular
    part of the content is visible once the widget becomes visible.

    E.g.: the text-widget contains 10 lines of context, and is setup
    for a height of 8 lines (and a scrollbar), and I use "see" to make
    sure that line 2 is initially visible. This may as well be a different
    number - in some cases I may need to have line 10 initially visible.
    The part of code doing the "see" is agnostic of the text widget's
    current visibility/realization.

    Now the problem: If - by the time I use the "see" command - the widget
    isn't yet visible (but it's requested width&height are already confed)
    then internally it seems to believe a size of 1x1 pixels, and therefore
    it sets the initial scrollposition to the second line, although second
    line would be eventually perfectly visible even without scrolling.

    Once the text widget is visible, "see" does a perfect job of determining
    the need to scroll for the target, but it would be nice if it could
    do the same job for not-yet-<Configure>d widgets, and in that case
    based on the requested sizes, lacking actual sizes.

    I can imagine some workarounds (e.g. postponing the "see" using "after
    idle ...", or explicitly calculating the initial need for scroll, or
    explicitly re-implementing "see" in my own code, but none of them
    seem nice to me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Fri Aug 27 08:26:34 2021
    Am 27.08.2021 um 00:14 schrieb Andreas Leitgeb:
    In my application I create text widgets, fill them with text-content,
    and eventually use ".text see ..." to make sure that a particular
    part of the content is visible once the widget becomes visible.

    E.g.: the text-widget contains 10 lines of context, and is setup
    for a height of 8 lines (and a scrollbar), and I use "see" to make
    sure that line 2 is initially visible. This may as well be a different number - in some cases I may need to have line 10 initially visible.
    The part of code doing the "see" is agnostic of the text widget's
    current visibility/realization.

    Now the problem: If - by the time I use the "see" command - the widget
    isn't yet visible (but it's requested width&height are already confed)
    then internally it seems to believe a size of 1x1 pixels, and therefore
    it sets the initial scrollposition to the second line, although second
    line would be eventually perfectly visible even without scrolling.

    Once the text widget is visible, "see" does a perfect job of determining
    the need to scroll for the target, but it would be nice if it could
    do the same job for not-yet-<Configure>d widgets, and in that case
    based on the requested sizes, lacking actual sizes.

    I can imagine some workarounds (e.g. postponing the "see" using "after
    idle ...", or explicitly calculating the initial need for scroll, or explicitly re-implementing "see" in my own code, but none of them
    seem nice to me.


    Andreas,
    the real size (winfo reqwidth/winfo reqheight) and current size (winfo width/winfo height) is only available and updated after an "update
    idletasks".
    I recommend you to:
    - weather insert "update idletasks" with the risks that anything may
    happen, including program stop
    - or to do "after 1 [list $w see $item]

    Others may have more insights.

    Take care,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Fri Aug 27 11:18:38 2021
    * Andreas Leitgeb <avl@logic.at>
    | I can imagine some workarounds (e.g. postponing the "see" using "after
    | idle ...", or explicitly calculating the initial need for scroll, or
    | explicitly re-implementing "see" in my own code, but none of them
    | seem nice to me.

    Bind to the <Map> event (probably just to the first one, removing the
    binding in the bind script)?

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)