Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix imgui popup menus #695

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

Merged
merged 4 commits into from
Jan 26, 2025
Merged

Fix imgui popup menus #695

merged 4 commits into from
Jan 26, 2025

Conversation

kushalkolar
Copy link
Member

@kushalkolar kushalkolar commented Jan 17, 2025

fixes #694

The kwargs for the imgui popup menu for right clicks got more strict in the v1.6.0 release. Was annoying to troubleshoot since I was first getting errors stating that the previous imgui frame had not been ended and to call imgui.end_frame(). So then I added an extra imgui.end_frame() within the right click menu and it produced the actual error which was that imgui wasn't happy with the types of the kwargs 🤷‍♂️

So before we had things like this for example:

imgui.menu_item("item name", None, val > 0)

# signature
menu_item(str, str, bool)

args are: (item name, keyboard shortcut, selected)

So before it worked if we gave None for the second arg which is keyboard shortcut, now it has to explicitly be "". And it's not taking expressions that results in a bool for whatever reason anymore.

So in summary the above needs to become the following for imgui v1.6.0 to be happy:

menu_item("item name", "", bool(val > 0))

@kushalkolar kushalkolar requested a review from clewis7 as a code owner January 17, 2025 01:17
@kushalkolar
Copy link
Member Author

@clewis7 ready for review!

Copy link

github-actions bot commented Jan 17, 2025

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/fix-imgui-popup-menus

@kushalkolar
Copy link
Member Author

oh wait let me add a test

@clewis7
Copy link
Member

clewis7 commented Jan 20, 2025

I'll wait for test before doing a review :D

@kushalkolar
Copy link
Member Author

ok so I looked into how we could have a test for this and we can't right now since the offscreen canvas does not have things like click events, we can look into this later, can ask almar.

@kushalkolar kushalkolar force-pushed the fix-imgui-popup-menus branch from e5cbc2d to 17730c4 Compare January 25, 2025 06:22
@kushalkolar
Copy link
Member Author

so there is canvas.submit_event() which we can use to offscreen test the right click menu :D

#705 (comment)

@kushalkolar
Copy link
Member Author

so there is canvas.submit_event() which we can use to offscreen test the right click menu :D

#705 (comment)

I just tried this, works for qt canvas but not offscreen 🤷‍♂️ . Documenting here for now, let's just merge this and figure it out later.

"""
Test right click menu
=====================

Screenshot test for the right click menu
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np

figure = fpl.Figure(size=(700, 560))

# for some reason right click menu doesn't show if the scene is completely empty
figure[0, 0].add_image(np.zeros((2, 2)), cmap="gray")


figure[0, 0].axes.visible = False

figure.show()


data = {"x": 10, "y": 10, "modifiers": (), "n_touches": 0, "touches": {}}

move = {
    "event_type": "pointer_move",
    "button": 0,
    "buttons": (),
    **data,
}
down = {
    "event_type": "pointer_down",
    "button": 2,
    "buttons": (2,),
    **data,
}
up = {
    "event_type": "pointer_up",
    "button": 2,
    "buttons": (),
    **data,
}


figure.canvas.submit_event(move)
figure.canvas.submit_event(down)
figure.canvas.submit_event(up)


if __name__ == "__main__":
    print(__doc__)
    fpl.loop.run()

@clewis7 clewis7 merged commit f3c7879 into main Jan 26, 2025
25 of 28 checks passed
@clewis7 clewis7 deleted the fix-imgui-popup-menus branch January 26, 2025 02:15
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

Successfully merging this pull request may close these issues.

right click menu is broken
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.