I have a GTK# Text View with word wrap and scroll bars turned on. I know that horizontal scroll bars will not be show because the words will wrap instead.
I want to add some text but before adding it I want to find out if the text will fit without the need for a vertical scroll bar.
I don’t want to add the text if it means that the text view will require a vertical scroll bar.
How do I do this?
I’m not aware of any way to measure the contents of a TextView without actually updating the text. It’s a complex text layout widget that can handle formatted text, images, etc. Inserting text could change the layout quite substantially, so you can’t “predict” how some new text will change the size without actually modifying the buffer and recalculating its layout.
It would be easier to suggest a solution if you explain why you need this functionality.
For example, if you simply need to know after adding text whether when the view will have scrollbars, you could use the scroll adjustments – the TextView is a “scrollable” widget, i.e. its layoutspace is virtualised, and is manipulated by a parent ScrolledWindow via “Adjustment” objects that contain the range, page size, scroll increment size, etc. You could detect when they change by accessing them from the ScrolledWindow and subscribing to their change events.