# Defines a special column type that does not use a standard rende +rer # The renderer is built by function 'column_builder' # The renderer will assume the first attribute of the model is def +ining the icon to show # and the second attribute contains the markup text to display $class->add_column_type('image_text', type => 'Glib::Scalar', renderer => undef, column_builder => sub { my $pixrd = Gtk3::CellRendererPixbuf->new(); my $txtrd = Gtk3::CellRendererText->new(); my $column = Gtk3::TreeViewColumn->new(); $column->pack_start($pixrd, 0); $column->pack_start($txtrd, 1); $column->add_attribute($pixrd, 'pixbuf', 0); $column->add_attribute($txtrd, 'markup', 1); return $column; } ); # Build the columns list for this new tree # according to the definition of column types my @column_info = (); for (my $i = 0; $i < @_ ; $i+=2) { my $typekey = $_[$i+1]; croak "expecting pairs of title=>type" unless $typekey; croak "unknown column type $typekey, use one of " . join(", ", keys %column_types) unless exists $column_types{$typekey}; my $type = $column_types{$typekey}{type}; if (not defined $type) { $type = 'Glib::String'; carp "column type $typekey has no type field; did you" . " create a custom column type incorrectly?\n" . "limping along with $type"; } push @column_info, { title => $_[$i], type => $type, rtype => $column_types{$_[$i+1]}{renderer}, attr => $column_types{$_[$i+1]}{attr}, column_builder => $column_types{$_[$i+1]}{column_builder}, }; } ## Create the store my $model = Gtk3::TreeStore->new (map {$_->{type}} @column_info); for (my $i = 0; $i < @column_info ; $i++) { if (!defined($column_info[$i]{rtype}) && defined($column_info[ +$i]{column_builder}) && ('CODE' eq ref $column_info[$i]{column_builde +r})) { # A column builder has been defined $view->append_column($column_info[$i]{column_builder}()); } elsif ('CODE' eq ref $column_info[$i]{attr}) { $view->insert_column_with_data_func (-1, $column_info[$i]{title}, $column_info[$i]{rtype}->new, $column_info[$i]{attr}, $i); } elsif ('hidden' eq $column_info[$i]{attr}) { # skip hidden column } else { my $column = Gtk3::TreeViewColumn->new_with_attributes ( $column_info[$i]{title}, $column_info[$i]{rtype}->new, $column_info[$i]{attr} => $i, ); $view->append_column ($column); if ($column_info[$i]{attr} eq 'active') { # make boolean columns respond to editing. my $r = $column->get_cells; $r->set (activatable => 1); $r->signal_connect (toggled => sub { my ($renderer, $row, $col) = @_; my $path = Gtk3::TreePath->new_from_string ($row); my $iter = $model->get_iter ($path); my $val = $model->get ($iter, $col); $model->set ($iter, $col, !$val); }, $i); } elsif ($column_info[$i]{attr} eq 'text') { # attach a decent 'edited' callback to any # columns using a text renderer. we do NOT # turn on editing by default. my $r = $column->get_cells; $r->{column} = $i; $r->signal_connect (edited => \&text_cell_edited, $model); } } }
In reply to Re: Gtk3::SimpleList create personal type with 2 cells in same column
by hanspr
in thread Gtk3::SimpleList create personal type with 2 cells in same column
by hanspr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |