I have a GtkTextView
, where I would like to be able to center the cursor vertically in the center.
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:
cursor_move
or text_changed
(I currently solved this withcursor_iter = self.TextBuffer.get_iter_at_mark(cursor)
fflines = round(self.window_height/(2*20))
cursor_iter.forward_visible_lines(fflines)
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!
Apparently nobody came up with an answer.
I finally hacked something together that is somehow working. It might not be the cleanest code, but who cares?
Actually, since there is no way to add padding to a textbox, it adds newlines at the beginning and the end of the textfile to get sort of a padding.
You can find my implementation here: Launchpad project for UberWriter
If you want to know more, feel free to ask me by mail.
Cheers, Wolf