enkisoftware / imgui_markdown

Markdown for Dear ImGui
zlib License
1.03k stars 69 forks source link

Image Resize when available size.x > image width #15

Closed soufianekhiat closed 3 years ago

soufianekhiat commented 3 years ago

Resize when ImGui::GetContentRegionAvailWidth() < imageData.size.x with respect of image ratio. Xxqp7e86q0 Tested to support image position on the line (not convicing).

float const imgPos = ImGui::GetCursorPosX();
contentSize.x -= imgPos;

TBD: support for:

![Alt](imgs/Image.png =250x50)
// And
![Alt](imgs/Image.png =250x)
juliettef commented 3 years ago

Thanks for the PR and apologies for the delay.

@dougbinks and I'd prefer the imageCallback to handle sizing. Indeed, although I could add a boolean to the MarkdownImageData struct to select whether to resize if not enough space, this could become unwieldy.

I think this would be more suitably added to the documentation as an example of how to auto-resize in the ImageCallback() definition in https://github.com/juliettef/imgui_markdown/blob/master/README.md#example-use-on-windows-with-links-opening-in-a-browser

Do you want to update your PR to modify the readme example or do you prefer me to do it?

soufianekhiat commented 3 years ago

I see, for now imageCallback do not allow use allow us to handle the resize of the image. Currently the image callback is agnotic of the current ImWindow. Two solutions:

What do you think? Personaly I prefer the first one, which fit in the essence of "The callback manage the resize".

dougbinks commented 3 years ago

The imageCallback function is called immediately before ImGui::Image is called, and so the ImGui context state is in the correct state to call ImGui::GetContentRegionAvail() as needed: https://github.com/juliettef/imgui_markdown/blob/master/imgui_markdown.h#L584-L590

So the exact same code should work from within the imageCallback function, returning the size via the MarkdownImageData struct. Thus there are no changes needed to the callback.

soufianekhiat commented 3 years ago

I understand, it's just counter intuitive for me to have the user aware of the implementation, particularly with a callback. Feel free to close this PR otherwise I can provide an update.

Best

dougbinks commented 3 years ago

Yes, I agree it's not intuitive so we need to improve the documentation & examples. Thanks for highlighting this issue!