Reputation: 2069
I'm working on a X-plotter like widget that plots incomming data live. I already searched for an solution to realize a scrolling along the x-axis if the widget has to much values and so they don't fit.
I had the folling approaches to realize it:
I really searched the web for suggestions or examples, but there is nothing about how to "construct" custom controls in a good way (beyond drawing something) esp. in the case of interaction... Sorry but I'm a newbie at GTK in general :/
Upvotes: 0
Views: 665
Reputation: 3134
Most widgets in Gtk do not have scrollbars.
If you want to scroll the entire widget, you have to implement the GtkScrollable
interface. Then, you add the widget to a GtkScrolledWindow
. The scrolled window has the scrollbars, those GtkScrollbars
are linked with GtkAdjustments
which are passed to your custom widget through the GtkScrollable
interface set_vadjustment
and set_hadjustment
.
If you just want to add a scrollbar and control its behaviour yourself, then you need to somehow add a GtkScrollbar
in your widget, which means you will need to make it a container too.
The GtkScrollable
approach is the following, first you implement vadjustment
and hadjustment
setters and getters, then when the GtkAdjustments
are set, you set its lower and upper limits and the page size(how much of the widget is visible at once). After that, you connect their value-changed
signal so you can refresh your widget when the scrollbars are dragged. A GtkScrollable
doesn't get to check the scrollbars, only the adjustments that will be bound to the scrollbars. When drawing the widget you get the adjustments' value
property in order to determine how much the scrollbars have shifted in the horizontal and vertical axes.
Upvotes: 2