Is it possible to make a syntax highlighted text editor ? (custom ui widget ?)

  1. What do you want to achieve? Keep it simple and clear!

I would like to know if it’s possible to write a custom widget that I can include in my game where people can write syntax highlighted Lua code (or any other custom text format that I write the highlighter for) ?

I would like to make something similar to this (the editor in the screenshot was made with c++ and raylib)
(the person manually programmed everything from letter typing to syntax highlighting etc)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I didn’t try any solutions yet because I have no ideas on how to make my own programmable ui widget that can be added into the explorer like TextBox/ImageLabel etc.

I also though about maybe instead rendering each character separately and then regrouping them and colorizing it ? But I have no ideas

I’m not asking a completed code , but I’d like if possible if someone can give me some head about how I could do this , as I think that there was a Lua learning game that had that feature iirc.

Thanks in advance to anyone who takes some time to help me

1 Like

You might want to use the RichText
Or take a look at this post, which already does what you’re trying to do.

1 Like

this is possible but there are some side effects such as lag and double text. You’ll need one textbox and one textlabel, the textlabel needs richtext to be enabled. Now just put all the text that is being typed in the textbox into the textlabel. Use regex to find certain words or combination of characters you want to highlight, then use richtext to change the color of the words in the textlabel. Don’t forget to sanitize the input text to avoid issue. The reason you need a textlabel is because richtext will not work in a textbox while the user is typing. I recommend disabling the highlighting if the text gets too long.

1 Like

Thanks , i think i missed that post

Thanks , i dont think performance is going to be a very big problem. I will to do it with a surface gui (to simulate a screen computer)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.