Re: TextView scrolling/cursor problems



For archival purposes followes a working autoscrolling output method 
whose scrolling is not dependent on the current cursor position. 
Seasoned gtkmm users certainly know about this or even better methods 
but for newbies like me it was not easy to figure out how to do this, 
even though one might think having an autoscrolling TextView should be 
a trivial thing to implement.

Sorry for the formatting.

void windowMain::print_output(Gtk::TextView* textview, std::string text)
{
	// A mark thingy
	Glib::RefPtr<Gtk::TextBuffer::Mark> cur_mark;
	
	cur_mark = 
(textview->get_buffer())->create_mark((textview->get_buffer())->end());
	
	// Insert passed text into buffer of passed TextView 
	(textview->get_buffer())->insert((textview->get_buffer())->end(),text);

	// Move the mark to the end of the buffer
	(textview->get_buffer())->move_mark(cur_mark, 
(textview->get_buffer())->end());

	// Scroll there
	textview->scroll_to(cur_mark, 0.0);
}

Andreas
-- 
Andreas "daff" Ntaflos 
daff AT dword DOT org
Vienna, Austria 

GPG Fingerprint: 	6234 2E8E 5C81 C6CB E5EC  7E65 397C E2A8 090C A9B4
GPG Public Key ID: 	090CA9B4
GPG Public Key:		http://daffit.meownz.info/publickey/andreas_ntaflos.asc

Attachment: pgpxkBLT0skyk.pgp
Description: PGP signature



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