我正在构建一个新闻阅读器应用程序,并且我有一个 wxScrolledWindow 来显示新闻。但是,我有类别,当单击一个类别时,我想用当前类别的新闻更新此面板。我在 wxScrolledWindow 上使用 DeleteChildren 实现了这一点,但这似乎不能正常工作。
问题是在重新生成新闻时会闪烁,并且除非我拉伸整个窗口,否则滚动条不会出现。此外,有时除非我手动调整新闻大小,否则不会显示。我尝试了刷新,但它仍然是一样的。这是我的代码:
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();
}