From c3cde61e9879825c1547e366e2b9becedc1179e7 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sun, 9 Jun 2002 18:28:49 +0000 Subject: Add documentation for using styles in text editor. Add placeholder for style attributes - hidden + underlined - for future use. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2301 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- documentation/editor.html | 286 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 284 insertions(+), 2 deletions(-) (limited to 'documentation/editor.html') diff --git a/documentation/editor.html b/documentation/editor.html index 3fb5c43b0..56de1ad71 100644 --- a/documentation/editor.html +++ b/documentation/editor.html @@ -105,7 +105,7 @@ Fl_Menu_Item menuitems[] = { Fl_Menu_Bar widget and assign the menus to it with:

@@ -118,7 +118,7 @@ m->copy(menuitems); widget to edit the text: @@ -598,5 +598,287 @@ The final editor window should look like the image in Figure 4-2.

The completed editor window.
Figure 4-2: The completed editor window

+

Advanced Features

+ +

Now that we've implemented the basic functionality, it is +time to show off some of the advanced features of the +Fl_Text_Editor widget. + +

Syntax Highlighting

+ +

The Fl_Text_Editor widget supports highlighting +of text with different fonts, colors, and sizes. The +implementation is based on the excellent NEdit text editor core, which +uses a parallel "style" buffer which tracks the font, color, and +size of the text that is drawn. + +

Styles are defined using the +Fl_Text_Display::Style_Table_Entry structure +defined in <FL/Fl_Text_Display.H>: + +

+ +

The color member sets the color for the text, +the font member sets the FLTK font index to use, +and the size member sets the pixel size of the +text. The attr member is currently not used. + +

For our text editor we'll define 7 styles for plain code, +comments, keywords, and preprocessor directives: + +

+ +

You'll notice that the comments show a letter next to each +style - each style in the style buffer is referenced using a +character starting with the letter 'A'. + +

You call the highlight_data() method to associate the +style data and buffer with the text editor widget: + +

+ +

Finally, you need to add a callback to the main text buffer so +that changes to the text buffer are mirrored in the style buffer: + +

+ +

The style_update() function, like the change_cb() +function described earlier, is called whenever text is added or removed from +the text buffer. It mirrors the changes in the style buffer and then updates +the style data as necessary: + +

+ +

The style_parse() function scans a copy of the +text in the buffer and generates the necessary style characters +for display. It assumes that parsing begins at the start of a line: + +

+ + -- cgit v1.2.3