Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a403ec7
commit 949481f
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
use v6.c; | ||
use lib 'lib'; | ||
use GTK::Simple; | ||
|
||
my $app = GTK::Simple::App.new(title=> 'Example 18'); | ||
|
||
# my $some-text = GTK::Simple::ScrolledWindow.new; | ||
my $t = GTK::Simple::TextView.new; | ||
$t.text ~= [~] gather for ^25 { take ' ' x $_ ~ "the quick brown fox jumps over the lazy dog\n" }; | ||
# $some-text.set-content( $t ); | ||
|
||
# my $more-text = GTK::Simple::ScrolledWindow.new; | ||
my $u = GTK::Simple::TextView.new; | ||
$u.text ~= [~] gather for ^25 { take ' ' x (25 - $_) ~ "Twas brillig and the slithy toothes did gyre and gymbol\n" }; | ||
# $more-text.set-content( $u ) ; | ||
|
||
# my $exit-b = GTK::Simple::ToggleButton.new(label=>'Exit'); | ||
# | ||
my $h-paned = GTK::Simple::Paned.new(:orientation(1)); | ||
# my $v-paned = GTK::Simple::Paned.new(:orientation<vertical>); | ||
|
||
=comment | ||
C<orientation> may only take the values 'horizontal' (default) or 'vertical' | ||
The standard GTK-3 Pane has two pack functions (pack1 and pack2) | ||
These are kept, but an additional helper C<set-contents> function combines them | ||
(Note the extra 's'). | ||
Each of the two panes have two presentation options, called C<shrink> and C<resize>. | ||
C<shrink> = True (default) allows the pane to go smaller than the minimum widget size | ||
C<shrink> = False sets a minimum size defined by the contained widget | ||
C<resize> = True (default) allows the pane to be resized (expanded or contracted) | ||
C<resize> = False freezes the pane to the initial size request of the contained widget. | ||
For C<set-contents> these are shrink-a, shrink-b, resize-a, resize-b. | ||
The widget associated with C<pack1> and C<a> in C<set-contents> is placed in the left pane for horizontal | ||
orientation, and the top pane for the vertical orientation. | ||
|
||
# $h-paned.set-contents( :a($some-text), :b($more-text) ); | ||
# $v-paned.set-contents( :b($some-text), :a($more-text), :resize-a(False), :shrink-b(False)); | ||
|
||
=comment | ||
To do the same as the line above using pack1/2 would require | ||
|
||
# $h-paned.pack1($some-text); $h-paned.pack2($more-text); | ||
# $v-paned.pack1($some-text,:resize(False)); $v-paned.pack2($more-text,:shrink(False)); | ||
|
||
$h-paned.add1( $t ); $h-paned.add2( $u ); | ||
$h-paned.set-position(-1); | ||
|
||
# $v-paned.pack1($t,:resize(False)); $v-paned.pack2($u,:shrink(False)); | ||
|
||
# my $v = GTK::Simple::VBox.new( | ||
# $h-paned, | ||
# # $v-paned, | ||
# # $some-text, $more-text, | ||
# $exit-b | ||
# ); | ||
# | ||
# $exit-b.toggled.tap(-> $b { $app.exit } ); | ||
|
||
$app.set-content( $h-paned ); | ||
$app.border-width = 20; | ||
$app.run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use v6; | ||
|
||
use NativeCall; | ||
use GTK::Simple::Raw :paned; | ||
use GTK::Simple::Common; | ||
use GTK::Simple::Widget; | ||
|
||
unit class GTK::Simple::Paned does GTK::Simple::Widget; | ||
|
||
submethod BUILD(:$orientation = 0) { | ||
self.WIDGET( gtk_paned_new( $orientation ) ); | ||
} | ||
# submethod BUILD( :$orientation where { $orientation eq one('horizontal', 'vertical') } = 'horizontal') { | ||
# self.WIDGET( gtk_paned_new( $orientation eq 'horizontal' ?? 0 !! 1 ) ); | ||
# } | ||
|
||
method add1( GTK::Simple::Widget $child ) { | ||
gtk_paned_add1(self.WIDGET, $child.WIDGET ); | ||
# gtk_paned_set_position( self.WIDGET ); | ||
} | ||
|
||
method add2( GTK::Simple::Widget $child ) { | ||
gtk_paned_add2(self.WIDGET, $child.WIDGET ); | ||
# gtk_paned_set_position( self.WIDGET ); | ||
} | ||
|
||
method pack1( GTK::Simple::Widget $child, Bool :$resize = True, Bool :$shrink = True ) { | ||
gtk_paned_pack1(self.WIDGET, $child.WIDGET, $resize, $shrink ); | ||
} | ||
|
||
method pack2( GTK::Simple::Widget $child, Bool :$resize = True, Bool :$shrink = True ) { | ||
gtk_paned_pack2(self.WIDGET, $child.WIDGET, $resize, $shrink ); | ||
} | ||
|
||
method set-contents( | ||
GTK::Simple::Widget :$a!, GTK::Simple::Widget :$b!, | ||
Bool :$shrink-a = True, Bool :$resize-a = True, | ||
Bool :$shrink-b = True, Bool :$resize-b = True) { | ||
gtk_paned_pack1(self.WIDGET, $a.WIDGET, $resize-a, $shrink-a ); | ||
gtk_paned_pack2(self.WIDGET, $b.WIDGET, $resize-b, $shrink-b ); | ||
} | ||
method set-position( int $position ) { | ||
gtk_paned_set_position( self.WIDGET, $position ) | ||
} |