Reputation: 2761
I've a feeling I might be missing something with Pango. Almost everything in the API seems geared towards displaying static text with the exception of two functions to draw/move a cursor at a particular position which suggests there might be a built in way to achieve editing text.
For example, to mark a block of text with the mouse (ie change the background color between two points), I can either regenerate the text with changed tags for every single mouse move or draw the rectangles in Cairo and then use Pango to draw the text with a transparent background over the top. Is there a way of applying attributes to a range without regenerating or redrawing the entire screen?
Similarly, if I have Pango draw the cursor and handle key press events myself, is there an alternative to redrawing the entire screen?
GtkTextBuffer is not an option - I don't have all the text at any time and it's far more efficient to calculate what needs to be displayed on the fly from a compact binary format and using a constantly changing set of filters. As well as being bloated, redundant and inelegant, it's also fantastically slow.
Upvotes: 4
Views: 1558
Reputation: 2761
In the absence of any but the sparsest of documentation, I examined the source of GtkTextView (https://git.gnome.org/browse/gtk+/tree/gtk/gtktextview.c) to see how pango layouts are used in GTK itself.
It would appear that rendering the window every time a key is pressed or the mouse changes the marked area is the least of its problems and the optimizations (while less flexible than GTK's) go beyond what they use.
Text marking, for example, involves inserting tags into the rendering tree, recalculating the tree and then double-buffering the output - something which ought to be massive overkill and reserved for 3d rendering. Scrolling is sped up by grabbing an image of the output and then rendering sub-sections of the text.
I suppose the thorough solution would be to rework GtkTextBuffer/GtkTextView to conform more closely to the MVC model and not demand the full text up-front but for now I suppose I'll stick to my minor optimization of the user-drawn widget.
Upvotes: 3