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

[feature request] Add tooltip (API) #91

Open
Bellisario opened this issue May 26, 2022 · 2 comments
Open

[feature request] Add tooltip (API) #91

Bellisario opened this issue May 26, 2022 · 2 comments

Comments

@Bellisario
Copy link

Would be great if I can use tooltips like in the browser, with a window.js API, obviously.
For example, I hover an element made on the canvas and, checking hover with mouse API, I can decide to show a tooltip if user stop the mouse in this position.

The API could be simply implemented so:

// default don't show any tooltip
window.tooltip = "";

// shows a description while hovering "interesting" content
window.tooltip = "This is a description of what are you hovering!";

// if element is not anymore hovered
window.tooltip = "";

Please, if you like my idea, add a 👍 below!

@joaodasilva
Copy link
Contributor

Tooltips are very useful but I'm not sure how to make this possible in Window.js. The main reason is that Window.js is just an immediate-mode drawing canvas, whereas HTML browsers are retained-mode:

https://en.wikipedia.org/wiki/Retained_mode
https://en.wikipedia.org/wiki/Immediate_mode_(computer_graphics)

This means that browsers know about elements and their position, but Window.js doesn't. So when the mouse hover at (100, 100), the browser knows whether that overlaps with an element that has a tooltip and can thus display it; but Window.js only "retains" the canvas content, which is just pixels really. So it wouldn't know what tooltips to show at what positions.

That said, you still have a couple of options. You can implement tooltips yourself, by keeping a list of rectangles and the tooltip to show for each, and then checking whether the mouse is inside one of those rectangles whenever it moves. Basically, implement tooltips yourself :-) This is essentially what the browser does for you behind the scenes. This is also how videogames do "tooltips" or other animations on hover.

@Bellisario
Copy link
Author

@joaodasilva thanks for your answer!
I know I can implement by myself, but because of too much work, I'll probably choose another way.

I'm not a C++ programmer so I can't help you... but talking about the tooltip API, because of the canvas only "browser", I would probably implement mouse cursor tracking and "auto-follow" by the tooltip and no element tooltip (I think it's impossible to do so), so like to "detect" hover on a button drawn and updating color (checking for mouse coordinates), it just needs a variable to update (issue opening example API with window.tooltip).

I don't know if what I'm saying can be made and is possible, but I think tooltips are a great way to "evolve" this project!
If something I tried to explain is not clear, don't esitate to tag me!

Thanks another time!!!

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

2 participants