Re: Placement of popup ( CellRendererDate from examples )



muppet wrote:

I know ( or I think I know anyway ... I haven't tried it yet ) I can do $popup->allocation to get the size of the popup.


There's also get_size_request(), which will ask the widget to calculate the size it wants (which propagates to children); you can use this before the widget is onscreen to avoid flicker.

This is returning -1 for x and y sizes. Not to worry - allocation() is working fine, and I've got a working solution now. I've attached a patch, against the cellrenderer_date.pl from Gtk2-1.081, to fix the issue ... it's a damned useful example ... maybe even a candidate for Gtk2::Ex::CoolStuff or something?

Is this the right place to send patches for the example apps?

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au
--- cellrenderer_date.pl.original       2005-09-06 12:26:08.000000000 +1000
+++ cellrenderer_date.pl        2005-09-06 12:27:47.000000000 +1000
@@ -212,14 +212,26 @@
   $popup -> move(-500, -500);
   $popup -> show_all();
 
-  # Align the top right edge of the popup with the the bottom right edge of the
-  # cell.
+  # Figure out where to put the popup - ie don't put it offscreen,
+  # as it's not movable ( by the user )
+  my $screen_height = $popup->get_screen->get_height;
+  my $popup_height = $popup->allocation->height;
+  
   my ($x_origin, $y_origin) =  $view -> get_bin_window() -> get_origin();
-
-  $popup -> move(
-    $x_origin + $cell_area -> x() + $cell_area -> width() - $popup -> allocation() -> width(),
-    $y_origin + $cell_area -> y() + $cell_area -> height()
-  );
+  
+  my ($popup_x, $popup_y);
+  
+  if ($x_origin + $cell_area -> x() + $cell_area -> width() - $popup -> allocation() -> width() < 0) {
+    $popup_x = 0;
+  } else {
+    $popup_x = $x_origin + $cell_area -> x() + $cell_area -> width() - $popup -> allocation() -> width();
+  }
+  
+  if ($y_origin + $cell_area->y + $cell_area->height + $popup_height > $screen_height) {
+    $popup_y = $screen_height - $popup_height;
+  } else {
+    $popup_y = $y_origin + $cell_area -> y() + $cell_area -> height();
+  }
 
   # Grab the focus and the pointer.
   Gtk2 -> grab_add($popup);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]