I am new here and this is a crosspost from Stackoverflow, since it seems that it doesn't really get any attention there, i thought this forum might be a little more suitable. Anyway, if someone wants to earn any karmapoints on stacko, i leave the url here: http://stackoverflow.com/questions/11470338/gtk-textview-cursor-alway-on-center-line
I have a Gtk TextView, where I would like to be able to center the cursor vertically in the center (like a typewriter).
If the cursor is moved, the text should scroll up (or down), but the cursor should still stay in center position.
I tried several things: Adding a margin on the first and last character of the textview, but that makes problems when adding text behind the first and last character. Also its not nice if one selects the first line, the selection color expands into the "empty" room.
In short, I need to:
Add a margin before the first line
Add a margin after the last line
Scroll text to center on cursor_move or text_changed (I currently solved this with
cursor_iter = self.TextBuffer.get_iter_at_mark(cursor)
fflines = round(self.window_height/(2*20))
self.TextEditor.scroll_to_iter(cursor_iter, 0.0, True, 0, 0.5)
however, with this approach I would need several newlines at the end of my textview. So if someone knows a better solution to that, I'd be happy to hear it)
I was thinking about doing pixelbased scrolling, but I don't know how to go about this.
I'd be happy to hear some suggestions!
My new idea is to create a specific number of newlines at the end and the beginning of the TextBuffer, and add a callback to every selection/cursor move to test if it hits the added newlines. If so, move the cursor either to start_iter or end_iter and thus prevent modifying these additional newlines.
But it seems hacky to me.
Also I noticed a very strange (bug?) in the gi.repository.Pango (python) that if you try to create a gi.repository.Pango.TabArray() you'll always get a memory error. Even in the python console. So sadly I'm not able to modify the tabwidth in the TextView with my python code. Thats quite annoying. (I also tried to modify it with the get_tab_blabla) but since it's still in its default state it only returns Null...
Thank you i