-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Multiline text input horizontal scrolling #383
Comments
Yes we could, but measuring width is costly and we tend to avoid it this is why the multi-line text input still use single-line still scrolling.
That code is quite complex for various reason so it's not a trivial change but I could look into the middle-ground solution sometimes. |
Untested idea but you could declare a larger child window for scrolling and create the widget inside it using all the width of it. |
Hmm... is it not possible to calculate the max line width whenever text is input into the box rather than recomputing every frame? Or is that what you were referring to in your rewrite that you don' t have time for? :) |
Yes that sort of thing. That would work but for very large text it would have an effect on interaction. However we could add it, I just don't have any enough time to do it all :) |
PS: First thing you can do is call PushItemWidth(-1.0f) to left-align and remove the label so that field. |
Sorry for the late response, I just got back to doing a little bit of GUI work and came to revisit this. I thought about your suggestion of creating a child window and I came up with the following code:
It's a little bit of a hack (probably doing some bad things here) but seems to work for me. Problems are that the vertical scrollbar isn't really accessible and the horizontal scrollbar is sized according to a very large constant set ahead of time, but these are small issues for us compared to just having the horizontal scrolling available. Here's what it looks like in action: -Dale Kim |
Reviving this topic because #1224 raised it. Thanks Dale and sorry I haven't reacted on your idea yet. As posted in the other thread here is another temporary solution, which works and is simple but is more costly (calculate width every frame). If you only edit small buffers it'd be another good-enough workaround until the feature is implemented. inputtext_multiline_calc_width.diff
|
Just a note to say I encountered this problem today, so I'll be happy to see the eventual rewrite to support this. I recognise it might be low on your priority list though. |
Based on ocornut#383. This is NOT good for performance but should work well enough for our case. We're not modifying giant files- our buffer is locked to 1024 characters and probably won't expand much further beyond that.
Based on ocornut#383. This is NOT good for performance but should work well enough for our case. We're not modifying giant files- our buffer is locked to 1024 characters and probably won't expand much further beyond that.
Was this ever solved @ocornut @unpacklo ? A fairly simple hack is to wrap the text input widget in a child frame and make a function to find the longest line in the buffer. Something like this:
Now you would Create a child frame of static size, with your edit inside it:
Obviously you can handle the frame colors many different ways, such as just using the container frame colors, and making the input text edit background opaque instead. What this will do is always resize the edit box's width to fit the longest line inside it. the container (ChildFrame) will always stay the same size, and will allow horizontal scrolling. For a rough idea on how to add auto text wrapping you could do something like this(This code is a rough example and may not function as-is):
The ImGui code is all the same, except you modify the Height value rather than the width. (unless you want the size completely static) Obviously the pitfall of the last method is, your data from the editbox will contain '\n' at WordWrap interval. There are several ways to solve this. Either by stripping '\n' every WordWrap interval, or having a vector to track the position(location) of each '\n so they can easily be removed without running a search loop. |
That’s prohibitively too slow. We ought to support eg 1 MB text buffer without flinching. I am waiting for a rewrite of InputText to solve this along with other issues. I know you mean well but your solutions are inadequate for the purpose of dear imgui. edit |
I was wondering if I was missing something obvious here for setting up a multiline text input with horizontal scrolling:
https://www.youtube.com/watch?v=Ncw78z9yTcA&feature=youtu.be
I know I can set the size manually in the code but that still doesn't help with the case where the text goes off the viewing area. It's rather laborious sometimes to edit some of these longer running lines.
We do have a workaround which is to make the overall window larger so the editing area becomes larger, but seeing as how we have some horizontal scrolling support, seems like that could be added to the multiline text?
The text was updated successfully, but these errors were encountered: