2

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.

gpoo
  • 8,408
  • 3
  • 38
  • 53
jasonmclose
  • 1,667
  • 4
  • 22
  • 38
  • I don't know what a static ribbon display is, but based on your description, I think a Gtk::DrawingArea based approach would be relatively straightforward and make it possible to control the look of the result. – ergosys May 08 '12 at 05:27

2 Answers2

1

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.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • would it be completely awful to simply maintain my GUI in memory, and then use set_text to do a basic wipe and refresh on the entire buffer when i want it changed? basically perform all of my manipulations on a long char array (with newlines at every 25th index), and then push that via set_text? – jasonmclose May 08 '12 at 11:33
  • Depends on how often you need to update the display. Perhaps best to just try it, and then optimize it later if it's too slow? Memory won't be a problem, most computers have at least 250 bytes of memory these days. – ptomato May 08 '12 at 11:38
  • updates once a second. i think i will go this route. i like the idea of using cairo like unwind posted, but i have a deadline to meet for a beta test, so i will do it this way for now, and optimize it later, once i get time for phase 2. – jasonmclose May 08 '12 at 12:20
0

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Hey. Why just GTK+ 3.x. and not with GTK+ 2? I know there are quite a few changes here and there, but are there any performance improvements? Because from my experience, Cairo is awful for something like that. – Ivarpoiss Jun 12 '12 at 14:48