Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render popup-menus relative to a child widget? #28

Closed
benknoble opened this issue Oct 31, 2022 · 1 comment
Closed

Render popup-menus relative to a child widget? #28

benknoble opened this issue Oct 31, 2022 · 1 comment

Comments

@benknoble
Copy link
Contributor

benknoble commented Oct 31, 2022

The render-popup-menu function takes x-y coordinates and renders a popup-menu (pum) relative to the root widget of a renderer.

Canvases are windows and can react to mouse events, so I can use a mixin with, say, pict-canvas to make right-clicks shows a popup-window if I have a renderer. The mouse-event's x-y coordinates are relative to the canvas (!).

I get a renderer only by calling render on the full tree of views, so its root widget is from the (window …) view.

This combines to result in the x-y coordinates being relative to the wrong part of the GUI, so the pum is in the wrong place.

Possible solutions I've come up with:

  1. Hack around it, duplicate some things from render-pum via reflection (benknoble/frosthaven-manager@53c567c)
  2. Translate the canvas x-y coordinates with respect to (renderer-root …). This would probably be much nicer, but I can't figure out how to do it.
  3. Manually compute approximate coordinates based on expected layout. This doesn't sit well with me, especially since I expect to re-use some views in very different compositions or layouts.

Have you run into this in the past? How did you solve it?

@benknoble
Copy link
Contributor Author

Update: roughly, the following approach works:

(define (clicker-mixin …)
  (mixin (canvas<%>) ()
    (super-new)
    (define/override (on-event e)
      (case (send e get-event-type)
        [(left-down) (…)]
        [(right-down)
         (define pum (popup-menu …))
         (apply
           render-popup-menu
           (current-renderer)
           pum
           (let* ([child-x (send e get-x)]
                  [child-y (send e get-y)]
                  [top (renderer-root (current-renderer))])
             (let loop ([x child-x]
                        [y child-y]
                        [container (send this get-parent)])
               (if (eq? container top)
                 (list x y)
                 (loop (+ x (send container get-x))
                       (+ y (send container get-y))
                       (send container get-parent))))))]))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant