RE: Scrolling a Cairo drawing-area or Gtk layout
Hi Damien Caliste, Jim Charlton, and Pramithesh, that has worked and here is the code I used:window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);gtk_window_set_default_size(GTK_WINDOW(window2), 1000, 800);grid2 = gtk_grid_new();darea = gtk_drawing_area_new();gtk_widget_set_size_request(darea, 3000, 2000);gtk_grid_attach(GTK_GRID (grid2), darea, 0, 0, 1, 1);g_signal_connect(G_OBJECT(darea), "draw", G_CALLBACK(on_draw_event), NULL);g_signal_connect(G_OBJECT(darea), "destroy", G_CALLBACK(gtk_widget_destroy), NULL);swin2 = gtk_scrolled_window_new(NULL, NULL);gtk_container_set_border_width(GTK_CONTAINER (swin2), 5);gtk_container_add(GTK_CONTAINER (swin2), grid2);box2 = gtk_box_new (TRUE, 5);gtk_box_pack_start (GTK_BOX (box2), swin2, TRUE, TRUE, 5);gtk_container_add (GTK_CONTAINER (window2), box2);gtk_widget_show_all (window2); > Date: Mon, 27 Jul 2015 10:10:27 +0200 > From: damien.cali...@cea.fr > To: gtk-app-devel-list@gnome.org > Subject: Re: Scrolling a Cairo drawing-area or Gtk layout > > Hello, > > Le 21/07/2015, Roger Matthews a écrit : > > which results from a simple straight line equation, and*/ /* that > > extends beyond the bounds of the window. > Reading your code quickly, it seems to me that, you're drawing indeed > the line outside the drawing area, *but* the drawing area has the size > of your window, so GTK is not displaying any scrollbars. > > In my opinion, you should : > - in main, declare your drawing area to a fixed size (let say > 1200×1200) and declare your window size at 600×400 as you're doing ; > - in the drawing method (do_drawing()), don't use the window size, but > the drawing size as bounds from your drwaing commands. It's useless > to draw lines or whatever outside the cairo drawing area, they will > be cropped anyway. So don't reach for the top level there, use the > size of the widget itself. > > As a schemme : > - your implementation : |#| > - the way to do it : |##| > - # means GTK scrollview, - means drawing area > - call cairo drawing primitives in the coordinates of the drawing area > (-), but not outside. > > Damien. > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Scrolling a Cairo drawing-area or Gtk layout
I did some testing of the code and also found that getting scroll bars to appear was not so easy. The only way that I could get them to appear was to modify the code with a container layout of: layout2->viewport->scrolled window->window2. Here is the section of the code that I altered. * window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL); layout2 = gtk_layout_new(NULL, NULL); GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL); GtkWidget *viewport = gtk_viewport_new (NULL,NULL); gtk_scrolled_window_set_policy (sw, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); gtk_widget_set_size_request (layout2, 800, 600); g_signal_connect(G_OBJECT(layout2), "draw", G_CALLBACK(on_draw_event), NULL); g_signal_connect(G_OBJECT(layout2), "destroy", G_CALLBACK(gtk_widget_destroy), NULL); gtk_window_set_default_size(GTK_WINDOW(window2), 600, 400); gtk_window_set_title(GTK_WINDOW(window2), "Graph"); gtk_container_add(GTK_CONTAINER (viewport), layout2); gtk_container_add(GTK_CONTAINER (sw), viewport); gtk_container_add(GTK_CONTAINER (window2), sw); gtk_widget_show_all(window2); *** I am using GTK3 and the documentation says that specifically including the viewport is not needed as it *should* be included automatically when it is needed. But that was not my experience in this case. I also agree with Damien that the goal of the code is unclear. You cannot scroll to a part of the plot that is not drawn. In the code above, you can only scroll around within the dimensions of layout2. Is that what you wanted? jim charlton On 15-07-27 01:10 AM, Damien Caliste wrote: Hello, Le 21/07/2015, Roger Matthews a écrit : which results from a simple straight line equation, and*/ /* that extends beyond the bounds of the window. Reading your code quickly, it seems to me that, you're drawing indeed the line outside the drawing area, *but* the drawing area has the size of your window, so GTK is not displaying any scrollbars. In my opinion, you should : - in main, declare your drawing area to a fixed size (let say 1200×1200) and declare your window size at 600×400 as you're doing ; - in the drawing method (do_drawing()), don't use the window size, but the drawing size as bounds from your drwaing commands. It's useless to draw lines or whatever outside the cairo drawing area, they will be cropped anyway. So don't reach for the top level there, use the size of the widget itself. As a schemme : - your implementation : |#| - the way to do it : |##| - # means GTK scrollview, - means drawing area - call cairo drawing primitives in the coordinates of the drawing area (-), but not outside. Damien. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Scrolling a Cairo drawing-area or Gtk layout
Hello, Le 21/07/2015, Roger Matthews a écrit : > which results from a simple straight line equation, and*/ /* that > extends beyond the bounds of the window. Reading your code quickly, it seems to me that, you're drawing indeed the line outside the drawing area, *but* the drawing area has the size of your window, so GTK is not displaying any scrollbars. In my opinion, you should : - in main, declare your drawing area to a fixed size (let say 1200×1200) and declare your window size at 600×400 as you're doing ; - in the drawing method (do_drawing()), don't use the window size, but the drawing size as bounds from your drwaing commands. It's useless to draw lines or whatever outside the cairo drawing area, they will be cropped anyway. So don't reach for the top level there, use the size of the widget itself. As a schemme : - your implementation : |#| - the way to do it : |##| - # means GTK scrollview, - means drawing area - call cairo drawing primitives in the coordinates of the drawing area (-), but not outside. Damien. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list