Letting syntax highlighting change background colours or underline text #7843
SeaLiteral
started this conversation in
GUI
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL/DR: Syntax highlighting can currently only change font colours, but when you're trying to show several types of information about each word in the code it's hard to present them together unless you can adjust other variables such as the background colour.
Context
For a game I made back in April, I made my own simple scripting language. This language lets me easily play animations and display text. I know there's plenty of such languages out there, but what matters about this one is probably the fact that strings could contain BBCode. So I have the custom scripting language, and the BBCode strings inside it. And I made a script for a
SyntaxHighlighter
to highlight those two languages together. I've considered adding spellchecking too, but don't have a working implementation of that yet.Problem
Syntax highlighting in Godot works by changing the colour of the font, and there's only so many colours you can use before they either start looking too similar to each other or too similar to the background.
Let's say I use some colours for the syntax of both the DSL and the BBCode, but some of the BBCode opens a tag without closing it or vice versa. Now there's a syntax error in the BBCode, and I'd like to be able to show where it is using a colour that I only use for syntax errors. Now throw in spellchecking and that's a different type of error I might need to be able to show, which I probably shouldn't use the same colour for, but I need to use something just as prominent and different enough from the syntax error colour that users can see it.
Proposed solution
Allowing
SyntaxHighlighter
objects to change the background colours behind individual characters in a similar way to how they change the foreground colour.Example usage code:
You probably could just call it
background
instead ofbackground-color
, but for this example I decided to go with what I think CSS uses.Additional suggestion
Underlining text doesn't change its width, so that would be another "easy to add" thing. I've seen underlining used in syntax highlighting outside Godot.
Workarounds?
Solvable via plugins? Depends what you mean by solvable:
TextEdit
orCodeEdit
node, trying hard to guess where exactly they should be, but I don't recommend it (I have tried something like that, and it would have broken as soon as scrollbars got involved, it's at least as ugly as you think. I'm attaching a screenshot of it since it kinda shows what I imagine the feature looking like).* There's nothing wrong with occasionally reimplementing the wheel. But doing that for a simple wheel should probably be more common than doing it for a complex wheel. I'm fine with bypassing
TranslationServer
when I want players to select the language of speech audio separately from that of text, but that's doable in GDScript, it doesn't require me to use C++.Interactions with existing functionality
I'm aware that text selection and search can colour the background behind individual characters, but those have specific purposes and I don't see them working directly for this. That being said, the fact that there is code that can change the background behind characters probably means that code could be modified to also support working for syntax highlighting.
But what would that mean for those features? I guess because selection and search need to change the background colour, combining that with another thing changing it too could make things more complicated. Perhaps instead of setting a colour and a background colour the
SyntaxHighighter
could set a colour, a background colour and a highlight colour. Or perhaps the highlight colour could just temporarily override the one set by theSyntaxHighlighter
, which is probably the easiest way to implement it.Irrelevant section
I initially didn't see the GUI category, perhaps expecting it to just be called UI or something like that, but removing sections of the proposal seemed odd, so here is what I initially wrote about the categories:
I had to choose between tagging this discussion as "2D" or "editor". And this is probably most useful for plugin developers, but I imagine programming games could use it too (I mean, those programming programming games could use it). And typing game developers would also be getting a new way to instantly show to the player if they were making a typo, not really necessary when they could just use the front colour, but still something some users could prefer over using the font colour.[Edit: I'd accidentally inserted the image in the middle of a word, sorry about that.]
[Edit 2: I had initially tagged this as 2D because I didn't see the option to tag it as GUI . I've changed that too now.]
[Edit 3: fixed a typo and added the "Interactions with existing functionality" section
Beta Was this translation helpful? Give feedback.
All reactions