Commits

Herbert Breunung committed b8baf01

rewrote main design with new splitter

  • Participants
  • Parent commits 21a1b1d

Comments (0)

Files changed (2)

File lib/Kephra/App/Splitter.pm

 	return Kephra::Log::error('have no first child widget')
 		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'};
 	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'})
 		or (not exists $parameter->{'top'} and not exists $parameter->{'bottom'}
 			and not exists $parameter->{'left'} and not exists $parameter->{'right'});
 
+	$self->Reparent( $parameter->{'parent'} )
+		if defined $parameter->{'parent'} and is_widget( $parameter->{'parent'} );
 
-	$self->{'child1'} = $parameter->{'top'} if exists $parameter->{'top'};
-	$self->{'child2'} = $parameter->{'bottom'} if exists $parameter->{'bottom'};
-	$self->{'child1'} = $parameter->{'left'} if exists $parameter->{'left'};
+	$self->{'child1'} = $parameter->{'top'}   if exists $parameter->{'top'};
+	$self->{'child2'} = $parameter->{'bottom'}if exists $parameter->{'bottom'};
+	$self->{'child1'} = $parameter->{'left'}  if exists $parameter->{'left'};
 	$self->{'child2'} = $parameter->{'right'} if exists $parameter->{'right'};
-	$self->{'child1'}->Reparent($self)
-		if $self->{'child1'} and $self->{'child1'}->GetParent ne $self;
-	$self->{'child2'}->Reparent($self)
-		if $self->{'child2'} and $self->{'child2'}->GetParent ne $self;
+
+	$self->{'child1'}->Reparent($self) if $self->{'child1'};
+	$self->{'child2'}->Reparent($self) if defined $self->{'child2'}
+										and is_widget( $self->{'child2'} );
 
 
 	$self->SetSplitMode( &Wx::wxSPLIT_HORIZONTAL )
 		if $self->{'dominant_child'} eq 'left' or $self->{'dominant_child'} eq 'top';
 	$self->{'dominant_child'} = 2
 		if $self->{'dominant_child'} eq 'right' or $self->{'dominant_child'} eq 'bottom';
+	$self->{'dominant_child'} = 1 
+		unless $self->{'dominant_child'} eq 1 or $self->{'dominant_child'} eq 2;
 
 
-	$self->{'position'} = exists $parameter->{'position'} ? $parameter->{'position'} : 0;
+	$self->{'position'} = 0 unless exists $self->{'position'};
+	$self->{'position'} = $parameter->{'pos'}      if exists $parameter->{'pos'};
+	$self->{'position'} = $parameter->{'position'} if exists $parameter->{'position'};
+
+
+	$self->{'min_size'} = 70 unless exists $self->{'min_size'};
+	$self->{'min_size'} = $parameter->{'min'}      if exists $parameter->{'min'};
+	$self->{'min_size'} = $parameter->{'min_size'} if exists $parameter->{'min_size'};
+	$self->SetMinimumPaneSize( $self->{'min_size'} );
 
 
 	$self->{'gravity'} = $parameter->{'gravity'} if exists $parameter->{'gravity'};
 		if not exists $self->{'child1'} or not $self->{'child1'}
 		or not exists $self->{'child2'} or not $self->{'child2'}
 		or exists $parameter->{'split'} and $parameter->{'split'} eq 'no';
-	$self->resplit();
+
+
+	if ($self->{'child2'}) { $self->resplit()                       }
+	else                   { $self->Initialize( $self->{'child1'} ) }
 }
 
 # call only if children or other property changes
 sub resplit {
 	my $self = shift;
 	return if $self->IsSplit;
-	return Kephra::Log::error("can't split without two child widgets")
-		unless $self->{'child1'} and $self->{'child2'};
+	return Kephra::Log::error("need at least one child", 0) unless $self->{'child1'};
+	return Kephra::Log::warning("need a second child", 0) unless $self->{'child2'};
 	if ($self->GetSplitMode eq &Wx::wxSPLIT_HORIZONTAL){
 		$self->SplitHorizontally( $self->{'child1'}, $self->{'child2'}, $self->{'position'} )
 	} else { 

File lib/Kephra/App/Window.pm

-use strict;
+use v5.10;
 use warnings;
 use Wx;
 use Kephra::API;
 use Kephra::App::Part::TreeLib;
 use Kephra::App::Part::OrgPad;
 use Kephra::App::Part::ScratchSheet;
+use Kephra::App::Panel;
+use Kephra::App::Splitter;
 
 
 package Kephra::App::Window;
 
 	# container var for all panel, sizer and splitter
 	my (%panel, %sizer, %splitter, %gui_part);
-	$splitter{'left'}  = Wx::SplitterWindow->new( $self,             -1 );
-	$splitter{'right'} = Wx::SplitterWindow->new( $splitter{'left'}, -1 );
-	$splitter{'below'} = Wx::SplitterWindow->new( $splitter{'right'},-1 );
-	$panel   {'above'} = Wx::Panel         ->new( $splitter{'below'});
-	$splitter{'edit'}  = Wx::SplitterWindow->new( $panel   {'above'},-1 );
 
-	for my $name (qw /left right above below edit/) {
-		$panel{ $name } = Wx::Panel->new( $splitter{ $name } ) unless $name eq 'above';
-		$sizer{ $name } = Wx::BoxSizer->new( &Wx::wxHORIZONTAL );
-		$sizer{ $name } = Wx::BoxSizer->new( &Wx::wxVERTICAL ) if $name eq 'above'
-															   or $name eq 'below';
+	for my $name (qw /left right above below/) {
+		$splitter{$name} = Kephra::App::Splitter->new( ) unless $name eq 'above';
+		$panel{ $name } = Wx::Panel->new( $self );
+		$sizer{ $name } = ($name eq 'above' or $name eq 'below')
+			? Wx::BoxSizer->new( &Wx::wxVERTICAL )
+			: Wx::BoxSizer->new( &Wx::wxHORIZONTAL );
 		$panel{ $name }->SetSizer( $sizer{ $name } );
 	}
+
+	$splitter{'left'}->set({
+		left => $panel{'left'},   right => $splitter{'right'}, parent  => $self,
+		dominant_child => 'right',  pos => 250,    min => 200
+	});
+	$splitter{'right'}->set({
+		left => $splitter{'below'}, right => $panel{'right'}, parent  => $splitter{'left'},
+		dominant_child => 'left',     pos => -200, min => 140
+	});
+	$splitter{'below'}->set({
+		top => $panel{'above'},    bottom => $panel{'below'}, parent  => $splitter{'right'},
+		dominant_child => 'top',      pos => -200, min => 100
+	});
+
+
 	$self->{'part'} = \%gui_part;
-	$gui_part{'editor'}      = Kephra::App::Part::Editor   ->new( $panel{'edit'} );
+	$gui_part{'editor'}      = Kephra::App::Part::Editor   ->new( $panel{'above'} );
 	$gui_part{'searchbar'}   = Kephra::App::Bar::Search    ->new( $panel{'above'} );
 	$gui_part{'iounit'}      = Kephra::App::Part::IOUnit   ->new( $panel{'below'} );
 	$gui_part{'filebrowser'} = Kephra::App::Part::FileBrowser->new($panel{'left'} );
 	#my $scratchsheet    = Kephra::App::Part::ScratchSheet->new( $panel{'right'} );
 	$gui_part{'statusbar'}   = Kephra::App::Bar::Status    ->new( $self );
 
-	$splitter{'left'}->SplitVertically( $panel{'left'}, $splitter{'right'}, 200);
-	$splitter{'left'}->SetSashGravity(0);
-	$splitter{'left'}->SetSashPosition(200);
-	$splitter{'left'}->SetMinimumPaneSize(140);
-	$splitter{'right'}->SplitVertically( $splitter{'below'}, $panel{'right'}, -200);
-	$splitter{'right'}->SetSashGravity(1);
-	$splitter{'right'}->SetSashPosition(-200);
-	$splitter{'right'}->SetMinimumPaneSize(140);
-	$splitter{'below'}->SplitHorizontally( $panel{'above'}, $panel{'below'}, -200);
-	$splitter{'below'}->SetSashGravity(1);
-	$splitter{'below'}->SetSashPosition(-200);
-	$splitter{'below'}->SetMinimumPaneSize(100);
-	$splitter{'edit'}->Initialize( $panel{'edit'} );
-
-	$sizer{'edit'} ->Add( $gui_part{'editor'},     1, &Wx::wxGROW );
-	$sizer{'above'}->Add( $splitter{'edit'},       1, &Wx::wxGROW );
+	$sizer{'above'}->Add( $gui_part{'editor'},     1, &Wx::wxGROW );
 	$sizer{'above'}->Add( $gui_part{'searchbar'},  0, &Wx::wxGROW );
 	$sizer{'below'}->Add( $gui_part{'iounit'},     1, &Wx::wxGROW );
 	$sizer{'right'}->Add( $gui_part{'treelib'},    1, &Wx::wxGROW );
 	$sizer{'main'}->Add( $gui_part{'statusbar'},  0, &Wx::wxGROW);
 	$self->SetSizer( $sizer{'main'} );
 
+
 	$self->SetMenuBar( Kephra::App::Bar::Menu::get() );
 	$self->GetMenuBar->SetAcceleratorTable( Wx::AcceleratorTable->new() );