-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Inline colors in TextEdit #14731
Inline colors in TextEdit #14731
Conversation
Nice feature :) |
Nice! Great idea. |
I agree with @Hinsbart |
I'm not qualified to review the code, but a couple questions come to mind. Does this have any implication for code that cares about a line's length? I'm thinking of the recent patches for code indentation behavior that impacted the selection area. This updates ClassDB entries, specifically moves _color_changed from ScriptTextEditor to TextEdit. Is this then considered part of the public API? Should that be documented? Not familiar with community guidelines on things that start with _; _color_changed doesn't appear to be documented now, so it's at least status quo. :) |
It's indeed an API change so it's Godot 3.1. The reason for the signal move is that There should be no impact on selection code or the like as That's also the reason I believe this thing belongs in |
This is fantastic!! Really hope to see it in godot master 👍 |
@poke1024 I definitely didn't mean to challenge this against the freeze. I don't see why this wouldn't be viable for 3.0 yet. Not that I have any say. Thanks! :) |
@brainsick No problem, I'm actually not that familiar with Godot API change rules, but AFAIK you could grab that signal from gdscript so it's probably part of the API. |
scene/gui/text_edit.cpp
Outdated
@@ -30,6 +30,7 @@ | |||
#include "text_edit.h" | |||
|
|||
#include "message_queue.h" | |||
#include "modules/gdscript/gdscript_tokenizer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GDScript is an optional module, we can't have a dependency on it in a core Control.
So this code should be moved somehow to the ScriptEditor, and guarded by #ifdef GDSCRIPT_ENABLED
.
a2b8357
to
9655abc
Compare
@akien-mga All gdscript parsing and the color picker are now moved (back) to the ScriptEditor, I did a number of bug fixes, cleanups, and generalizations along the way. This should make it relatively easy to embed other inline content in the future if needed. As a simple test, I've added a triangular inline error indicator that shows the column when an error comes up. Just an experiment along the way. |
Whats the general consensus with this kind of inheritance / OOP should it use a new node type / signals instead? |
Currently
|
9655abc
to
ee10412
Compare
Thanks a lot for your contribution! Moving this PR to the 3.1 milestone, to be reviewed once the release freeze is lifted. It could eventually be cherry-picked for a future 3.0.1 maintenance release if it doesn't change the user-facing APIs and doesn't compromise the engine's stability. |
This would close #4882. |
84d49b9
to
49ead84
Compare
Rebased (which I don't see myself doing again) and cleaned up. The implementation is basically the same as before, the new abstractions for the syntax coloring are too high level to make use fo them for rendering the additional inline elements. There are still problems when wrapping is enabled (basically not yet implemented as this was not there before). |
Tried this out locally, seems good for the most part. It failed when the Colour is defined incorrectly:
or when its defined over multiples lines e.g.
In the first case, as its not valid code, will be erroring out at the tokenizer. It might be worth hiding the inline in these cases, rather then bothering the user with something they cannot interact with / displayed incorrectly. As far as code goes, so long as the multi-inheritance is okay, I would move the tokenizer part further down something like: As a side thought, it might be worth looking at caching these in a similar way to |
This is valid code, I don't know why this would give any error. |
My bad, it doesn't error. As there are no arguments, it can't find the colour values so it doesn't display correctly / set it as editable. |
This branch has conflicts and some concerns of places where syntax wont work. Any progress on this so far? |
I'll take a look at this this weekend. |
8e32016
to
c3ce0c0
Compare
- Renamed "inline" to "annotation" - Don't display partially parsable Colors - Fix annotations with line wrapping - Moved tokenizing to GDScriptLanguage - Caching annotation vectors in TextEdit
c3ce0c0
to
d41fe42
Compare
Changes:
Also:
Apart from the color pick annotation, this currently also includes the red triangle error marker for the current error position; I personally find this useful, but it's not strictly part of this PR. Multi-line color-definitions are ignored. I didn't squash the commits yet, to make the changes more trackable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -35,6 +35,18 @@ | |||
#include "editor/script_editor_debugger.h" | |||
#include "os/keyboard.h" | |||
|
|||
#ifdef GDSCRIPT_ENABLED | |||
#include "modules/gdscript/gdscript_tokenizer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is no longer needed.
code_editor->get_text_edit()->set_line(c.line, line.substr(0, c.begin) + new_args + line.substr(c.end + 1, line.length())); | ||
code_editor->get_text_edit()->update(); | ||
edited_inline_color.end = c.begin + new_args.length(); | ||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to keep this.
@@ -382,20 +387,19 @@ class TextEdit : public Control { | |||
void _scroll_lines_up(); | |||
void _scroll_lines_down(); | |||
|
|||
void _color_changed(const Color &p_color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not implemented anywhere?
@@ -31,6 +31,7 @@ | |||
#ifndef TEXT_EDIT_H | |||
#define TEXT_EDIT_H | |||
|
|||
#include "scene/gui/color_picker.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be imported in ScriptTextEditor
Moving to 3.2 milestone as we're reaching beta stage for 3.1, and there are still changes needed in this PR. |
@poke1024 Rebase? |
This needs to be rebased indeed to be mergeable, but we haven't reached a clear consensus about the implementation. The feature looks awesome, but I have some concerns over adding annotations to I mentioned in other issues and on IRC that I find If we decide to do this, I would then hold off on this PR until such refactoring has been done, and then the PR could be redone to implement the feature via |
As mentioned in #14731 (comment), a correct implementation for this feature should likely wait for #31739 to be implemented. I will close this for now as it's not going to be merged as is. This should likely be rediscussed in a proposal in the https://github.com/godotengine/godot-proposals/ repository, to see if/how we want to support this feature for the script editor (and shader editor?) while keeping the underlying controls manageable. |
Prologue:
The current master has a cool function to open a color picker in the code editor using the context menu and
Pick Color
, but it's well hidden and I wasn't aware of it until I found it in the code:This PR removes this great but hidden context menu
Pick Color
in favor of inline colors, i.e. colored circles in front ofColor
(you can click on them to open the color picker):Full demo: https://www.dropbox.com/s/fdzqwnt6sm77w3u/demo-inline-colors.mp4?dl=0
I'm currently using unicode
0x25CF
to draw the color circle, I'm not sure if that's safe on all versions of Freetype/Linux (plus sides: it adapts to all font sizes and is much faster thandraw_circle
).