1

I'm building a news reader application and I have a wxScrolledWindow in which I show the news. However, I have categories and when one is clicked, I want to update this panel with the current categorie's news. I achieved that using DeleteChildren on the wxScrolledWindow, but this doesn't seem to work very correctly.

The problem is that there's blinking while the news are regenerating, and also the scrollbars don't appear unless I strech the whole window. Also, sometimes unless I do this manual resizing the news doesn't show. I tried with refresh but it's still the same. Here my code:

our ($self);

sub new {
    my ($class, $parent_window) = @_;
    $self = $class->SUPER::new($parent_window, -1);
    $self->SetScrollRate(10, 10);

    my @news = (...);
    regenerate_news_list(@news);

    return $self;
}

sub regenerate_news_list($) {
    my (@news) = @_;

    $self->DestroyChildren();

    my $vbox = Wx::BoxSizer->new(wxVERTICAL);
    for my $news_item (@news) {

        my $news_panel = Wx::Panel->new($self, wxID_ANY);

        my $news_sizer = Wx::BoxSizer->new(wxVERTICAL);
        my $news_title = Wx::HyperlinkCtrl->new($news_panel, wxID_ANY, $news_item{'title'}, $news_item{'url'},  wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
        my $news_description = Wx::StaticText->new($news_panel, wxID_ANY, $news_item{'description'}, wxDefaultPosition);
        $news_description->Wrap(560);

        $news_sizer->AddSpacer(5);
        $news_sizer->Add($news_title, 0);
        $news_sizer->AddSpacer(5);
        $news_sizer->Add($news_description, 0);
        $news_sizer->AddSpacer(5);

        $vbox->Add($news_panel, 0, wxEXPAND|wxALL);
    }

    $self->SetSizer($vbox);
    $vbox->Fit($self);
    $self->Refresh();
}
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88

2 Answers2

3

Call $self->Freeze() before DestroyChildren() to stop redraws before you do the updates, then call Thaw() when you're done, after Refresh(). It should be much faster and there won't be any flickering.

  • I have not tries this myself, but it sounds like it should work well. +1 – ravenspoint Feb 11 '13 at 13:55
  • This works pretty well, there is no flickering, but the scroll problem is still there. If I do not resize (just a few pixels) the scroll doesn't update itself and does not work. –  Feb 11 '13 at 17:20
0

Use two panels, one which you show to the user, one where you prepare the new display. When the new display is complete, show the new panel and hide the old one. Alternate.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103