GTK TextView - creating a static display format

837 Views Asked by At

I am trying to simulate a piece of hardware, and this hardware has a static ribbon display.

to do this, I'd like to use a TextView. My display has 10 rows, with 25 columns. So I figured that a TextView should be easy enough.

basically, I would like to be able to say "insert/replace string S at row X, starting at column Y". i may need to only update a specific row, or even a single column within a row.

I have not been successful at getting this to work though. the best I have been able to do is to fill the TextView with 10 lines of 25 spaces when i create it, and then use the get_iter_at_line_offset to get the iterator of a line, and then push the new text onto that line.

but this will start appending text to the line, rather than replacing the existing one.

I need both row and column control (i.e. need to be able to set text at a specific (X,Y) coordinate).

I'm assuming this is somehow possible using marks.

Can anyone give me a quick example of how i can do this? Unfortunately, there isn't a whole lot of documentation on this sort of thing.

2

There are 2 best solutions below

3
On

You'll have to get an iter at a specific line, row X, and then use the iterator's forward_chars() method to move forward Y characters. Then delete the number of characters you are replacing, and finally insert the text you want to insert. You can do it all with iterators, I think - iterators are invalidated when you change the buffer, but when you delete text, one of your iterators is revalidated to point to the place where the text was.

1
On

If you're targetting GTK+ 3.x, you should really look into using Cairo. Since you don't actually need a text buffer, it seems like overkill and a bit of a mis-alignment to use the GtkTextView.

Look at the very basic introduction on how to draw with Cairo in GTK+. Then look at the text-rendering Cairo APIs, that should be enough to get you started.