Text alignment in a custom cell renderer?



I've got a custom text cell renderer, and I've discovered that if I
provide a RENDER sub, I loose a lot of nice stuff, eg alignment.

I assume I have to get the value of the 'xalign' property and manually
set alignment, but I can't quite figure out how to do that. There's no
parent object for the layout ( I originally thought it might have a
Gtk2::Alignment parent ... as in my previous alignment question ...  but
no such luck in this case ). I've tried the 'set_alignment' method of
the layout object, but this doesn't seem to align things either. Any clues?

Current RENDER sub:

sub RENDER {
   
    my ( $cell, $window, $widget, $background_area, $cell_area,
$expose_area, $flags ) = @_;
   
    my $state;
   
    if ( $flags & 'selected' ) {
        $state = $widget->has_focus()
            ? 'selected'
            : 'active';
    } else {
        $state = $widget->state() eq 'insensitive'
            ? 'insensitive'
            : 'normal';
    }
   
    my $layout = $cell->get_layout( $widget );
   
    my $original_text = $cell->get( "text" ) || '';
   
    my $final_text = $original_text;
   
    if ( $cell->get('number') ) {
       
        my $decimals = $cell->get('decimals');
        my $decimal_fill = FALSE;
       
        if ( $decimals ) {
            $decimal_fill = TRUE;
        }
       
        my $formatter = Number::Format->new(
            thousands_sep   => ',',
            decimal_point   => '.',
            decimal_fill    => $decimal_fill
                                           );
       
        if ( $decimals ne "-1" ) {
            $final_text = $formatter->round( $final_text, $decimals );
        }
       
        $final_text = $formatter->format_number( $final_text );
       
    }
   
    # If we're a currency renderer, prepend a dollar sign,
    # but only if there is data ... otherwise we don't want to render
anything
       
    if ( $cell->get('currency') ) {
        if ( $original_text ) {
            $final_text = '$' . $original_text;
        } else {
            $final_text = '';
        }
    }
   
    # Neither xalign property nor set_alignment() seem to work here ...
    if ( $cell->get('xalign') == 1 ) {
        $layout->set_alignment( 'right' );
    }
   
    $layout->set_text ( $final_text );
   
    my ( $x_offset, $y_offset, $width, $height ) = $cell->calc_size(
$layout );
   
    $widget->get_style->paint_layout(
        $window,
        $state,
        1,
        $cell_area,
        $widget,
        "cellrenderertext",
        $cell_area->x() + $x_offset + x_padding,
        $cell_area->y() + $y_offset + y_padding,
        $layout
                                    );
   
}

1;

-- 
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



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