GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Aug 29, 2016 9:36 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GTK TextView cursor always on vertical center line
PostPosted: Fri Jul 13, 2012 3:34 pm 

Joined: Fri Jul 13, 2012 3:25 pm
Posts: 2
Hello Folks,

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: :)

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

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group