Re: [Vala] Newbie help requested for scrolling a TextView




On 01/25/18 18:04, Manish Jain wrote:


On 01/25/18 16:11, Al Thomas wrote:
On Thursday, 25 January 2018, 01:00:05 GMT, Manish Jain 
<jude obscure yandex com> wrote:

Despite a lot of effort to write an event handler, I still cannot get
the scale to tell the view to scroll. I have tried scrolling with the
scroll_to_iter() method, but the iterator always lands me at the top of
the file, whereas I want the view to move south.

Have you tried moving the TextIter with something like:
https://valadoc.org/gtk+-3.0/Gtk.TextIter.set_line.html

It sounds like you want a TextIter instance for your vscale widget 
that you can then move
about the document and then scroll to it.

It may be your almost there, just missing the last piece of the puzzle!

Regards,

Al

Hi Al/others,

The scrolling is beginning to happen, but not in the way I would expect.

Here is my event handler for the scale (which I am using a normal
command widget) :

     void scale_moved (Gtk.Range range)
     {
         TextIter iter = TextIter();

         view.get_iter_at_location(out iter, 0, ypos);
         view.scroll_to_iter(iter, 0, false, 0, 0);
         view.place_cursor_onscreen();
         ypos++;
     }

The ypos counter is initialized as 0, and then gets incremented
each time the scale is used. Effectively, each time the uses clicks
the scale, the view should move south one line. That is the behaviour
I would expect.

But the scrolling is almost negligible unless I jack up ypos argument
to get_iter_at_location() as 25*ypos - at which point the view moves
south sometimes one line or sometimes two lines.

I must be missing something: is the view scrolling somehow dependent
on window geometry and/or line lengths ? I would normally think the
ypos argument is just the number of newlines (minus one) to be skipped
when readjusting the view.


Hi all,

I managed to work it out. Luckily, Vala documentation is superb.

Unless I am mistaken, the iterator has to be initialized with a call
to view.buffer.get_iter_at_line().

After that, the programmer has to compute view/line heights using
view.get_window(Gtk.TextWindowType.TEXT).get_height() and
view.get_line_yrange().

It is all working nicely now. Thanks to all for help.

Manish Jain


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]