-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support GUI key/mouse events on Mac OS X #478
Conversation
Currently they are at taichi/python/taichi/misc/gui.py Line 9 in 2097096
We want it move into gui.h and then exported into gui.py. But this takes a lot of works, and benefits a little - keyboards are unlikely to change, we don't have to keep a table of all key constants. I personally think it doesn't worth it. |
Actually we already have that, eg. |
Sorry about the confusion. I don't mean to export them to python. Instead, just create something like
I mean another enum class (e.g. |
But how to keep gui.py the same with gui/constants.h without export? Maybe a code generator will help. |
My opinion, |
I kind of feel like that's a bit of an overkill as well... My original intention was really just to share these constants among But if we want to do this in a really fancy way, maybe have our own enums (e.g. Line 9 in 2097096
|
Great! Just #define DEF_KEY_CODE(x) case KeyCode::x: return #x;
...
std::string key_code_name(KeyCode c)
{
switch (c) {
DEF_KEY_CODE(SHIFT)
...
}
return "UnknownKey";
} |
I feel like Widgets event shouldn't be mixed with mouse/keyboard events. Widgets are part of the GUI hierarchy, and should be the responder/handler of the input device events. The
The later can be useful for debugging purpose. But yeah, i think the enum is the essential thing here... |
The reason why I mix mouse into key_events was, if we have two queue or two class with same interface, then it is hard to get data from it. eg. |
Yeah, as I said, the GUI works pretty well. I don't think any of these are immediate problems... |
Thanks for the PR and discussions! I'll ship the new interactive features in v0.5.1 by tonight. I believe having a GUI will make people have much more fun with Taichi, yet forgive me that I won't have too much time to think about it right now, since I've got enough things to do (i.e. make sparse computation codegen fully functional and optimized, which I initially promised to finish by end of Jan...). @archibate @k-ye Please feel free to make your own design decisions regarding the GUI. I will probably champion your decisions. About the widgets: #484 |
Follow up of PR #459 by @archibate
I think there are some opportunities for refactoring more:
"Shift"
) can be defined in a single place and shared by all platforms.MouseEvent
should probably include a button field to distinguish left, middle or right.taichi/taichi/visual/gui.h
Line 495 in 2097096
push_back
here:taichi/taichi/visual/gui.h
Line 718 in 2097096
key_events
is a little bit abused for holding mouse events. Maybe haveti.has_input_event()
andti.get_input_event()
? The item returned byti.get_input_event()
has a type to tell if it's a mouse or a keyboard event (or any other input device). But i guess this can be deferred because it's not that trivial and the current GUI works OK enough. @yuanming-hu @archibate Thoughts?