Wednesday, March 17, 2010

Some more obscure Text widget commands

This morning I added a few extra commands to the text widget which, are somewhat odd, I admit, but does provide further widget introspection for those who might need it.

text-id getCoords start
text-id getCoords cursor
text-id getCoords {1 0}
text-id getIndex {15 15}
text-id getRect
These commands are derived from the GtkTextView widget rather than GtkTextBuffer and GtkTextIter and so are more focussed on how text is rendered to the display rather than the text content itself. Internally, the Gtk+ keeps track of what is kept in the current text display buffer. Looking at the above examples one can see that getCoord takes as its argument either a text index, ie line 1, row 1 (of the text buffer) or one of several positioning keywords. What is returned is the window x,y pixel coordinates for that position. The opposite effect is produced by getIndex, here 15 15 is the pixel x,y coords whose content we want to determine in terms of its corresponding position in the textBuffer. Finally, getRect returns the window position and size of the rendered region of the text. If a specified position is not in the textView, then a negative value will be returned.

I’ve always found the idea of matched data and display buffers (i.e. a viewport) to be a little hard to work with. When I have the time I’ll create an illustrative diagram.


No comments: