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
How to handle click events? #16
Comments
@Widdershin Asked me to detail my use case for this. It's pretty straight forward. I have to make a sort of chart where the y axis is a list of people and the x axis is time. I have to be able to move the bars inside the chart, so it would be convenient if I could do something like: Canvas.select(some_sort_of_id).events(click) -> stream of events with information about the pressed mouse buttons etc... I think this would also require implementing isolation so that the individual bars could easily be defined as separate instances of a component. So yeah... pretty much the same as the DOM driver. :) |
This is an interesting problem. Drawing to a canvas simply paints the pixels on the canvas. Any information about what was painted there (a circle, square, text, an image) is lost. To be able to tell what "entity" was clicked on, you need to have the information about what was drawn to the screen (like the vtree used internally in the canvas driver, or just an object where you kept all your entities before even calling Long story short, you need this:
Inside that function, you'll have to figure out the layout of all your entities:
You can do it yourself right now, just getting the clicks from the canvas element and creating your implementation of This is a very interesting problem to solve, but I would question if it is something that Another option is to use SVG, as you can attach event listeners to SVG elements in the DOM. I don't know if there's a svg-driver for cyclejs yet. |
Thanks for the response! I think it would be cool if the canvas driver had similar ergonomics to the DOM driver, Perhaps it could even wrap a library which works on WebGL and falls back to canvas when WebGL isn't available? pixi.js and ivank come to mind, though it might be preferable (for some reason) to make your own. If you go for a game engine, I think WebGL would probably be good. |
If you don't mind me bringing this relatively dusty issue back up, I think we really should provide an API for clicking (and I will gladly work on it). Of course, I am thinking of something very basic that'll just give you the coordinates, and possibly modifier keys. That means tracking entities is left entirely to the user. The way I see it, clicking the canvas is a very common interaction so it makes sense to include it in this driver. |
#35 does indeed close this. |
Should we provide an API for clicking on parts of the canvas? or should this be a separate driver?
The text was updated successfully, but these errors were encountered: