I am trying to implement as TextView which automatically scrolls to display the latest added text unless there is any user scroll input.
Basically, the view auto-scrolls until the user does any scroll input or moves the slider bar, which has the effect of pausing the auto-scroll (text continues to be inserted).
When the user scrolls back to the bottom, auto-scroll resumes.
For the auto scrolling, I am using
end_iter = TextView.get_end_iter()
TextView.scroll_to_iter(end_iter, 0, False, 0, 0)
For detecting if the user has done any movement, I am trying to check if the end iterator is still visible with:
location = self.log_view.get_iter_location(iter)
visible = self.log_view.get_visible_rect()
if location.intersect(visible)[0]:
text_view.scroll_to_iter(end_iter, ...)
However, location.intersect(visible)
returns False
with a resulting intersection rectable having all 0 values.
How would one go about implementing the functionality that I am after?
Thank you.
Hi,
get_iter_location()
returns a zero-width rectangle, so intersect()
will always return False, because null areas can’t intersect with anything.
You can force the width to be at lease 1px:
location = self.log_view.get_iter_location(iter)
location.width = 1
Thanks for that hint.
I still can’t figure out how to determine if the user has changed the position of the text/scrollview. I can add a scroll event controller but that only deals with the mouse scroll. There doesn’t seem to be a way to determine this from the Adjustment (the value of the adjustment constantly changes because the view is auto-scrolled).
I suggest the other way around: try to detect the text insertion, e.g. with Gtk.TextBuffer::insert-text , and if the adjustment value
+page
>=upper
then perform the scroll.
That is a interesting idea but unfortunately but unfortunately, it doesn’t work. The problem is that the volume of text that gets inserted is large enough to cause the upper
value to jump way past the value + page
sum on the first signal callback:
0.0 400.0 400.0 0.0
0.0 400.0 37808.0 37408.0
0.0 400.0 81504.0 81104.0
(values above are value
, page_size
, upper
, upper - (value + page_size)
)
So, the text view ends up never actually scrolling.