gtkgtktextview

GTK: How to display a fixed-size page of text


I'm just now learning GTK programming, and I can't figure out how to display a "page" of text, M rows of N columns, each position containing a character with a given foreground and background. The size of bounding rectangle will be fixed, and I will update the contents of the "page" (or grid) from time to time. How can I intelligently do this?

I've read about GtkLabel, but that seems wrong. GtkTextView looked like it might work, but my experiments have been awkward. GtkTextView seems to want a stream of text to display, instead of displaying a grid, and updating individual grid positions.

Any help with this would be greatly appreciated.


Solution

  • There is no good pre-made solution for this in GTK, but I have made it work acceptably with a GtkTextView, of which the contents are M strings of N characters each, joined with a \n. You can update an individual grid position by getting a GtkTextIter at the correct position in the string (y * (N + 1) + x) and replacing the character there.

    Another approach would be to write a custom widget where you render the grid text yourself in the draw signal handler.