WxGrid highlighting cells on hover not working as expected
Posted: Mon Aug 05, 2019 1:46 pm
First off, i am not sure if this is better off in general development, or if it needs to be in platform related issues so apologies in advance if i am in the wrong sub forum.
the problem i am facing is, i have wrote a small function that highlights cells on hover... it works GREAT unless the cell spans multiple columns, then the spanned cells are not highlighted if hovering in the spanned cell area (past the first cell in the span).
the way i am doing this is as follows:
Like i said, if i hover the first cell that is spanned multiple columns/cells, the whole cell span is "highlighted". if i hover in the part of the cell thats spanned, it does not highlight the cell at all. so if a cell has a span of 3 columns, if i hover in the first column of the spanned cell, the whole cell is "highlighted". if i hover over to the second or third column in the same cell span, nothing gets highlighted.
https://imgur.com/a/Ny8myaw - hovering first cell in span
https://imgur.com/a/yJAXPGK - hovering past the first cell in the cell span
i did notice that if the cell is spanned, the built in functions of WxGrid are able to tell if it is spanned... if i select a cell thats spanned it outlines the whole spanned cell. so i need to figure out, hopefully with a little help, how wxgrid is managing to know if that cell is spanned and clone that behaviour.
the lib i am working with does not have GetCellSize built in. when i try to use this function i get an error "GetCellSize not found in Wx::Grid", but somehow the built in functions of WxGrid are able to tell because when i click a cell (in original cell or spanned from original cell), it outlines the whole spanned cell.
EDITED: updated description of the problem and added pictures which hopefully help describe my problem.
the problem i am facing is, i have wrote a small function that highlights cells on hover... it works GREAT unless the cell spans multiple columns, then the spanned cells are not highlighted if hovering in the spanned cell area (past the first cell in the span).
the way i am doing this is as follows:
Code: Select all
my $last_col;
my $last_row;
my $id = $grid->GetGridWindow();
EVT_MOTION( $id, sub { onmove( $_[1], $grid, $grid2 ) } );
sub onmove {
my ( $event, $grid, $grid2 ) = @_;
my ($coords) = $event->GetPosition();
my ( $x, $y ) = $grid->CalcUnscrolledPosition( $coords->x, $coords->y );
my $col_pos = $grid->XToCol($x);
my $row_pos = $grid->YToRow($y);
#highlight cell on hover!
if ( $col_pos != $last_col or $row_pos != $last_row ) {
my $last_label = $grid2->GetCellValue( 0, $last_col ) if defined($last_col);
$last_label =~ /(\d{2})\/(\d{2})\/(\d{4})\s(\d{2}):(\d{2})/;
$grid->SetCellBackgroundColour( $last_row, $col_label_lookup{"$3$1$2$4$5"}, Wx::Colour->newRGB( 50, 50, 50 )) if defined($last_row);
$last_col = $col_pos;
$last_row = $row_pos;
my $label = $grid2->GetCellValue( 0, $col_pos );
$label =~ /(\d{2})\/(\d{2})\/(\d{4})\s(\d{2}):(\d{2})/;
$grid->SetCellBackgroundColour( $row_pos, $col_label_lookup{"$3$1$2$4$5"}, Wx::Colour->newRGB( 220, 220, 220 ));
$grid->Refresh;
}
}
https://imgur.com/a/Ny8myaw - hovering first cell in span
https://imgur.com/a/yJAXPGK - hovering past the first cell in the cell span
i did notice that if the cell is spanned, the built in functions of WxGrid are able to tell if it is spanned... if i select a cell thats spanned it outlines the whole spanned cell. so i need to figure out, hopefully with a little help, how wxgrid is managing to know if that cell is spanned and clone that behaviour.
the lib i am working with does not have GetCellSize built in. when i try to use this function i get an error "GetCellSize not found in Wx::Grid", but somehow the built in functions of WxGrid are able to tell because when i click a cell (in original cell or spanned from original cell), it outlines the whole spanned cell.
EDITED: updated description of the problem and added pictures which hopefully help describe my problem.