Commits

Herbert Breunung committed 21a1b1d

last change were just older bugfixes, now really merge splitter enhancements from sp1

Comments (0)

Files changed (1)

lib/Kephra/App/Splitter.pm

 package Kephra::App::Splitter;
 our @ISA = 'Wx::SplitterWindow';
 
-my $is_widget = Kephra::App::Util::get('is_widget');
+use Scalar::Util qw(looks_like_number);
+use Kephra::App::Util qw(is_widget);
 
 sub new {
 	my ($class, $parameter) = @_;
 	my $parent;
-	if (ref $parameter eq 'HASH')   {$parent = $parameter->{'parent'} || Kephra::API::main_window()}
-	elsif (not defined $parameter)  {$parent = Kephra::API::main_window()}
-	elsif ($is_widget->($parameter)){$parent = $parameter}
+	if (ref $parameter eq 'HASH') {$parent = $parameter->{'parent'} || Kephra::API::main_window()}
+	elsif (not defined $parameter){$parent = Kephra::API::main_window()}
+	elsif (is_widget($parameter)) {$parent = $parameter}
 	else  { return Kephra::Log::error('need parent widget or parameter hash') }
 
 	my $self = $class->SUPER::new($parent);
 	#            split=yes/no/keep
 	return Kephra::Log::error('need parameter as hash') unless ref $parameter eq 'HASH';
 	return Kephra::Log::error('have no first child widget')
-		unless $is_widget->( $parameter->{'top'} )
-		or $is_widget->( $parameter->{'left'} ) or $self->{'child1'};
+		unless is_widget( $parameter->{'top'} )
+		or is_widget( $parameter->{'left'} ) or $self->{'child1'};
 	return Kephra::Log::error('have no second child widget') 
-		unless $is_widget->( $parameter->{'bottom'} )
-		or $is_widget->( $parameter->{'right'} ) or $self->{'child2'};
+		unless is_widget( $parameter->{'bottom'} )
+		or is_widget( $parameter->{'right'} ) or $self->{'child2'};
 	return Kephra::Log::error('declare left/right or top/bottom children or none', 1) 
 		unless (exists $parameter->{'top'} and not exists $parameter->{'left'} and not exists $parameter->{'right'})
 		or (exists $parameter->{'left'} and not exists $parameter->{'top'} and not exists $parameter->{'bottom'})
 	}
 }
 
+sub resize {
+	my ($self, $size) = @_;
+	return unless defined $size;
+	$size = 0.5 if $size eq 'equal';
+	return unless looks_like_number($size);
+
+	if ($size <= 1 and $size > -1){
+		my $size = $self->GetSize;
+		if ($self->GetSplitMode eq &Wx::wxSPLIT_HORIZONTAL){
+			$self->SetSashPosition( $size->GetHeight * $size, 1);
+		} 
+		elsif ($self->GetSplitMode eq &Wx::wxSPLIT_VERTICAL) {
+			$self->SetSashPosition( $size->GetWidth * $size, 1);
+		} 
+		else { return }
+	} 
+	else { $self->SetSashPosition($size, 1) }
+
+	$self->{'position'} = $self->GetSashPosition;
+	$self;
+}
+
 sub resplit {
 	my $self = shift;
 	return if $self->IsSplit;