-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 area / Code editor #200
Comments
Features requests are totally fine here. Yes we should probably add multi-line text edition. Shouldn't be too hard seeing the underlying stb_textedit already supports it. It may be biased toward "short" text (a few hundred lines). Can't really tell when. But you could look into it if you need it soon. Syntax highlighting would be a separate thing. I don't have any immediate plan/idea to implement this. The approach that https://github.com/emoon/ProDBG is using is to use Scintilla which is a full featured source code edition component, and wire it to render within ImGui. #108 I think it's working now you you may be able to borrow code from there. Probably requires a bit of setup but then I assume you'd get a high quality multi-language component. |
I +1 this request for multiline editing via stb_textedit. Code/Syntax highlight is too application specific so I simple request for multiline editor. If bounties are accepted, I'd offer $35 for this request to be completed. Thank you for this great project! |
Hi Paul, It's on my list, I'll try to work on it when I'm done with the menus stuff, but I have so many things lined up at the moment it is a little overwhelming to handle every request. But I will try! You can probably bribe me with a Patreon subscription ($35 every month? :) |
Hello Omar, Understandable, have been watching the menu branch and see you are a busy guy! |
Thank you very much! :) What sort of text size are you aiming to edit? A few kilobytes and under a hundred lines? Or something larger? The current API takes a buffer size, so to handle large amount of text you would either need a big enough buffer or allocate a capacity enough to fit current text size + extra inputs every frame which needs to take account of the worse case, aka clipboard size. Otherwise it would make more sense if I added extra feature in the API or via callback to resize your buffer, but the first version will probably require you sizing the buffer. Again it depends how scalable you need the thing to be for big text. Above a few lines, it would also probably need to preserve scrolling and cursor position more persistently (currently we only preserve them for 1 text field), so that you don't lose scrolling when another field is edited. Do you need TAB ? Proper tabs requires a change in the text renderer and text size calculation which I have removed prior to v1.0 because it was making the rendering code more complicated and less performant. Text size calculation is among the bottleneck for very large UI so it needs to be kept optimal even if it takes having multiple code path with features enabled/disabled as needed. We're also lacking an horizontal scrollbar, shouldn't be a big problem. |
Very welcome! Sized buffer would be fine for first revision but a dynamic method would be desirable Tab would be a a desirable attribute as the formatting is a important aspect for assembly code. Thank you! |
Hope pings are not considered rude as I know your busy. Any ETA on this? Planning internally around this feature so a rough estimate would be appreciated |
Sorry! I'll give it an attempt in the upcoming days and see how it does (it might just be easy) On another note bgfx has a basic integration of scintilla using imgui that I could fix/cleanup and then provide as a standalone thing for using scintilla. |
Fantastic! No reason for sorry, Did not mean to rush. I did look at scintilla but the interface looked rather complex. I'd be over the moon for a clean standalone scintilla interface for ImGUI! |
One issue with Scintilla is that it's a bit "statefull" which goes against ImGui style a bit. If you want you can take a peak at how I solved it for ProDBG (uiFuncs here is a C wrapper for ImGui) PDSCInterface* sourceFuncs = uiFuncs->scInputText("test", 800, 700, 0, 0); Here I return an API to for the input that I later on can use to send command to Scintilla like this PDUI_SCSendCommand(sourceFuncs, SCI_GOTOLINE, (uintptr_t)line, 0); This code above is just a macro that looks like this #define PDUI_SCSendCommand(funcs, msg, p0, p1) funcs->sendCommand(funcs->privateData, msg, p0, p1) The code is used here https://github.com/emoon/ProDBG/blob/master/src/plugins/sourcecode/sourcecode_plugin.cpp#L85 Internally in https://github.com/emoon/ProDBG/blob/master/src/prodbg/ui/bgfx/imgui_extra.inl#L81 I will do caching of the Scintilla editor because it's heavy to create each frame. Hopefully my implementation can be used somewhat as a ref. |
Thank you emoon. Reviewing that information now. A simple multiline may be a better fit for my usage. |
@paultech The Scintilla version I use (for ProDBG) doesn't have any such requirements. Me and @gwihlidal implemented a backend that uses ImGui rendering functions directly. The base implementation is here https://github.com/emoon/ProDBG/blob/master/src/prodbg/ui/bgfx/sc_platform_bgfx.cpp Which still needs improvments but is somewhat working. |
For reference that's the bgfx commit (not viewable on github web) But yes there will be a simple multiple :) |
That is not needed for ImGui integration: I cleaned away quite a bit of code with the version I'm using. Look at this tree here https://github.com/emoon/ProDBG/tree/master/src/external/scintilla/src |
Been working on this now. Not sure when it'll be done, there's literally a hundred things to redo in the code but I'm on it. |
…tUnformatted() level for large chunks but this is also useful) (#200)
Not horizontally scrolling on char boundaries anymore
@paultech : If you checkout the multiline branch you can try a version 1
|
Bit messy & not happy with using ImVector<char>
I tested it on big text (100k+) and it seems to works but it is really slow at the moment. Lots of assumption in both stb_textedit and imgui side don't scale well with big text. Even a few hundred lines can have noticeable 1ms+ impact. I'll work on some optimisation. imgui side still does a lot of stupid things (~5 calc text size calculation per-frame when cursor is in a scrolled position due to various dependencies). |
Hi @ocornut - This is looking great on my end and all my InputText seem to work just fine. Thanks! |
…e, better clipping, much faster for large text (#200)
Went beyond the call of duty and spent some time optimising the code. Basically went to tried to minimize the number of passes touching each character by merging lots of stuff. My test case was pasting and text editing imgui.cpp (12600 lines, 540 KB) in a non-optimised build. The CPU cost grows with character count, line count, position of the cursor within the field (very top is cheaper than very bottom), amount and position selection. TL;DR; it is now optimised enough that the cost should be negligible for files of a few hundred lines. Some measurement on my laptop
Obviously editing a 12000+ lines file is not something that I'd expect anyone to do with ImGui, it's more of a extreme case. Rather than add more state to the widget for this sort of thing I'd expect people to use something like Scintilla. Feedback welcome! I hope to merge that in master soon |
Thank you very, very much! It looks awesome! It really is quite speedy, and I don't think thousands of lines would be that uncommon as even simple scripts could reach so many lines easily. I ran into some issues however: in the provided example, when a line is too long I cannot see a horizontal scrollbar. But I guess I just have to provide it myself, as it is the case with vertical scrollbar. Another issue is, I have a mouse which has a "free-running" scroll-wheel - I can spin the wheel quickly and it keeps on scrolling for a while by inertia. When the text input is at the very bottom and I keep scrolling down, the screen starts to flicker as it redraws the very last lines and probably the last frame before them. What Scintilla goes, I don't know about the one provided in bgfx, but I cannot use its original version as it scrolls the text line-by-line, i.e. not "smoothly" pixel-by-pixel, which I find very distracting, especially when using e.g. web browser next to it. Also, I know you said you have no immediate plan to implement it but maybe you can give us a hint on how to go about adding the syntax highlighting? In any case, thanks a lot once more, I believe this is a great addition to ImGui. Edit: I now see that the scroll-wheel thing affect any scrolling widget but maybe it's I'm trying this under Ubuntu in VirtualBox. |
Horizontal scrollbar So one possibility is to have it available but not by default and clearly comment that it has non-negligible cost. Another possibility is to come up with a "click and drag" scrollbar with no visualization of the limits but that would be inconsistent with the vertical scroll-bar. Another possibility would be to start carrying more state across frame for this sort of case. The problem is to handle CPU spikes. I could easily cache width for a given text blob, or in fact once edition is active ImGui is in control of the text box content so I could maintain it as edition happens. But I still need to do it without major spikes (would be bad to have a 5 ms spike then typing a character, which may not be easy to do without preprocessing/indexing of lines) and need to handle it for non-active edit box which is essentially taking the text data from the user so it could change every frame. We could hide the horizontal scrollbar prior to activating the widget and that would simplify the problem a little. Of course this all stem from the fact that little state is kept across frame and it could be reworked, but I don't see myself heading into writing a proper text editor which is a task in itself. Mouse wheel/scrolling Syntax highlighting todo
|
Mouse wheel issue is solved. I had noticed this bug recently but as my mouse wheel my failing I attributed it to crazy mouse. When mapping the wheel to keyboard it became super clear there was a bug :) I have now merged everything back in master. |
The mouse wheel issues is indeed gone. Thank you! |
Closing this. Other things like horizontal scrollbar, making it easier to grow the buffer without allocating for worse case etc. will be handled later. I added notes in the todo list. |
So then no news about this ? |
hello, @ocornut, can you show us the code you use scintilla from bgfx ? i have many porblem with my Eu keyboard and the use of brace. left brace is alt gr and 4, and right brace is alt gr and +. after done the right brace, the control not receive any others input, and there is some delay to have the left or right brace to show in the editor. its weird thanks in advance :) |
I don't use scintilla or bgfx. @emoon might know. |
OK but you have post an example from bgfx on top (Jun 2015). I speak about that |
You can link to post by pressing the date. So I assume you mean this? #200 (comment) |
yep :) |
Could I ask you quickly, how did you get those line numbers? :3 |
@egordorichev If you are interested in a fully featured text editor, try https://github.com/BalazsJako/ImGuiColorTextEdit |
Haha, thanks 👍 |
And even better with Scintilla |
…gle from counting in the worst case vertices reservation. (fix code added in #200!)
Hello!
I apologize in advance, as this is not an issue but I could not find any user forums.
Do you have any plans for adding multi-line editing widget, aka text area? I was just wondering, as there are now a single line edit and the ability to display lots of "immutable" lines of text.
If so, would it be possible to use it as a simple syntax-highlighting code editor? (just colored tokens and perhaps regular/bold/italic styles)
In any case, thank you for the hard work you are putting into the project!
The text was updated successfully, but these errors were encountered: