Skip to content

Commit

Permalink
- Addresses a bit of #40 if rerun several times. Fix still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Xliff committed Nov 6, 2019
1 parent a407189 commit 821c850
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 31 deletions.
32 changes: 23 additions & 9 deletions lib/GTK/Container.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use GTK::Compat::Types;
use GTK::Raw::Container;
use GTK::Raw::Subs;
use GTK::Raw::Types;
use GTK::Raw::Utils;

use GTK::Adjustment;
use GTK::Widget;

use GTK::Roles::LatchedContents;

our subset ContainerAncestry is export where GtkContainer | WidgetAncestry;
our subset ContainerAncestry is export
where GtkContainer | WidgetAncestry;

class GTK::Container is GTK::Widget {
also does GTK::Roles::LatchedContents;
Expand Down Expand Up @@ -163,7 +165,8 @@ D
Str() $prop,
Int $val is rw
) {
my guint $v = self.RESOLVE-BOOL($val);
my guint $v = resolve-bool($val);

# CArray[guint]?
gtk_container_child_get_uint($!c, $child, $prop, $v, Str);
$val = $v;
Expand All @@ -176,7 +179,8 @@ D
)
is also<child_set_bool>
{
my guint $v = self.RESOLVE-BOOL($val);
my guint $v = resolve-bool($val);

gtk_container_child_set_uint($!c, $child, $prop, $v, Str);
}

Expand All @@ -193,7 +197,8 @@ D
Str() $prop,
Int $val is rw
) {
my guint $v = self.RESOLVE-INT($val);
my guint $v = resolve-int($val);

# CArray[guint]?
gtk_container_child_get_int($!c, $child, $prop, $v, Str);
$val = $v
Expand All @@ -206,7 +211,8 @@ D
)
is also<child_set_int>
{
my gint $v = self.RESOLVE-INT($val);
my gint $v = resolve-int($val);

gtk_container_child_set_int($!c, $child, $prop, $v, Str);
}

Expand All @@ -223,7 +229,8 @@ D
Str() $prop,
Int $val is rw
) {
my guint $v = self.RESOLVE-UINT($val);
my guint $v = resolve-uint($val);

# CArray[guint]?
gtk_container_child_get_uint($!c, $child, $prop, $v, Str);
$val = $v;
Expand All @@ -236,7 +243,8 @@ D
)
is also<child_set_uint>
{
my gint $v = self.RESOLVE-UINT($val);
my gint $v = resolve-uint($val);

gtk_container_child_set_uint($!c, $child, $prop, $v, Str);
}

Expand Down Expand Up @@ -303,18 +311,23 @@ D
gtk_container_get_border_width($!c);
},
STORE => sub ($, Int() $border_width is copy) {
my $bw = self.RESOLVE-UINT($border_width);
my $bw = resolve-uint($border_width);

gtk_container_set_border_width($!c, $bw);
}
);
}

multi method add (GTK::Widget $widget) {
say 'Container object add';

@!end.push: $widget;
self.SET-LATCH;
samewith($widget.Widget);
}
multi method add (GtkWidget $widget) {
say 'Container pointer add';

@!end.push: $widget unless self.IS-LATCHED;
self.UNSET-LATCH;
gtk_container_add($!c, $widget);
Expand Down Expand Up @@ -464,7 +477,8 @@ D
method set_reallocate_redraws (Int() $needs_redraws)
is also<set-reallocate-redraws>
{
my gboolean $nr = self.RESOLVE-BOOL($needs_redraws);
my gboolean $nr = resolve-bool($needs_redraws);

gtk_container_set_reallocate_redraws($!c, $nr);
}

Expand Down
67 changes: 45 additions & 22 deletions lib/GTK/FlowBox.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ use NativeCall;

use GTK::Compat::GList;
use GTK::Compat::Types;
use GTK::Raw::FlowBox;
use GTK::Raw::Types;

use GTK::Raw::Utils;
use GTK::Raw::FlowBox;

use GTK::FlowBoxChild;
use GTK::Container;
use GTK::Widget;

use GTK::Roles::Orientable;
use GTK::Roles::Signals::FlowBox;

our subset FlowBoxAncestry is export
where GtkFlowBox | GtkOrientable | ContainerAncestry;

class GTK::FlowBox is GTK::Container {
also does GTK::Roles::Orientable;
also does GTK::Roles::Signals::FlowBox;

has GtkFlowBox $!fb;

Expand Down Expand Up @@ -58,8 +62,10 @@ class GTK::FlowBox is GTK::Container {
}
}
}

method GTK::Raw::Types::GtkFlowBox is also<FlowBox> { $!fb }

method GTK::Raw::Types::GtkFlowBox
is also<FlowBox>
{ $!fb }

multi method new (FlowBoxAncestry $flowbox) {
my $o = self.bless(:$flowbox);
Expand Down Expand Up @@ -122,7 +128,8 @@ class GTK::FlowBox is GTK::Container {
so gtk_flow_box_get_activate_on_single_click($!fb);
},
STORE => sub ($, Int() $single is copy) {
my gboolean $s = self.RESOLVE-BOOL($single);
my gboolean $s = resolve-bool($single);

gtk_flow_box_set_activate_on_single_click($!fb, $s);
}
);
Expand All @@ -134,7 +141,8 @@ class GTK::FlowBox is GTK::Container {
gtk_flow_box_get_column_spacing($!fb);
},
STORE => sub ($, Int() $spacing is copy) {
my gint $s = self.RESOLVE-INT($spacing);
my gint $s = resolve-int($spacing);

gtk_flow_box_set_column_spacing($!fb, $s);
}
);
Expand All @@ -146,7 +154,8 @@ class GTK::FlowBox is GTK::Container {
so gtk_flow_box_get_homogeneous($!fb);
},
STORE => sub ($, Int() $homogeneous is copy) {
my gboolean $h = self.RESOLVE-BOOL($homogeneous);
my gboolean $h = resolve-bool($homogeneous);

gtk_flow_box_set_homogeneous($!fb, $h);
}
);
Expand All @@ -158,7 +167,8 @@ class GTK::FlowBox is GTK::Container {
gtk_flow_box_get_max_children_per_line($!fb);
},
STORE => sub ($, Int() $n_children is copy) {
my gint $n = self.RESOLVE-INT($n_children);
my gint $n = resolve-int($n_children);

gtk_flow_box_set_max_children_per_line($!fb, $n);
}
);
Expand All @@ -170,7 +180,8 @@ class GTK::FlowBox is GTK::Container {
gtk_flow_box_get_min_children_per_line($!fb);
},
STORE => sub ($, Int() $n_children is copy) {
my gint $n = self.RESOLVE-INT($n_children);
my gint $n = resolve-int($n_children);

gtk_flow_box_set_min_children_per_line($!fb, $n);
}
);
Expand All @@ -182,7 +193,8 @@ class GTK::FlowBox is GTK::Container {
gtk_flow_box_get_row_spacing($!fb);
},
STORE => sub ($, Int() $spacing is copy) {
my gint $s = self.RESOLVE-INT($spacing);
my gint $s = resolve-int($spacing);

gtk_flow_box_set_row_spacing($!fb, $s);
}
);
Expand All @@ -194,7 +206,8 @@ class GTK::FlowBox is GTK::Container {
GtkSelectionMode( gtk_flow_box_get_selection_mode($!fb) );
},
STORE => sub ($, Int() $mode is copy) {
my uint32 $m = self.RESOLVE-UINT($mode);
my uint32 $m = resolve-uint($mode);

gtk_flow_box_set_selection_mode($!fb, $m);
}
);
Expand All @@ -217,6 +230,7 @@ class GTK::FlowBox is GTK::Container {

# Override.
method add($widget) {
say 'Flowbox add';
my $adding = do given $widget {
when GTK::FlowBoxChild { $_ }

Expand Down Expand Up @@ -262,10 +276,10 @@ class GTK::FlowBox is GTK::Container {

# ↓↓↓↓ METHODS ↓↓↓↓
multi method bind_model (
GListModel $model,
GListModel() $model,
GtkFlowBoxCreateWidgetFunc $create_widget_func,
gpointer $user_data,
GDestroyNotify $user_data_free_func
gpointer $user_data = gpointer,
GDestroyNotify $user_data_free_func = gpointer
)
is also<bind-model>
{
Expand All @@ -275,18 +289,23 @@ class GTK::FlowBox is GTK::Container {
}

method get_child_at_index (Int() $idx) is also<get-child-at-index> {
my gint $i = self.RESOLVE-INT($idx);
my gint $i = resolve-int($idx);
self.end[$idx];
# GTK::FlowBoxChild.new(
# gtk_flow_box_get_child_at_index($!fb, $i)
# );
}

method get_child_at_pos (Int() $x, Int() $y) is also<get-child-at-pos> {
my gint ($xx, $yy) = self.RESOLVE-INT($x, $y);
GTK::FlowBoxChild.new(
gtk_flow_box_get_child_at_pos($!fb, $xx, $yy)
);
method get_child_at_pos (Int() $x, Int() $y, :$raw = False)
is also<get-child-at-pos>
{
my gint ($xx, $yy) = resolve-int($x, $y);
my $fbc = gtk_flow_box_get_child_at_pos($!fb, $xx, $yy);

$fbc ??
( $raw ?? $fbc !! GTK::FlowBoxChild.new($fbc) )
!!
Nil;
}

method get_selected_children is also<get-selected-children> {
Expand All @@ -296,10 +315,12 @@ class GTK::FlowBox is GTK::Container {

method get_type is also<get-type> {
state ($n, $t);

GTK::Widget.unstable_get_type( &gtk_flow_box_get_type, $n, $t );
}

method insert ($widget, Int() $position) {
my gint $p = resolve-int($position);
my $inserting = do given $widget {
when GTK::FlowBoxChild { $_ }

Expand All @@ -315,9 +336,9 @@ class GTK::FlowBox is GTK::Container {
.^name }";
}
};

%!child-manifest{ +.get-child.Widget.p } = $_ given $inserting;
self.insert-end-at($inserting, $position);
my gint $p = self.RESOLVE-INT($position);
gtk_flow_box_insert($!fb, $inserting, $p);
}

Expand All @@ -334,7 +355,8 @@ class GTK::FlowBox is GTK::Container {
}

method select_child ($child) is also<select-child> {
my $to-be-selected = self!resolve-selected-child;
my $to-be-selected = self.resolve-selected-child($child);

This comment has been minimized.

Copy link
@hythm7

hythm7 Nov 6, 2019

Collaborator

This is a typo I guess, it should be self!resolve-selected-child since the method has !. also line 417.

This comment has been minimized.

Copy link
@Xliff

Xliff Nov 6, 2019

Author Owner

It's been fixed in master, so no problem!

This comment has been minimized.

Copy link
@hythm7

hythm7 Nov 7, 2019

Collaborator

may be I didn't explain well what I mean or I'm missing something, the method !resolve-selected-child is defined as a private method, however it's called with . in lines 358 and 417. also I get method not found error if ran #41 script. (on master).


gtk_flow_box_select_child($!fb, $to-be-selected);
}

Expand Down Expand Up @@ -392,7 +414,8 @@ class GTK::FlowBox is GTK::Container {
method unselect_child (GtkFlowBoxChild() $child)
is also<unselect-child>
{
my $to-be-unselected = self!resolve-selected-child;
my $to-be-unselected = self.resolve-selected-child($child);

gtk_flow_box_unselect_child($!fb, $to-be-unselected);
}
# ↑↑↑↑ METHODS ↑↑↑↑
Expand Down
24 changes: 24 additions & 0 deletions t/0392-issue_40.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env perl6

use GTK::Application;
use GTK::FlowBox;
use GTK::Label;

GTK::Application.new;

my $str = q:to/END/; # Reducing number of children by removing one line from $str fix the issue
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
END

my $flowbox = GTK::FlowBox.new;

for $str.words.join.comb -> $sym {
say $sym;
$flowbox.add: GTK::Label.new: $sym;
}

0 comments on commit 821c850

Please sign in to comment.