Re: Subclassing Gtk2::CellRenderer (reprise)



First impression is "Wow!". Not only does it show how to sub-class a renderer (from what I can see, this is 90-95% of what I need in my application, directly from your example code), it also gives good hints at how to sub-class other classes (if that should turn out to be necessary or desired), and there's even an example of how to create and use a "raw" ListStore.

Tusen takk!

Visually distinguishing the cells with the special renderer can be done by simply painting an arrow in front of the text. Please see attached diff. It doesn't really look like an arrow at this font size, but still... Doesn't look too bad, does it?

Bjarne

*** Gtk2-CellRenderer-Base-0.01/example.pl      Sat Oct 11 00:12:42 2003
--- myexample.pl        Mon Oct 13 23:58:44 2003
***************
*** 33,43 ****
  
  use constant xpad => 3;
  use constant ypad => 2;
  
  sub calc_size {
        my ($cell, $layout) = @_;
        my ($w, $h) = $layout->get_pixel_size;
!       return (xpad, ypad, $w + xpad * 2, $h + ypad * 2);
  }
  
  sub on_get_size {
--- 33,46 ----
  
  use constant xpad => 3;
  use constant ypad => 2;
+ # Arrow will use text height and ypad
+ use constant arrow_width => 5;
+ use constant arrow_xpad => 5;
  
  sub calc_size {
        my ($cell, $layout) = @_;
        my ($w, $h) = $layout->get_pixel_size;
!       return (xpad, ypad, $w + xpad * 2 + arrow_width + arrow_xpad * 2, $h + ypad * 2);
  }
  
  sub on_get_size {
***************
*** 49,55 ****
  
  sub get_layout {
        my ($cell, $widget) = @_;
!       return $widget->create_pango_layout ("");
  }
  
  sub on_render {
--- 52,59 ----
  
  sub get_layout {
        my ($cell, $widget) = @_;
!       return $cell->{layout} if defined $cell->{layout};
!       return $cell->{layout} = $widget->create_pango_layout ("");
  }
  
  sub on_render {
***************
*** 77,87 ****
        my $layout = $cell->get_layout ($widget);
        $layout->set_text ($cell->{list}[$cell->{index}]);
        my ($xoff, $yoff, $width, $height) = $cell->calc_size ($layout);
        $widget->get_style->paint_layout ($window,
                                $state,
                                 1, $cell_area,
                                 $widget, "cellrenderertext",
!                                $cell_area->x+$xoff,
                                 $cell_area->y+$yoff
                                 + ($cell_area->height - $height) / 2,
                                 $layout);
--- 81,98 ----
        my $layout = $cell->get_layout ($widget);
        $layout->set_text ($cell->{list}[$cell->{index}]);
        my ($xoff, $yoff, $width, $height) = $cell->calc_size ($layout);
+ 
+       $widget->get_style->paint_arrow ($window, $state, 'none',
+                               $cell_area, $widget, "",
+                               'down', 0,
+                               $cell_area->x+$xoff,
+                               $cell_area->y+$yoff + ($cell_area->height - $height) / 2,
+                               arrow_width, $cell_area->height);
        $widget->get_style->paint_layout ($window,
                                $state,
                                 1, $cell_area,
                                 $widget, "cellrenderertext",
!                                $cell_area->x+$xoff + arrow_width + arrow_xpad,
                                 $cell_area->y+$yoff
                                 + ($cell_area->height - $height) / 2,
                                 $layout);
***************
*** 156,161 ****
--- 167,175 ----
           [ 'flurble',    [qw/murble swurble curble/]],
           [ 'frob',       [qw/blob clob plob mob rob gob glob wob dob/]],
           [ 'frobnitz',   [qw/fronbination that's sweepin' the nation/]],
+ #         [ 'repeated',   [qw/fronbination that's sweepin' the nation the the the the/]],
+ #         [ 'none',   [],
+ #         [ 'verymany',   [(1..50)]],
           [ 'ftang',      [qw/quisinart/]],
           [ 'fire truck', [qw/red white green yellow polka-dot/]]) {
        my $iter = $model->append;


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