• Can I anchor a canvas element to the visible screen?

    From Luc@21:1/5 to All on Tue Nov 15 09:40:28 2022
    I have a canvas with a chart, a bar chart, and a grid background. Or maybe
    that is more accurately described as a canvas with a grid and a bar chart
    on top of it. It seems to me that whatever is drawn last becomes "on top"
    of everything else.

    And there is a "floating" canvas label that displays some data in a much more evident way.

    I have managed to make that chart "scrollable" left and right. I use the arrow keys for that. But when I scrolled, the floating label would be pushed off the right edge of the screen. I fixed that:


    proc scrollchart {leftright} {
    lassign [$::chart xview] x1 x2
    if {$leftright == "left"} {
    $::chart xview moveto [expr $x1 - 0.0005]
    set ::toplabel_x [expr $::toplabel_x - 10]
    }
    if {$leftright == "right"} {
    $::chart xview moveto [expr $x1 + 0.0005]
    set ::toplabel_x [expr $::toplabel_x + 10]
    }


    That works very well. The label flickers a little, but it stays put.

    But there is also this:

    bind $::chart <B1-Motion> {%W scan dragto %x %y 1}

    That works to the extent that I can indeed drag the chart left and right
    with the mouse pointer, but then the floating label gets dragged too, which
    I obviously don't want.

    Maybe there is some code I could use to compensate for the movement like I did in the scrollchart proc, but then I think, everything would be so much easier if I could anchor some elements to some edge or corner of the visible screen rather than to the canvas' hard coordinates.

    I am struggling with that concept. Can someone please shed some light?

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Nov 15 16:36:54 2022
    * Luc <[email protected]>
    | I have a canvas with a chart, a bar chart, and a grid background. Or maybe
    | that is more accurately described as a canvas with a grid and a bar chart
    | on top of it. It seems to me that whatever is drawn last becomes "on top"
    | of everything else.

    | And there is a "floating" canvas label that displays some data in a
    | much more evident way.

    | I have managed to make that chart "scrollable" left and right. I use the arrow
    | keys for that. But when I scrolled, the floating label would be pushed off the
    | right edge of the screen.
    --<snip-snip>--
    | That works to the extent that I can indeed drag the chart left and right
    | with the mouse pointer, but then the floating label gets dragged too, which
    | I obviously don't want.

    Rather than trying to compensate for the canvas scrolling, place the
    'floating' label in a separate canvas and [place] that one in the
    original canvas?

    canvas .c1 ; # the scrolled canvas
    canvas .c1.c2 ; # the one with the floating label
    place .c1.c2 -relx 0 -rely 0 ; # always top left in .c1

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Ralf Fassel on Tue Nov 15 13:52:50 2022
    On Tue, 15 Nov 2022 16:36:54 +0100, Ralf Fassel wrote:

    Rather than trying to compensate for the canvas scrolling, place the 'floating' label in a separate canvas and [place] that one in the
    original canvas?

    canvas .c1 ; # the scrolled canvas
    canvas .c1.c2 ; # the one with the floating label
    place .c1.c2 -relx 0 -rely 0 ; # always top left in .c1

    R'


    Thanks.

    That works in terms of positioning, but then the floating canvas eclipses
    the background grid. Sadly, there is no transparent canvas in Tk.


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Adrien Peulvast@21:1/5 to All on Wed Nov 16 14:28:43 2022
    Le 16/11/2022 à 00:52, Luc a écrit :
    On Tue, 15 Nov 2022 16:36:54 +0100, Ralf Fassel wrote:

    Rather than trying to compensate for the canvas scrolling, place the
    'floating' label in a separate canvas and [place] that one in the
    original canvas?

    canvas .c1 ; # the scrolled canvas
    canvas .c1.c2 ; # the one with the floating label
    place .c1.c2 -relx 0 -rely 0 ; # always top left in .c1

    R'


    Thanks.

    That works in terms of positioning, but then the floating canvas eclipses
    the background grid. Sadly, there is no transparent canvas in Tk.



    Hello, but there is "transparent" toplevel in which you could pack the
    canvas and then use the transparent color in canvas background. Then
    place the transparent toplevel where you wish to.

    --
    Cet e-mail a été vérifié par le logiciel antivirus d'Avast.
    www.avast.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Wed Nov 16 12:23:07 2022
    * Adrien Peulvast <[email protected]>
    | Le 16/11/2022 à 00:52, Luc a écrit :
    | > Thanks.
    | > That works in terms of positioning, but then the floating canvas
    | > eclipses the background grid. Sadly, there is no transparent canvas in Tk. | >

    | Hello, but there is "transparent" toplevel in which you could pack the
    | canvas and then use the transparent color in canvas background.

    What is the "transparent color" for the canvas? Could you show the
    -configure line?

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Wed Nov 16 15:28:29 2022
    What is the "transparent color" for the canvas? Could you show the
    -configure line?

    R'

    The top level manpage mentions setting -background ""

    However the result on Slackware Linux with a fvwm window manager is rather weird.

    Apparently each time a section of the toplevel is uncovered, it just copies the stuff obscuring the toplevel into its own background. However the toplevel ignores the background when it is moved.
    In addition, once some background is copied to the toplevel it stays there until that section of the toplevel is covered and uncovered again.

    Looks singularly useless. Perhaps I'm misusing it somehow.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From APE@21:1/5 to All on Wed Nov 16 18:25:25 2022
    Le mercredi 16 novembre 2022 à 23:28:13 UTC+8, [email protected] a écrit :
    What is the "transparent color" for the canvas? Could you show the >-configure line?

    R'
    The top level manpage mentions setting -background ""

    However the result on Slackware Linux with a fvwm window manager is rather weird.

    Apparently each time a section of the toplevel is uncovered, it just copies the stuff obscuring the toplevel into its own background. However the toplevel ignores the background when it is moved.
    In addition, once some background is copied to the toplevel it stays there until that section of the toplevel is covered and uncovered again.

    Looks singularly useless. Perhaps I'm misusing it somehow.

    Dave B

    Sorry my answer was not so clear : I meant using the -transparent and -transparentcolor toplevel attributes

    The following little script gives an example (I am using a wish console, so toplevel . is created) :

    wm attributes . -transparent; # toplevel has transparent attribute
    wm attributes . -transparentcolor green; # the"transparent" color is "green" (can be any other color)
    wm overrideredirect . 1; # remove decorative frame. Need more to remove borders though
    pack [canvas .c -bg green]
    .c create line 10 10 100 100 -fill blue -width 10

    Now you have a blue line floating on the screen.

    Then more work is needed to manage this toplevel when the parent toplevel changes

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