Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling a very large GtkDrawingArea

Tags:

c++

c

gtk

gtk2

I have a GtkDrawingArea that is used to visualize data. Depending on the database and user input the drawing can grow really large (larger than the maximum allowed GtkDrawingArea size). Therefore I would like to use a drawing area that is just as big as the current window and update it manually upon scrolling.

If I use the ScrolledWindow + Viewport method to add scroll-bars to the drawing area it does obviously not work because the drawing area is not big enough to need scroll-bars.

Is there any way that that I can trick the viewport into thinking that the underlying widget is larger than it actually is? If not what would be the best way to solve this problem?

Note: I am using Gtk2 and switching to Gtk3 is not a possibility.

like image 298
Arne Böckmann Avatar asked Nov 03 '22 02:11

Arne Böckmann


1 Answers

You need to subclass GtkDrawingArea and override the set_scroll_adjustments signal. GtkWidget docs

In this signal you will get the adjustments for the scrolled window. I wrote some code a few years back that you can look at to see how to implement it.

MarlinSampleView code

This code was able to pretend that the widget was millions of pixels wide when in reality it wasn't any bigger than the window.

like image 58
iain Avatar answered Nov 15 '22 05:11

iain