Render image alt text as a link if image is not drawn
Hello again!
Currently, the 'Image not loaded' message is rendered if an image wasn't drawn. There are 2 issues with this:
- ImGui::Text is used, which doesn't wrap the text.
- The image alt text should be rendered as a link instead. If there is no alt text, nothing should be rendered. This is how GitHub Markdown works for example.
This PR renders the image alt text as a link if an image wasn't drawn.
This message is intended for debug purposes, I'm not sure we would want this to silently fail or to draw the alt text as a link.
Perhaps we could include a debug setting in MarkdownConfig (default to false) and then if this is enabled show the URL as before, otherwise use your revision?
Given that the "failure" happens when no image callback is defined or when it returns a MarkdownImageData with isValid set to false, then the user already knows there is an issue, so there shouldn't be any surprises if the image wasn't drawn.
If the library was actually checking for the validity of the image texture or if ImGui::ImageWithBg was returning a boolean value for example, I can perhaps see a use case for a debug mode. But with how things are set currently, I don't think a debug mode makes sense.
so there shouldn't be any surprises if the image wasn't drawn.
I disagree. There are two errors possible here as you've identified. Rather than decreasing the amount of debug information presented to the developer we should probably add a little more.
But with how things are set currently, I don't think a debug mode makes sense.
I do.
Thinking about it more I also think that using the RenderLinkTextWrapped when one may not have been intended is a risk. We probably need 3 options: show debug text, show nothing, or show a link. The default probably being the debug text.
I'll get around to making these changes and merge your code in with the new code when I have time.