Resetting size of GtkDrawingArea?

I have a GtkDrawingArea inside of a GtkScrolledWindow.

I use gtk_widget_set_size_request() to set minimum size for the drawing area when the content is too big to fit, and this forces the scrolled window to display scrollbars, so the user can see the entire file.

But if the user opens a new file, the size of the drawing area that was set for the previous file is still saved, and if the file is smaller than the previous one, the user sees extra space of the drawing area, that is not needed.

So my question is: is it possible to somehow reset the size of the drawing area so it is equal to the size of the visible region (and so no scrollbars appear). Or do I just destroy the drawing area and create a new one?

Sorry, can not really help you.

But does GtkDrawingArea inside GtkScrolledWindow work really fine for you? Is drawing fast, does clipping work fine? For example if you have a large collection of objects to draw, but only few are really visible (called zoomed in). Is drawing automatically restricted to visible objects, or can you easily restrict the drawing to objects which really needs redraw? Maybe when an object is moved, redraw only object itself and only background and objects overlapping? Otherwise complete redraw can be very slow with cairo.

If that really works fine for you, can you provide a nice, not too large example?

I tried GtkDrawingArea inside GtkScrolledWindow myself ten years ago, but switched to GtkDrawingArea with custom scrollbars soon. Initial app was http://ssalewski.de/PetEd.html.en, a half year ago I ported the GtkDrawingArea code to Nim, https://github.com/StefanSalewski/gintro#a-more-advanced-example-for-cairo-drawing-with-zooming-panning-scrolling, and now I am slowly porting the drawing app. Object location is supported by my RTree module now, see https://github.com/StefanSalewski/RTree. Works fine, but I would still be interested in alternate, maybe simpler solutions.

Nevermind, I was really sleepy when I posted this and I didn’t realize that if you pass -1 and -1 gtk_widget_set_size_request, you reset the area size. So that’s solved.

Perfectly.

Yes, something like that.

You just draw normally, i.e. draw everything and GTK takes care of the details. I’m don’t know what GTK does in that case, but I guess it either smartly avoids rendering what is outside of view and maybe uses backing store features of X server to avoid redraws. Or maybe not.

I guess you can do that, but if that’s what you want you’d have to draw everything manually.

I don’t know whether I can help you, I’m not an expert myself. I use scrolled window to display one image at a time, and I never implemented something so complex using Cairo / GTK.

So I’m afraid I can’t help you here except for most basic stuff. Sorry, and good luck!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.