Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elements: make right-click popup-menu to any state
We have to use `(send this popup-menu …)` rather than `(render-popup-menu …)` because 1. The latter requires a renderer, which would probably be the renderer for the root window of the application, and 2. The latter renders in coordinates specified by the root window of the renderer. Since the canvases to which we apply the mixins _are_ gui windows (https://docs.racket-lang.org/gui/windowing-overview.html#%28part._.Core_.Windowing_.Classes%29), the mouse-click event is reported in coordinates of the canvas. When we try to render the popup-menu via `(render-popup-menu …)` with a renderer built from `(render (window … elements-cycler …))`, the menu ends up being placed at the wrong coordinates. In a diagram: ------------------------------ | | | p | | ----- ----- ----- | | | | | | | | | | | | | | | x | | | ----- ----- ----- | | A B C | | | ------------------------------ The 'x' marks the click. We want the popup to appear there, but the coordinates we are given are in terms of the canvas 'C' (roughly (1,1) here). When rendered on the outer window, that shows the popup-menu at position 'p'! So, we borrow the logic of `render-popup-menu` from `racket/gui/easy/private/renderer`, but swapping in the canvas window (_i.e._, `this`). That way, the coordinates are specified appropriately. This is done by something of a hack: the `renderer%` class is not available publicly from `racket/gui/easy` or from its internal private modules, so to access it we use Racket's namespace reflection capabilities. If there were a way to translate the coordinates of the canvas to coordinates of the parent window, we could probably use `render-popup-menu` with the renderer for the parent window.
- Loading branch information