Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #39 from finanalyst/master
get-active method to combobox
  • Loading branch information
jonathanstowe committed May 28, 2016
2 parents 61e6b37 + 1f7c486 commit 30ec795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/06-combo.pl6
Expand Up @@ -25,19 +25,22 @@ $combo.changed.tap({
=comment preset the active item.
my $pre-set-combo = GTK::Simple::ComboBoxText.new();
my @items = <zero one two three four five six>;
my @items = <alpha beta gamma delta epsilon zeta eta theta>;

for @items -> $item {
$pre-set-combo.append-text( $item )
}

$pre-set-combo.set-active( 3 );
my $index = 4;
$pre-set-combo.set-active( $index );
=comment
If the index is 0 > index > @item.end then nothing happens.

my $lbl2 = GTK::Simple::Label.new( text => @items[3] );
my $lbl2 = GTK::Simple::Label.new( text => @items[$index] );

$pre-set-combo.changed.tap: { $lbl2.text = $pre-set-combo.active-text(); };
$pre-set-combo.changed.tap: {
$lbl2.text = 'ComboBoxText has selection ' ~ $pre-set-combo.active-text() ~ ', which has index ' ~ $pre-set-combo.get-active();
};


$app.set-content(GTK::Simple::VBox.new($label, $combo, $lbl2, $pre-set-combo));
Expand Down
4 changes: 4 additions & 0 deletions lib/GTK/Simple/ComboBoxText.pm6
Expand Up @@ -49,6 +49,10 @@ method set-active( $index ) {
gtk_combo_box_set_active($!gtk_widget,$index)
}

method get-active() returns Int {
gtk_combo_box_get_active($!gtk_widget)
}

has $!changed_supply;
method changed() {
$!changed_supply //= do {
Expand Down
6 changes: 6 additions & 0 deletions lib/GTK/Simple/Raw.pm6
Expand Up @@ -290,6 +290,12 @@ sub gtk_combo_box_set_active(GtkWidget $widget, int32 $index)
is export(:combo-box-text)
{ * }

sub gtk_combo_box_get_active(GtkWidget $widget)
is native(&gtk-lib)
is export(:combo-box-text)
returns int32
{ * }

sub gtk_combo_box_text_get_active_text(GtkWidget $widget)
is native(&gtk-lib)
is export(:combo-box-text)
Expand Down

0 comments on commit 30ec795

Please sign in to comment.