balazsjako / imguicolortextedit Goto Github PK
View Code? Open in Web Editor NEWColorizing text editor for ImGui
License: MIT License
Colorizing text editor for ImGui
License: MIT License
How to change the size of the textbox
SetSelection(Coordinates(0, 0), Coordinates((int)mLines.size(), 0));
Would resolve to Coordinates(0,0), Coordinates(1,0), which is then sanitised by SetSelection to Coordinates(0,0),Coordinates(0,0), resulting in no selection as the end coord is beyond the end of the document.
I've fixed this locally by changing it to select the last character of the last line instead of the line beyond the end of the document:
void TextEditor::SelectAll()
{
if(!mLines.empty())
SetSelection(Coordinates(0, 0), Coordinates((int)mLines.size()-1, mLines.back().size()));
}
Return key does not work for me ...
I'm working on a tool, if you're interested: https://github.com/berdal84/Nodable/
I would like to be able to use your imGuiColorTextEdit with custom width/height fonts.
I'll be happy to contribute by adding custom font handling, are you open to it ? If yes, any suggestions to do it before I start ?
A capture of your ImGuiColorTextEdit integrated into my app :
https://github.com/berdal84/Nodable/blob/texteditor/screenshots/2018_06_03_Testing_ImGuiColorTextEdit.png
So in my setup whenever I write _
(Shift + -
) I get everything from my clipboard pasted in addition to the underscore character written. This is because of this code. What is the purpose behind pasting with _
?
The ASCII code of -
is 45 - is it supposed to be something else?
I also tested this with the demo project and it doesn't get triggered there - any idea why?
I'm using this code from the examples of imgui for opengl2 and glfw
Colorizer uses std::regex, but it is too slow for that amount of work. Not to mention it is not optimized to scan multiple expressions at once. It is necessary to replace it with a proper lexical scanner (like RE/Flex).
When I click on a line contening tabulations, the cursor is placed at a wrong position.
For example, calling only these two functions with the default font of ImGui:
editor.SetText(" abcdefghijklmnopqrstuvwxyz\n\t\tabcdefghijklmnopqrstuvwxyz\n");
editor.Render("editor", ImGui::GetContentRegionAvail(), false);
If I click after the text on the first line the cursor is put at the right position (the end of the line), but if I click after the end of the second line the cursor is placed at a wrong position (as in the picture).
Its cool that we can go through words with Ctrl+ Left/Right and etc. but perhaps more standard controls like Ctrl+A for selecting everything (and others I can't think of right now) might be a big plus :)
Removing a line using delete removes the marker on that line, as expected.
Removing a line using backspace however, doesn't. Using backspace to delete the line below the marker does remove it though.
A bit of an inconsistency in their behavior.
I will try to make a fix myself. But that requires rewriting either Delete() or Backspace(), while maintaining the other existing behavior.
Longer the line more cursor gets off to right from place it is writing. I tried multiple fonts along with monospaced one but nothing helped. Maybe some change in recent ImGui? I'am using release of 1.68 made recently. Here is the issue visible:
Cursor is there actually at the end of the line (when i press delete last character on line dissapears)
It should return the std::string inside the object instead of a copy. The string might destroyed when the function exits.
Most languages have completely different tokens for single-line comments and block comments (eg //
and /* */
in C), but in Lua they start the same: --
and --[[
.
The comment highlighting logic needs fixing so that it prioritises block comments first.
I've fixed this locally by swapping the logic over:
if(currentIndex + startStr.size() <= line.size() &&
equals(startStr.begin(), startStr.end(), from, from + startStr.size(), pred))
{
commentStartLine = currentLine;
commentStartIndex = currentIndex;
}
else if (singleStartStr.size() > 0 &&
currentIndex + singleStartStr.size() <= line.size() &&
equals(singleStartStr.begin(), singleStartStr.end(), from, from + singleStartStr.size(), pred))
{
withinSingleLineComment = true;
}
If I set an empty string :
editor.SetString("");
And then I click into the Text Editor area I got an assert (aLine is wrong).
Also it would be grand if the double-click glob chars could be changed, I'm thinking about ":" specifically. In passwd and shadow files It's great to stop at : but for "scp host:file ." it's unfortunate.
There are two issues introduced in 8fbb932:
langDef.mSingleLineComment = "--";
was removed from the Lua language definition.ColorizeInternal()
will set withinSingleLineComment
to true
if mSingleLineComment
is the empty string, so a language that does not have comments (e.g. JSON) will be fully colorised as commentsg++ -I../cimgui/imgui -I../../include -c -o TextEditor.o TextEditor.cpp
In file included from TextEditor.cpp:7:0:
TextEditor.h:125:30: warning: ‘TextEditor::Glyph::mColorIndex’ is too small to hold all values of ‘enum class TextEditor::PaletteIndex’
PaletteIndex mColorIndex : 7;
This is on i686, 32bit linux.
ImGuiColorTextEdit/TextEditor.cpp
Line 534 in b4a074b
I'm basically using similar logic, but I'm not sure whether I need the resize there at the end.
Any advice on why you have it there?
Awesome work!
PTAL at https://github.com/ocornut/imgui_club/tree/master/imgui_freetype
It has hinting support so it will result in better text render quality.
(you'll find screenshots here: ocornut/imgui#618)
We've noticed that there's a lag colorizing new text - as you're typing it renders in the default color for a frame before the syntax highlighting kicks in.
It appears this is happening because when ColorizeInternal
goes down the multi-line comment path, it return
s rather than continuing to do the main colorization pass. This results in a two-stage process where commenting is checked on frame 1, and then syntax highlighting applies on frame 2.
Is there a reason for it being this way? I can see any bad effects after removing the return
locally. According to blame, it's always been there.
ImGuiColorTextEdit/TextEditor.cpp
Line 1951 in 2aa980e
When a code editor widget is focused and has a cursor inside of it - querying ImGui::GetIO().WantCaptureKeyboard
or ImGui::GetIO().WantTextInput
(or maybe both) should return true
instead of false
. Also not sure about WantCaptureMouse
and the rest such flags.
Great project btw! Thanks for making it public!
The following warning is produced from the header with gcc 7:
TextEditor.h:125:30: warning: 'TextEditor::Glyph::mColorIndex' is too small to hold all values of 'enum class TextEditor::PaletteIndex'
PaletteIndex mColorIndex : 7;
on the default warning level - and it cannot be easily silenced (without disabling all warnings with -w
)
Should reflect the character underneath.
You can see some examples here http://lua-users.org/wiki/StringsTutorial
The way you currently check for multiline strings and comments won't allow for the nesting capability that lua has.
Minor trick/suggestion: because png adds up in the git repo size.
The wiki that github offers is a separate git repo (ImGuiColorTextEdit.wiki.git
instead of ImGuiColorTextEdit.git
)
What I do for imgui is I upload any images to the wiki repo and link to them from the readme instead, so the main repository doesn't grow with extra data.
Inside GetDarkPalette(), GetLightPalette() and GetRetroBluePalette()
error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
I've fixed this locally by double-bracing the initialisation lists so they look like this:
static Palette p = {{
0xffffffff, // None
0xffd69c56, // Keyword
0xff00ff00, // Number
0xff7070e0, // String
0xff70a0e0, // Char literal
0xffffffff, // Punctuation
0xff409090, // Preprocessor
0xffaaaaaa, // Identifier
0xff9bc64d, // Known identifier
0xffc040a0, // Preproc identifier
0xff206020, // Comment (single line)
0xff406020, // Comment (multi line)
0xff101010, // Background
0xffe0e0e0, // Cursor
0x80a06020, // Selection
0x800020ff, // ErrorMarker
0x40f08000, // Breakpoint
0xff707000, // Line number
0x40000000, // Current line fill
0x40808080, // Current line fill (inactive)
0x40a0a0a0, // Current line edge
}};
It would be nice if the rendered text could wrap around (optionally with some flag) so we don't have to scroll horizontally when the lines are too long
I understand that this project doesn't aim to be a complete editor - I'm just suggesting... :D
how to add the text edditor to imgui
"foo\"bar"
, the \
should be highlighted... IMHO.
Hi,
The following code has incorrect syntax highlighting. One can verify this by copy-pasting it into the editor.
if (hasValue == false && nodeId != kGraphNodeIdInvalid)
{
//logDebug("reset realTimeSocketCapture");
//*this = GraphEdit_Visualizer();
}
//
const bool hasChannels = channelData.hasChannels();
if (hasChannels)
{
I investigated why, and it's caused by the multi-line comment highlighter running before single line comments are detected. It causes the '/*' in '//*this' above to be interpreted as the start of a multi-line comment. While it should be ignored as it's part of a single line comment. A possible solution would be to detect single line comments together with multi-line ones.
Perhaps eventually to make (multi-line) comments work well across different languages we'll need a separate comment highlighter for each language.
with GCC the <cmath>
header needs to be included for floor()
in the .cpp - this PR fixes that.
Currently I have a workaround in a demo project (as can be seen here) which I would like to remove so that the code is simpler - people will be looking at it when I make an official release of that example project.
Hi, I hope you can read that :). I encountered a little problem with fonts, it looks like you use the first one in the array of fonts in ImGui, and if you are using different fonts that doesn't seem to work...
void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)
{
mWithinRender = true;
ImGuiIO& io = ImGui::GetIO();
auto xadv = (io.Fonts->Fonts[0]->IndexAdvanceX['X']);
mCharAdvance = ImVec2(xadv, io.Fonts->Fonts[0]->FontSize + mLineSpacing);
My solution was passing the used font as an argument in the "Render" function, although I think that it'd be better to acces the currently used font from the ImGui io.
void TextEditor::Render(const char* aTitle,ImFont* font, const ImVec2& aSize, bool aBorder)
{
mWithinRender = true;
ImGuiIO& io = ImGui::GetIO();
auto xadv = (font->IndexAdvanceX['X']);
mCharAdvance = ImVec2(xadv, font->FontSize + mLineSpacing);
Having said that, your API i great, the fact that you can make custom colors for different languages is really good. I'll make one for "wren", and pass it to you in case you want to merge it with the source code.
There are a few [ \t]
that should be [ \\t]
.
I can't wait to combine this with http://duktape.org and truly empower my users.
Hi! currently the source code requires c++14.
Only 2 lines of code have to be changed to enable c++11 builds - where std::equals()
is used.
Including this lib in my project causes the time from starting the executable to the time the window is displayed to be increased by several seconds.
I would appreciate any input about this issue, such as why it might be so long, and what if anything I might do about it.
I really like this lib otherwise, but more than tripling my startup time is hard to accept.
FWIW I'm using this with ImGui 1.69, sdl2 and gl3w. I'm using the default impl_sdl and impl_opengl3.
in:
void TextEditor::HandleKeyboardInputs()
this row:
else if (!IsReadOnly() && !ctrl && !alt)
makes the texteditor unable to enter any characters requiring AltGr key to be pressed (coded as Ctrl+Alt in European Windows). (for instance { } [ ] etc)
Quick fix for those affected is to remove the !ctrl and !alt check.
This issue doesn't exist within ImGui's inputtext itself.
Do you reckon there's a better fix for this issue?
Would be nice if there was an easy way to make the editor read only. Selections and such would still be possible, but text input, deletions etc would be locked.
It may be possible now. Maybe I just missed it. If not, it would be nice.
My project builds and runs, but the enter key does not feed a line and return the carrage.
I've installed the callbacks and passed on keypresses.
This is a nice addon. I got a question when using it. Should io.FontGlobalScale
be counted here:
ImGuiColorTextEdit/TextEditor.cpp
Line 379 in b23fb4a
Thanks.
Eg. BASIC, etc.
What can I do if I need this Text Editor in c#?
The readme says no UTF8 support... how far would that be on the horizon? Would it involve a lot of changes?
Probably needs a languagehelper-like class.
It would be useful to be able to receive information about when the text has been changed (eg to trigger a Lua script load to check for errors in realtime).
Naively, this could be done by the user comparing GetText() with the previous value, but it's a bit of a sledgehammer approach.
Better would be implemented with a "text changed" member bool that's set inside any text manipulation function that adjusts the undo index. The flag would be returned and cleared at the end of Render().
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.