Thursday, April 29, 2021

Why didn't I do this before?

Sometimes its so much more convenient (and efficient) to implement something in C rather than Tcl: positioning a popup menu on screen is one of those situations. To this end a new option, -widget, has been added to the menu popup subcommand. 

This causes the callback handler to determine screen coordinates from the on-screen location and height of the widget specified by the -widget option.

Compare:

$abut configure -onClicked "$menu popup -widget %w"

With:

$abut configure -data $menu -onClicked {
        lassign [gnocl::winfo geometry %w] x y w h
        %d popup [expr $x-4] [expr $y+$h] }

This latter approach not only requires memory allocation using -data but 'pollutes' the global namespace with the extra variables 'x y w h' which might result in some form of conflict. 

For those who notice, there is '+4' which is an attempt to handle the buttons style border-width setting. This isn't handled in the callback script, but accommodated in the module core.





No comments: