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

Text wrapping in auto-resizing window (was: ossible modal bug / auto-resize) #778

Closed
r-lyeh-archived opened this issue Aug 14, 2016 · 4 comments

Comments

@r-lyeh-archived
Copy link

r-lyeh-archived commented Aug 14, 2016

image

I dont know if I am doing right, but inserting TextWrapped() inside a BeginPopupModal() seems to break it.

if (ImGui::Button("Delete.."))
    ImGui::OpenPopup("Delete?");
if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
    ImGui::TextWrapped("Modal windows are like popups but the user cannot close them by clicking outside the window.");
    ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
    ImGui::Separator();
// etc...

Keep up the good work :)

@ocornut
Copy link
Owner

ocornut commented Aug 14, 2016

Text wrapping without an explicit wrapping position and ImGuiWindowFlags_AlwaysAutoResize are not really compatible / somehow contradictory flags if there aren't other preceeding items in the window.

TextWrapped() needs a known width to wrap and here you are requesting automatic width.

From a end-user perspective what width do you expect the window to have? Would you want the window to fit exactly the width of the OK/Cancel buttons? In that case the text wrapping would depends on the width OK/Cancel buttons, that would work and feel correct but also probably rather odd and mildly desirable. It may just be more desirable to have a default width for the window all-together?

The workaround/fix now is to specific a width to your window or disable always-auto-resize on it.

@r-lyeh-archived
Copy link
Author

Aha, well but it also breaks with no AlwaysAutoResize flag but in a different way!
I guess I just use Text() and no big worries :D

Thanks for the quick response!

@ocornut
Copy link
Owner

ocornut commented Aug 14, 2016

You can use SetNextWindowSize(width, 0) or PushTextWrapPos(width); Text(); PopTextWrapPos().

It is a rather common issue/pattern I'd like to solve/improve in a better way. It's currently quite confusing for everyone who wants to do the same thing as you. Perhaps TextWrapped() should fallback to use MAX(SOME_DEFAULT_WIDTH, WINDOW_WIDTH).

@ocornut ocornut reopened this Aug 14, 2016
@ocornut ocornut added the layout label Aug 14, 2016
@ocornut ocornut added the popups label Aug 16, 2017
@ocornut ocornut changed the title Possible modal bug (auto-resize) Text wrapping in modal/popup window (was: ossible modal bug / auto-resize) Jun 23, 2020
@ocornut ocornut changed the title Text wrapping in modal/popup window (was: ossible modal bug / auto-resize) Text wrapping in auto-resizing window (was: ossible modal bug / auto-resize) Jun 23, 2020
@ocornut
Copy link
Owner

ocornut commented Jun 23, 2020

Closing this old issue, note that it's not particularly related to popups but simple that TextWrapped() + AlwaysAutoResize flag without an explicit width is contradictory or ambiguous.

So this repro just as well:

ImGui::Begin("Always", NULL, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::TextWrapped("Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet");
ImGui::End();

I've added myself some note about how we could proceed and would like to redesign text wrapping eventually so may come back to it, but right now I've got no other answer than having to push a text wrap pos.

And we cannot push a default wrap pos for auto-resizing windows since as implemented, using PushTextWrapPos() has lots of other side-effects. Pretty much none of those effects aredesirable ihmo, which make me think the whole PushTextWrapPos() api is undesirable as-is and should be redesigned, vs TextWrapped() itself is useful. We do however want to solve #2313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants