Commits

Herbert Breunung  committed bd10ee7

made sizer ready for recursive structures

  • Participants
  • Parent commits 3f9bae0

Comments (0)

Files changed (1)

File lib/Kephra/App/Sizer.pm

 use strict;
 use warnings;
-use Scalar::Util qw(blessed looks_like_number);
 use Kephra::API;
 use Kephra::App::Util;
 
-
-
 package Kephra::App::Sizer;
 our @ISA = 'Wx::Sizer';
 my ($is_widget, $is_sizer) = Kephra::App::Util::get('is_widget', 'is_sizer');
+use Scalar::Util qw(blessed looks_like_number);
 
 
 sub new {
 
 # syntax sugar for insert method, unless insert can take list of child items
 # all these methods are ment to be chained, thatswhy the $self at the end
-sub before {
+sub prepend         { shift->insert(  0, 0, @_ ) }
+sub append          { shift->insert( -1, 0, @_ ) }
+sub append_expanded { shift->insert( -1, 1, @_ ) }
+sub insert_before   {
 	my ($self) = shift;
 	my ($mark_child) = shift;
 	my $pos = $self->get_position($mark_child);
 	return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
 	$self->insert($pos, 0, @_);
-	$self;
 }
-sub after {
+sub insert_after   {
 	my ($self) = shift;
 	my ($mark_child) = shift;
 	my $pos = $self->get_position($mark_child);
 	return Kephra::Log::error("bookmark child $mark_child not found", 1) unless $pos > -1;
 	$self->insert($pos+1, 0, @_);
-	$self;
 }
-sub prepend         { my ($self) = shift; $self->insert(  0, 0, @_ ); $self }
-sub append          { my ($self) = shift; $self->insert( -1, 0, @_ ); $self }
-sub append_expanded { my ($self) = shift; $self->insert( -1, 1, @_ ); $self }
 sub insert          {
 	my ($self) = shift;
 	my ($position) = shift;
-	my ($proportion) = shift;
+	my ($proportion)  = shift;
 	for (@_) {
 		$self->_insert( $self->_build_item($position, $proportion, $_) );
 		$position++ unless $position == -1;
 	$item->{'position'};
 }
 
-sub show     {$_[0]->_relayout( sub { $_[0]->Show(   $_[1], 1) }, @_); $_[0] }
-sub hide     {$_[0]->_relayout( sub { $_[0]->Hide(   $_[1] ) },   @_); $_[0] }
-sub detach   {$_[0]->_relayout( sub { $_[0]->Detach( $_[1] ) },   @_); $_[0] }
-sub remove   {$_[0]->_relayout( sub { $_[0]->Remove( $_[1] ) },   @_); $_[0] } # del spacer & sizer
+
+
+sub show     {$_[0]->_relayout( sub { $_[0]->Show(   $_[1], 1) }, @_) }
+sub hide     {$_[0]->_relayout( sub { $_[0]->Hide(   $_[1] ) },   @_) }
+sub detach   {$_[0]->_relayout( sub { $_[0]->Detach( $_[1] ) },   @_) }
+sub remove   {$_[0]->_relayout( sub { $_[0]->Remove( $_[1] ) },   @_) } # del spacer & sizer
 sub _relayout{
 	my ($self, $child, $call) = @_;
 	return Kephra::Log::error('need a coderef, not $call', 2) unless ref $call eq 'CODE';
 	my $pos = 0;
 	if ($is_widget->($child)){
 		for ($self->GetChildren){
-			return $pos if $_->GetWindow and $_->GetWindow eq $child;
+			return $pos if $_->IsWindow and $_->GetWindow eq $child;
 			$pos++;
 		}
 	}
 	elsif ($is_sizer->($child)){
 		for ($self->GetChildren){
-			return $pos if $_->GetSizer and $_->GetSizer eq $child;
+			return $pos if $_->IsSizer and $_->GetSizer eq $child;
 			$pos++;
 		}
 	} 
 	return -1;
 }
 sub is_child       { $_[0]->get_position( $_[1] ) > -1 ? 1 : 0 }
-sub get_child_item { $_[0]->GetItem($_[1]) }       # child with that number
-sub get_children   { 
+sub child_item { $_[0]->GetItem($_[1]) }       # child with that number
+sub childsizer { 
 	my ($self) = shift;
+	my @sizer;
+	for ($self->GetChildren){ push @sizer, $_->GetSizer if $_->IsSizer }
+	@sizer;
+}
+sub widgets    {
+	my ($self) = shift;
+	my @widgets;
+	for ($self->GetChildren){ push @widgets, $_->GetWindow if $_->IsWindow }
+	@widgets;
+}
 
-}
-sub get_widgets    { 
-	my ($self) = shift;
-
-}
-sub get_childsizer { 
-	my ($self) = shift;
-
+sub sizer_items  { shift->_items( sub{ $_[0]->IsSizer  } ) }
+sub space_items  { shift->_items( sub{ $_[0]->IsSpacer } ) }
+sub widget_items { shift->_items( sub{ $_[0]->IsWindow } ) }
+sub _items       {
+	my ($self, $check) = @_;
+	return Kephra::Log::error("no checker coderef as first parameter, only $check", 1);
+	my @item;
+	for ($self->GetChildren){ push @item, $_ if $check->($_) }
+	@item;
 }
 
 1;