Commits

Herbert Breunung committed 39546d3

replaced with improved and cleaner App::Panel

Comments (0)

Files changed (2)

lib/Kephra/App/Bar/Document.pm

 	# put panel under a none-panel
 	unless ($new_page->isa('Wx::Panel')) {
 		my $widget = $new_page;
-		$new_page = Kephra::App::Panel->new( $self, $widget);# if ($position == 0 or $label);
+		$new_page = Kephra::App::Panel->new( $self, \$widget);# if ($position == 0 or $label);
 		# document property: panel the editor sits on has to be set before EVT_AUINOTEBOOK_PAGE_CHANGED
 		Kephra::DocumentStash::doc_by_ed( $widget )->panel( $new_page ) if $widget->isa('Kephra::Editor'); # and ($position == 0 or $label);
 	}

lib/Kephra/App/Panel.pm

 our @ISA = 'Wx::Panel';
 my $is_widget = Kephra::App::Util::get('is_widget');
 
+
 sub new {
-	my( $class, $parent, $children) = @_;
+	my $class = shift;
+	my $parent = shift;
+	my @children = @_;
 	$parent = Kephra::API::main_window() unless defined $parent and $is_widget->($parent);
+
 	my $self = $class->SUPER::new( $parent );
 	my $sizer = $self->{'sizer'} = Wx::BoxSizer->new( &Wx::wxVERTICAL );
 	$self->SetSizer($sizer);
 
 	$self->{'widgets'} = [];
-	# if list of widgets came in a ref, flat them
-	my @children = ref $children eq ref [] ? @$children : $children;
-	# if there is only one widget without further info, make it to fill space
-	if (@children == 1 and not ref $children[0] eq ref {}){
-		$children = $children[0];
-		$children[0] = \$children;
+	for my $child (@_) {
+		$self->append($child);
 	}
-	$self->append(@children);
 	$self;
 }
 
 sub prepend {
 	my ($self, @widgets) = @_;
-	my %presets = ( position => 0 );
-	$self->_insert($_, \%presets) for @widgets;
+	$self->_insert({widget => $_, position => 0}) for @widgets;
 }
-
 sub append {
 	my ($self, @widgets) = @_;
-	my %presets = ( position => $self->{'sizer'}->GetChildren || 0 );
-	$self->_insert($_, \%presets) for @widgets;
+	$self->_insert({widget => $_, 
+	                position => $self->{'sizer'}->GetChildren || 0}) for @widgets;
 }
-
+sub append_expanded {
+	my ($self, @widgets) = @_;
+	$self->_insert({
+		widget => $_, 
+		position => $self->{'sizer'}->GetChildren || 0, 
+		proportion => 1                               }) for @widgets;
+}
 sub insert {
-	my ($self, $position, @widgets) = @_;
-	my %presets = ( position => $position );
-	$self->_insert($_, \%presets) for @widgets;
+	my ($self, $widget, $position ) = @_;
+	$self->_insert({widget => $widget, position => $position}) if ref $widget;
 }
 
 sub _insert { # only one item
-	my ($self, $item_def, $presets) = @_;
-	my %item = (
+	my ($self, $item) = @_;
+	return Kephra::Log::error('got hash as item def') unless ref $item eq 'HASH';
+	return Kephra::Log::error('got no proper widget, but '.$item->{'widget'})
+		unless $is_widget->( $item->{'widget'} )
+		or $is_widget->( ${$item->{'widget'}} );
+	# ref to widget ref can signal to expand that widget
+	if (ref $item->{'widget'} eq 'REF'){
+		$item->{'widget'} = ${ $item->{'widget'} };
+		$item->{'proportion'} = 1;
+	}
+	my %presets = (
 		position => $self->{'sizer'}->GetChildren || 0,
 		proportion => 0,
 		style => &Wx::wxGROW,
 		border => 0,
 	);
-	if (ref $item_def eq ref {}) {
-		Kephra::Log::error('got no proper widget, but '.$item_def->{'widget'})
-			unless $is_widget->( $item_def->{'widget'} );
-		for (qw/proportion widget border/)
-			{ $item{$_} = $item_def->{$_} if exists $item_def->{$_} }
-	} elsif (ref $item_def eq ref \$item_def ) {
-		Kephra::Log::error('got no proper widget, but '.$$item_def)
-			unless $is_widget->($$item_def);
+	for (qw/position proportion style border/)
+		{ $item->{$_} = $presets{$_} unless exists $item->{$_} }
 
-		$item {'widget'} = $$item_def;
-		$item {'proportion'} = 1;
-	} else {
-		Kephra::Log::error('got no proper widget, but '.$item_def)
-			unless $is_widget->($item_def);
-
-		$item {'widget'} = $item_def;
-	}
-	if (defined $presets and ref $presets eq ref {}){
-		for (qw/position proportion style border/)
-			{ $item{$_} = $presets->{$_} if exists $presets->{$_} }
-	}
-
-	splice @{$self->{'widgets'}}, $item{'position'}, 0, $item{'widget'};
+	splice @{$self->{'widgets'}}, $item->{'position'}, 0, $item->{'widget'};
 	$self->{'sizer'}->Insert(
-		$item{'position'}, $item{'widget'}, $item{'proportion'},
-		$item{'style'},    $item{'border'}
+		$item->{'position'}, $item->{'widget'}, $item->{'proportion'},
+		$item->{'style'},    $item->{'border'}
 	);
-	$item{'widget'}->Reparent($self) if $is_widget->( $item{'widget'} );
+	$item->{'widget'}->Reparent($self) unless $item->{'widget'}->GetParent eq $self;
+	$item->{'position'};
 }
 
 sub remove {}