From 9e6e3bd269840225c6d2f932fe72214765c4ac01 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 18 Jun 2012 16:46:43 +0200 Subject: [PATCH] Custom Treebook implementation --- lib/Slic3r/GUI/SkeinPanel.pm | 22 +++--------------- lib/Slic3r/GUI/Tab.pm | 43 +++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 1b7b43838..25a7ca674 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -22,26 +22,10 @@ sub new { my $self = $class->SUPER::new($parent, -1); my $tabpanel = Wx::Notebook->new($self, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, &Wx::wxNB_TOP); - my $make_treebook_tab = sub { - my $class = shift; - - my $tab = Wx::Panel->new($tabpanel, -1); - my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); - $sizer->Add($class->new($tab), 1, &Wx::wxALL | &Wx::wxEXPAND, 5); - $tab->SetSizer($sizer); - return $tab; - }; - - my @tabs = ( - $make_treebook_tab->('Slic3r::GUI::Tab::Print'), - $make_treebook_tab->('Slic3r::GUI::Tab::Filament'), - $make_treebook_tab->('Slic3r::GUI::Tab::Printer'), - ); - $tabpanel->AddPage(Slic3r::GUI::Plater->new($tabpanel), "Plater"); - $tabpanel->AddPage($tabs[0], "Print settings"); - $tabpanel->AddPage($tabs[1], "Filament settings"); - $tabpanel->AddPage($tabs[2], "Printer settings"); + $tabpanel->AddPage(Slic3r::GUI::Tab::Print->new($tabpanel), "Print settings"); + $tabpanel->AddPage(Slic3r::GUI::Tab::Filament->new($tabpanel), "Filament settings"); + $tabpanel->AddPage(Slic3r::GUI::Tab::Printer->new($tabpanel), "Printer settings"); my $buttons_sizer; { diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index b34892452..27b04857a 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -4,17 +4,36 @@ use warnings; use utf8; use Wx qw(:sizer :progressdialog); -use Wx::Event qw(); -use base 'Wx::Treebook'; +use Wx::Event qw(EVT_TREE_SEL_CHANGED); +use base 'Wx::Panel'; sub new { my $class = shift; my ($parent) = @_; my $self = $class->SUPER::new($parent, -1, [-1,-1], [-1,-1], &Wx::wxBK_LEFT); - $self->{images} = Wx::ImageList->new(16, 16, 1); - $self->AssignImageList($self->{images}); - $self->{imagecount} = -1; + $self->{sizer} = Wx::BoxSizer->new(&Wx::wxHORIZONTAL); + $self->{sizer}->SetSizeHints($self); + $self->SetSizer($self->{sizer}); + + $self->{treectrl} = Wx::TreeCtrl->new($self, -1, [-1, -1], [200, -1], &Wx::wxTR_NO_BUTTONS | &Wx::wxTR_HIDE_ROOT | &Wx::wxTR_SINGLE | &Wx::wxTR_NO_LINES); + $self->{sizer}->Add($self->{treectrl}, 0, &Wx::wxEXPAND); + + $self->{icons} = Wx::ImageList->new(16, 16, 1); + $self->{treectrl}->AssignImageList($self->{icons}); + $self->{iconcount} = -1; + + $self->{treectrl}->AddRoot("root"); + $self->{pages} = {}; + $self->{treectrl}->SetIndent(0); + EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub { + $_->Hide for values %{$self->{pages}}; + $self->{sizer}->Remove(1); + my $page = $self->{pages}->{ $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) }; + $page->Show; + $self->{sizer}->Add($page, 1, &Wx::wxEXPAND | &Wx::wxLEFT, 5); + $self->{sizer}->Layout; + }); return $self; } @@ -22,17 +41,19 @@ sub new { sub AddOptionsPage { my $self = shift; my $title = shift; - my $image = (ref $_[1]) ? undef : shift; + my $icon = (ref $_[1]) ? undef : shift; my $page = Slic3r::GUI::Tab::Page->new($self, @_); - my $bitmap = $image - ? Wx::Bitmap->new("$Slic3r::var/$image", &Wx::wxBITMAP_TYPE_PNG) + my $bitmap = $icon + ? Wx::Bitmap->new("$Slic3r::var/$icon", &Wx::wxBITMAP_TYPE_PNG) : undef; if ($bitmap) { - $self->{images}->Add($bitmap); - $self->{imagecount}++; + $self->{icons}->Add($bitmap); + $self->{iconcount}++; } - $self->AddPage($page, $title, undef, $self->{imagecount}); + $page->Hide; + $self->{treectrl}->AppendItem($self->{treectrl}->GetRootItem, $title, $self->{iconcount}); + $self->{pages}{$title} = $page; } package Slic3r::GUI::Tab::Print;