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

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

Closed
wants to merge 3 commits into from

Conversation

soufianekhiat
Copy link

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
Copy link
Member

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
Copy link
Author

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:

  • Either we change the callback which will receive as parameter let say an ImVec2 which is ImGui::GetContentRegionAvail();
    OR
  • As you propose a boolean on the struct (cf. my last push)

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

@dougbinks
Copy link
Member

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.

@juliettef juliettef added the enhancement New feature or request label Jan 5, 2021
@soufianekhiat
Copy link
Author

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
Copy link
Member

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

@juliettef juliettef closed this in 1aadefd Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants