Color in Fl_Text_Display

36 views
Skip to first unread message

supsm17

unread,
Nov 13, 2021, 1:07:42 PM11/13/21
to fltk.general
Is there some way to change the color of certain lines in Fl_Text_Display? For example, if I want a certain line to be red and another line to be blue, how would I do that? On the docs I saw there was linenumber_fgcolor, but the docs are rather unclear how to use it. How do I select which lines will be affected by the color change?

Also, is there a better way to add text to the display? Currently I just add to a string, then call buffer() every time I update it. I was wondering if there was some better way to print text to the display (I won't need to delete anything, only add).

Thanks for any help!

lifeatt...@gmail.com

unread,
Nov 14, 2021, 4:54:14 PM11/14/21
to fltk.general
>Is there some way to change the color of certain lines in Fl_Text_Display?

Erco has a sample in his cheatsheet which shows exactly what you're trying to accomplish: each line is assigned a specific color.

"The way" to control color and formatting in a Fl_Text_Display is via styles and the style buffer.

You set up a "style table" via an array of Style_Table_Entry, pass that to your Fl_Text_Display instance using the highlight_data() function. You add your text to the textbuffer, and for each character you want to have a given style, you indicate that via the stylebuffer.

>  I just add to a string, then call buffer() every time I update it.

Use the Fl_Text_Buffer append() function to add text to the text buffer:

Fl_Text_Buffer *buf = my_text_display->buffer();
buf->append("my new text");
 

Ian MacArthur

unread,
Nov 15, 2021, 4:36:51 AM11/15/21
to fltk.general
On Saturday, 13 November 2021 at 18:07:42 UTC sups... wrote:
Is there some way to change the color of certain lines in Fl_Text_Display? For example, if I want a certain line to be red and another line to be blue, how would I do that? On the docs I saw there was linenumber_fgcolor, but the docs are rather unclear how to use it. How do I select which lines will be affected by the color change?

Also, is there a better way to add text to the display? Currently I just add to a string, then call buffer() every time I update it. I was wondering if there was some better way to print text to the display (I won't need to delete anything, only add).

An Fl_Browser might be a better option than a Fl_Text_* for this purpose, if it is just adding lines of text.
Also simpler to colourize too, in that case.
It is not an "editor" but it sounds like what you want is just a text list of sorts, so Fl_Browser is possibly a "btter fit" for that case...?

 

Matthias Melcher

unread,
Nov 18, 2021, 7:56:38 AM11/18/21
to fltk.general
If you use 1.4.0, also check out Fl_Simple_Terminal. It supports color by interpreting ANSI code in text. It's for displaying tet, not for editing.

supsm17

unread,
Nov 19, 2021, 2:55:33 AM11/19/21
to fltk.general
Thank you, I am actually using 1.3.6, but Fl_Browser works well and the examples were also very helpful.

Ian MacArthur

unread,
Nov 19, 2021, 7:29:24 AM11/19/21
to fltk.general
On Friday, 19 November 2021 at 07:55:33 UTC sups... wrote:
Thank you, I am actually using 1.3.6, but Fl_Browser works well and the examples were also very helpful.

OK, that's good.
How big does your list get, how many lines of text? 
Internally, Fl_Browser uses a system of linked lists to manage the line entries, so if you have a very long file, with "many" lines, it may become unwieldy in use.

Though, with modern CPU's, I'm not sure what actually constitutes "many lines" these days - I'd assume many thousands of lines, but don't actually know.
In practice, where I have done this, I've tended to hold a few thousand lines in the Fl_browser and beyond that, as more lines are added, pop lines off the top of the browser into a log file (then I can read them back later if I really need to; in practice that doesn't seem to happen as much as I imagined it might!)


supsm17

unread,
Nov 20, 2021, 11:33:47 AM11/20/21
to fltk.general
It should probably be "not a lot." A few hundred lines would be a LOT for my program, so that probably shouldn't be a problem)

imm

unread,
Nov 20, 2021, 11:37:53 AM11/20/21
to General FLTK
On Sat, 20 Nov 2021, 16:33 supsm17 wrote:
It should probably be "not a lot." A few hundred lines would be a LOT for my program, so that probably shouldn't be a problem)

That should be no problem - a few hundred lines is fine.

--
Ian
From my Fairphone FP3

Reply all
Reply to author
Forward
0 new messages