Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
unit classization
  • Loading branch information
azawawi committed Jun 3, 2016
1 parent ab0cccd commit 2205667
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 62 deletions.
42 changes: 19 additions & 23 deletions lib/GTK/Simple/MenuToolButton.pm6
Expand Up @@ -4,31 +4,27 @@ use NativeCall;
use GTK::Simple::Raw :toolbar, :DEFAULT;
use GTK::Simple::Widget;

class GTK::Simple::MenuToolButton
does GTK::Simple::Widget
{
has $!clicked_supply;
unit class GTK::Simple::MenuToolButton does GTK::Simple::Widget;

submethod BUILD(:$icon) {
if $icon {
$!gtk_widget = gtk_tool_button_new_from_stock($icon);
} else {
$!gtk_widget = gtk_toolbar_new;
}
$!gtk_widget;
}
has $!clicked_supply;

method clicked() {
$!clicked_supply //= do {
my $s = Supplier.new;
g_signal_connect_wd($!gtk_widget, "clicked",
-> $, $ {
$s.emit(self);
CATCH { default { note $_; } }
},
OpaquePointer, 0);
$s.Supply;
}
submethod BUILD(:$icon) {
if $icon {
$!gtk_widget = gtk_tool_button_new_from_stock($icon);
} else {
$!gtk_widget = gtk_toolbar_new;
}
}

method clicked() {
$!clicked_supply //= do {
my $s = Supplier.new;
g_signal_connect_wd($!gtk_widget, "clicked",
-> $, $ {
$s.emit(self);
CATCH { default { note $_; } }
},
OpaquePointer, 0);
$s.Supply;
}
}
75 changes: 36 additions & 39 deletions lib/GTK/Simple/Toolbar.pm6
Expand Up @@ -5,44 +5,41 @@ use GTK::Simple::VBox;
use GTK::Simple::Widget;
use GTK::Simple::MenuToolButton;

class GTK::Simple::Toolbar
does GTK::Simple::Widget
{
has $!item-count = 0;

enum GtkToolbarStyle is export (
GTK_TOOLBAR_ICONS => 0,
GTK_TOOLBAR_TEXT => 1,
GTK_TOOLBAR_BOTH => 2,
GTK_TOOLBAR_BOTH_HORIZ => 3,
);

constant GTK_STOCK_NEW is export = "gtk-new";
constant GTK_STOCK_OPEN is export = "gtk-open";
constant GTK_STOCK_SAVE is export = "gtk-save";
constant GTK_STOCK_QUIT is export = "gtk-quit";

submethod BUILD(GtkToolbarStyle :$style = GTK_TOOLBAR_ICONS) {
$!gtk_widget = gtk_toolbar_new;
gtk_toolbar_set_style($!gtk_widget, $style);
}

method add-menu-item(GTK::Simple::MenuToolButton $button) {
gtk_toolbar_insert($!gtk_widget, $button.WIDGET, -1);
$!item-count++;
}

method add-separator() {
my $sep = gtk_separator_tool_item_new;
gtk_toolbar_insert($!gtk_widget, $sep, -1);
$!item-count++;
$sep;
}

method pack() {
my $vbox = GTK::Simple::VBox.new;
gtk_box_pack_start($vbox.WIDGET, $!gtk_widget, 0, 0, $!item-count);
$vbox;
}
unit class GTK::Simple::Toolbar does GTK::Simple::Widget;

has $!item-count = 0;

enum GtkToolbarStyle is export (
GTK_TOOLBAR_ICONS => 0,
GTK_TOOLBAR_TEXT => 1,
GTK_TOOLBAR_BOTH => 2,
GTK_TOOLBAR_BOTH_HORIZ => 3,
);

constant GTK_STOCK_NEW is export = "gtk-new";
constant GTK_STOCK_OPEN is export = "gtk-open";
constant GTK_STOCK_SAVE is export = "gtk-save";
constant GTK_STOCK_QUIT is export = "gtk-quit";

submethod BUILD(GtkToolbarStyle :$style = GTK_TOOLBAR_ICONS) {
$!gtk_widget = gtk_toolbar_new;
gtk_toolbar_set_style($!gtk_widget, $style);
}

method add-menu-item(GTK::Simple::MenuToolButton $button) {
gtk_toolbar_insert($!gtk_widget, $button.WIDGET, -1);
$!item-count++;
}

method add-separator() {
my $sep = gtk_separator_tool_item_new;
gtk_toolbar_insert($!gtk_widget, $sep, -1);
$!item-count++;
$sep;
}

method pack() {
my $vbox = GTK::Simple::VBox.new;
gtk_box_pack_start($vbox.WIDGET, $!gtk_widget, 0, 0, $!item-count);
$vbox;
}

0 comments on commit 2205667

Please sign in to comment.