Scrolling Very Large GtkDrawingArea

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

If I use the ScrolledWindow + Viewport method to add scrollbars to the drawing area, this obviously does not work, because the drawing area is not large enough to use the scrollbars.

Is there a way I can trick the viewport into thinking that the main widget is bigger than it really is? If not for the best way to solve this problem?

Note. I am using Gtk2, and switching to Gtk3 is not possible.

+5
source share
2 answers

You need to subclass GtkDrawingAreaand override the signal set_scroll_adjustments. GtkWidget Documents

In this signal, you will get the settings for the scrolled window. A few years ago, I wrote some code that you can look at how to implement it.

MarlinSampleView Code

This code was able to pretend that the widget is millions of pixels wide when in reality it is no bigger than a window.

+2
source

It turned out pretty simple:

GtkScrolledWindowhas another constructor that can be used for installation GtkAdjustments, which should use a scrollable window.

//These adjustments will be attached to the scrollbars.
prvt->hAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));
prvt->vAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));

GtkWidget* scrolledTree = gtk_scrolled_window_new(prvt->hAdjustment, prvt->vAdjustment);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledTree), drawing_area);

, , , GtkAdjustments, . .

gtk_adjustment_set_lower(prvt->hAdjustment, 0);
gtk_adjustment_set_step_increment(prvt->hAdjustment, 1);
gtk_adjustment_set_page_increment(prvt->hAdjustment, 10);
gtk_adjustment_set_upper(prvt->hAdjustment, picture_width);
gtk_adjustment_set_page_size(prvt->hAdjustment, scrollArea_width);
gtk_adjustment_changed(prvt->hAdjustment);

, gtk_adjustment_changed . , ScrolledWindow .

, value_changed GtkAdjustmens .

: , GtkScrolledWindow : (

0

All Articles