ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.231 by root, Thu May 25 00:26:19 2006 UTC vs.
Revision 1.245 by elmex, Sat May 27 21:15:57 2006 UTC

5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8 8
9use CFClient; 9use CFClient;
10use CFClient::Texture;
10 11
11our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
12 13
14our $LAYOUT;
13our $ROOT; 15our $ROOT;
14our $TOOLTIP; 16our $TOOLTIP;
15our $BUTTON_STATE; 17our $BUTTON_STATE;
16 18
17our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
20
21sub get_layout {
22 for (grep { $_->{name} } values %WIDGET) {
23 $LAYOUT->{$_->{name}} = {
24 x => $_->{x} / $::WIDTH,
25 y => $_->{y} / $::HEIGHT,
26 w => $_->{w} / $::WIDTH,
27 h => $_->{h} / $::HEIGHT
28 };
29 }
30
31 return $LAYOUT;
32}
33
34sub set_layout {
35 my ($layout) = @_;
36 $LAYOUT = $layout;
37}
18 38
19sub check_tooltip { 39sub check_tooltip {
20 if (!$GRAB) { 40 if (!$GRAB) {
21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
22 if (length $widget->{tooltip}) { 42 if (length $widget->{tooltip}) {
186 can_events => 1, 206 can_events => 1,
187 @_ 207 @_
188 }, $class; 208 }, $class;
189 209
190 for (keys %$self) { 210 for (keys %$self) {
191 if (/^connect_(.*)$/) { 211 if (/^on_(.*)$/) {
192 $self->connect ($1 => delete $self->{$_}); 212 $self->connect ($1 => delete $self->{$_});
193 } 213 }
194 } 214 }
195 215
196 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); 216 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
197 217
218 if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) {
219 $self->{user_x} = $layout->{x} * $::WIDTH;
220 $self->{user_y} = $layout->{y} * $::HEIGHT;
221 $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH;
222 $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT;
223 }
224
198 $self 225 $self
226}
227
228sub toggle_visibility {
229 my ($self) = @_;
230
231 if ($self->{visible}) {
232 $self->hide;
233 } else {
234 $self->show;
235 }
199} 236}
200 237
201sub destroy { 238sub destroy {
202 my ($self) = @_; 239 my ($self) = @_;
203 240
226} 263}
227 264
228sub set_invisible { 265sub set_invisible {
229 my ($self) = @_; 266 my ($self) = @_;
230 267
268 return unless $self->{visible};
269
231 # broken show/hide model 270 # broken show/hide model
232 271
272 delete $self->{root};
233 delete $self->{visible}; 273 delete $self->{visible};
234 274
235 undef $GRAB if $GRAB == $self; 275 undef $GRAB if $GRAB == $self;
236 undef $HOVER if $HOVER == $self; 276 undef $HOVER if $HOVER == $self;
237 277
278 CFClient::UI::check_tooltip
279 if $CFClient::UI::TOOLTIP->{owner} == $self;
280
238 $self->focus_out; 281 $self->focus_out;
282
283 $self->emit (visibility_change => 0);
239} 284}
240 285
241sub hide { 286sub hide {
242 my ($self) = @_; 287 my ($self) = @_;
243 288
318 delete $self->{max_h}; $self->{max_h} = $h if $h; 363 delete $self->{max_h}; $self->{max_h} = $h if $h;
319} 364}
320 365
321sub set_tooltip { 366sub set_tooltip {
322 my ($self, $tooltip) = @_; 367 my ($self, $tooltip) = @_;
368
369 $tooltip =~ s/^\s+//;
370 $tooltip =~ s/\s+$//;
371
372 return if $self->{tooltip} eq $tooltip;
323 373
324 $self->{tooltip} = $tooltip; 374 $self->{tooltip} = $tooltip;
325 375
326 if ($CFClient::UI::TOOLTIP->{owner} == $self) { 376 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
327 delete $CFClient::UI::TOOLTIP->{owner}; 377 delete $CFClient::UI::TOOLTIP->{owner};
417 if ($ENV{PCLIENT_DEBUG}) { 467 if ($ENV{PCLIENT_DEBUG}) {
418 glPushMatrix; 468 glPushMatrix;
419 glColor 1, 1, 0, 1; 469 glColor 1, 1, 0, 1;
420 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 470 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
421 glBegin GL_LINE_LOOP; 471 glBegin GL_LINE_LOOP;
422 glVertex 0 , 0; 472 glVertex 0 , 0;
423 glVertex $self->{w}, 0; 473 glVertex $self->{w} - 1, 0;
424 glVertex $self->{w}, $self->{h}; 474 glVertex $self->{w} - 1, $self->{h} - 1;
425 glVertex 0 , $self->{h}; 475 glVertex 0 , $self->{h} - 1;
426 glEnd; 476 glEnd;
427 glPopMatrix; 477 glPopMatrix;
428 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 478 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
429 } 479 }
430} 480}
450sub set_parent { 500sub set_parent {
451 my ($self, $parent) = @_; 501 my ($self, $parent) = @_;
452 502
453 Scalar::Util::weaken ($self->{parent} = $parent); 503 Scalar::Util::weaken ($self->{parent} = $parent);
454 504
505 if ($parent->{visible} || 1) {
506 $self->{root} = $parent->{root};
507 $self->{visible} = $parent->{visible} + 1;
508
509 $self->emit (visibility_change => 1)
510 unless $self->{parent}{visible};
511 }
512
455 # TODO: req_w _does_change after ->reconfigure 513 # TODO: req_w _does_change after ->reconfigure
456 $self->check_size 514 $self->check_size
457 unless exists $self->{req_w}; 515 unless exists $self->{req_w};
458 516
459 $self->show; 517 $self->show;
488sub emit { 546sub emit {
489 my ($self, $signal, @args) = @_; 547 my ($self, $signal, @args) = @_;
490 548
491 $self->_emit ($signal, @args) 549 $self->_emit ($signal, @args)
492 || $self->$signal (@args); 550 || $self->$signal (@args);
551}
552
553sub visibility_change {
554 #my ($self, $visible) = @_;
493} 555}
494 556
495sub DESTROY { 557sub DESTROY {
496 my ($self) = @_; 558 my ($self) = @_;
497 559
610 delete $child->{parent}; 672 delete $child->{parent};
611 $child->hide; 673 $child->hide;
612 674
613 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 675 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
614 676
615 $self->check_size; 677 $self->check_size (1);
616 $self->update; 678 $self->update;
617} 679}
618 680
619sub clear { 681sub clear {
620 my ($self) = @_; 682 my ($self) = @_;
760 822
761package CFClient::UI::ViewPort; 823package CFClient::UI::ViewPort;
762 824
763our @ISA = CFClient::UI::Window::; 825our @ISA = CFClient::UI::Window::;
764 826
827sub new {
828 my $class = shift;
829
830 $class->SUPER::new (
831 scroll_x => 0,
832 scroll_y => 1,
833 @_,
834 )
835}
836
765sub size_request { 837sub size_request {
766 my ($self) = @_; 838 my ($self) = @_;
767 839
768 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 840 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
769 841
771} 843}
772 844
773sub size_allocate { 845sub size_allocate {
774 my ($self, $w, $h) = @_; 846 my ($self, $w, $h) = @_;
775 847
776 my ($cw, $ch) = @$self{qw(child_w child_h)}; 848 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w};
777# $w = $self->{w}; 849 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h};
850
778 $self->child->configure (0, 0, $cw, $ch); 851 $self->child->configure (0, 0, $w, $h);
779 $self->update; 852 $self->update;
780} 853}
781 854
782sub set_offset { 855sub set_offset {
783 my ($self, $x, $y) = @_; 856 my ($self, $x, $y) = @_;
834 my $class = shift; 907 my $class = shift;
835 908
836 my $self; 909 my $self;
837 910
838 my $slider = new CFClient::UI::Slider 911 my $slider = new CFClient::UI::Slider
839 vertical => 1, 912 vertical => 1,
840 range => [0, 0, 1, 0.01], # HACK fix 913 range => [0, 0, 1, 0.01], # HACK fix
841 connect_changed => sub { 914 on_changed => sub {
842 $self->{vp}->set_offset (0, $_[1]); 915 $self->{vp}->set_offset (0, $_[1]);
843 }, 916 },
844 ; 917 ;
845 918
846 $self = $class->SUPER::new ( 919 $self = $class->SUPER::new (
852 $self->{vp}->add ($self->{scrolled}); 925 $self->{vp}->add ($self->{scrolled});
853 $self->add ($self->{vp}); 926 $self->add ($self->{vp});
854 $self->add ($self->{slider}); 927 $self->add ($self->{slider});
855 928
856 $self 929 $self
930}
931
932sub update {
933 my ($self) = @_;
934
935 $self->SUPER::update;
936
937 # todo: overwrite size_allocate of child
938 my $child = $self->{vp}->child;
939 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
857} 940}
858 941
859sub size_allocate { 942sub size_allocate {
860 my ($self, $w, $h) = @_; 943 my ($self, $w, $h) = @_;
861 944
991 my ($ev, $x, $y) = @_; 1074 my ($ev, $x, $y) = @_;
992 1075
993 my $dx = $ev->{x} - $ox; 1076 my $dx = $ev->{x} - $ox;
994 my $dy = $ev->{y} - $oy; 1077 my $dy = $ev->{y} - $oy;
995 1078
1079 $self->{user_x} = $wx + $dx * $mx;
1080 $self->{user_y} = $wy + $dy * $my;
996 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); 1081 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
997 $self->{user_h} = $bh + $dy * ($my ? -1 : 1); 1082 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
998 $self->move ($wx + $dx * $mx, $wy + $dy * $my); 1083 $self->move ($self->{user_x}, $self->{user_y});
999 $self->check_size; 1084 $self->check_size;
1000 }; 1085 };
1001 1086
1002 } elsif ($lr ^ $td) { 1087 } elsif ($lr ^ $td) {
1003 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1088 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1006 $self->{motion} = sub { 1091 $self->{motion} = sub {
1007 my ($ev, $x, $y) = @_; 1092 my ($ev, $x, $y) = @_;
1008 1093
1009 ($x, $y) = ($ev->{x}, $ev->{y}); 1094 ($x, $y) = ($ev->{x}, $ev->{y});
1010 1095
1011 $self->move ($bx + $x - $ox, $by + $y - $oy); 1096 $self->{user_x} = $bx + $x - $ox;
1097 $self->{user_y} = $by + $y - $oy;
1098 $self->move ($self->{user_x}, $self->{user_y});
1012 $self->update; 1099 $self->update;
1013 }; 1100 };
1014 } 1101 }
1015} 1102}
1016 1103
1078sub new { 1165sub new {
1079 my $class = shift; 1166 my $class = shift;
1080 1167
1081 $class->SUPER::new ( 1168 $class->SUPER::new (
1082 col_expand => [], 1169 col_expand => [],
1083 @_ 1170 @_,
1084 ) 1171 )
1172}
1173
1174sub children {
1175 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1085} 1176}
1086 1177
1087sub add { 1178sub add {
1088 my ($self, $x, $y, $child) = @_; 1179 my ($self, $x, $y, $child) = @_;
1089 1180
1090 $child->set_parent ($self); 1181 $child->set_parent ($self);
1091 $self->{children}[$y][$x] = $child; 1182 $self->{children}[$y][$x] = $child;
1092 1183
1093 $child->check_size; 1184 $self->check_size (1);
1094} 1185}
1095 1186
1096sub children {
1097 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1098}
1099
1100# TODO: move to container class maybe? send childs a signal on removal? 1187# TODO: move to container class maybe? send children a signal on removal?
1101sub clear { 1188sub clear {
1102 my ($self) = @_; 1189 my ($self) = @_;
1103 1190
1104 my @children = $self->children; 1191 my @children = $self->children;
1105 delete $self->{children}; 1192 delete $self->{children};
1107 for (@children) { 1194 for (@children) {
1108 delete $_->{parent}; 1195 delete $_->{parent};
1109 $_->hide; 1196 $_->hide;
1110 } 1197 }
1111 1198
1199 $self->check_size (1);
1112 $self->update; 1200 $self->update;
1113} 1201}
1114 1202
1115sub get_wh { 1203sub get_wh {
1116 my ($self) = @_; 1204 my ($self) = @_;
1148sub size_allocate { 1236sub size_allocate {
1149 my ($self, $w, $h) = @_; 1237 my ($self, $w, $h) = @_;
1150 1238
1151 my ($ws, $hs) = $self->get_wh; 1239 my ($ws, $hs) = $self->get_wh;
1152 1240
1153 my $req_w = sum @$ws; 1241 my $req_w = (sum @$ws) || 1;
1154 my $req_h = sum @$hs; 1242 my $req_h = (sum @$hs) || 1;
1155 1243
1156 # TODO: nicer code && do row_expand 1244 # TODO: nicer code && do row_expand
1157 my @col_expand = @{$self->{col_expand}}; 1245 my @col_expand = @{$self->{col_expand}};
1158 @col_expand = (1) x @$ws unless @col_expand; 1246 @col_expand = (1) x @$ws unless @col_expand;
1159 my $col_expand = (sum @col_expand) || 1; 1247 my $col_expand = (sum @col_expand) || 1;
1562 my ($self) = @_; 1650 my ($self) = @_;
1563 1651
1564 my ($w, $h) = $self->SUPER::size_request; 1652 my ($w, $h) = $self->SUPER::size_request;
1565 1653
1566 ($w + 1, $h) # add 1 for cursor 1654 ($w + 1, $h) # add 1 for cursor
1567}
1568
1569sub size_allocate {
1570 my ($self, $w, $h) = @_;
1571
1572 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1573} 1655}
1574 1656
1575sub key_down { 1657sub key_down {
1576 my ($self, $ev) = @_; 1658 my ($self, $ev) = @_;
1577 1659
2119} 2201}
2120 2202
2121sub set_range { 2203sub set_range {
2122 my ($self, $range) = @_; 2204 my ($self, $range) = @_;
2123 2205
2124 $self->{range} = $range; 2206 ($range, $self->{range}) = ($self->{range}, $range);
2125 2207
2126 $self->update; 2208 $self->update
2209 if "@$range" ne "@{$self->{range}}";
2127} 2210}
2128 2211
2129sub set_value { 2212sub set_value {
2130 my ($self, $value) = @_; 2213 my ($self, $value) = @_;
2131 2214
2514 2597
2515sub new { 2598sub new {
2516 my $class = shift; 2599 my $class = shift;
2517 2600
2518 my $self = $class->SUPER::new ( 2601 my $self = $class->SUPER::new (
2519 state => 0, 2602 state => 0,
2520 connect_activate => \&toggle_flopper, 2603 on_activate => \&toggle_flopper,
2521 @_ 2604 @_
2522 ); 2605 );
2523 2606
2524 if ($self->{state}) {
2525 $self->{state} = 0;
2526 $self->toggle_flopper;
2527 }
2528
2529 $self 2607 $self
2530} 2608}
2531 2609
2532sub toggle_flopper { 2610sub toggle_flopper {
2533 my ($self) = @_; 2611 my ($self) = @_;
2534 2612
2535 # TODO: use animation 2613 $self->{other}->toggle_visibility;
2536 if ($self->{state} = !$self->{state}) {
2537 $CFClient::UI::ROOT->add ($self->{other});
2538 $self->{other}->move ($self->coord2global (0, $self->{h}));
2539 $self->_emit ("open");
2540 } else {
2541 $CFClient::UI::ROOT->remove ($self->{other});
2542 $self->_emit ("close");
2543 }
2544
2545 $self->_emit (changed => $self->{state});
2546} 2614}
2547 2615
2548############################################################################# 2616#############################################################################
2549 2617
2550package CFClient::UI::Tooltip; 2618package CFClient::UI::Tooltip;
2626 2694
2627sub new { 2695sub new {
2628 my $class = shift; 2696 my $class = shift;
2629 2697
2630 my $self = $class->SUPER::new ( 2698 my $self = $class->SUPER::new (
2631 aspect => 1, 2699 aspect => 1,
2700 can_events => 0,
2632 @_, 2701 @_,
2633 ); 2702 );
2634 2703
2635 if ($self->{anim} && $self->{animspeed}) { 2704 if ($self->{anim} && $self->{animspeed}) {
2636 Scalar::Util::weaken (my $widget = $self); 2705 Scalar::Util::weaken (my $widget = $self);
2695 $self->SUPER::DESTROY; 2764 $self->SUPER::DESTROY;
2696} 2765}
2697 2766
2698############################################################################# 2767#############################################################################
2699 2768
2700package CFClient::UI::InventoryItem; 2769package CFClient::UI::Inventory;
2701 2770
2702our @ISA = CFClient::UI::HBox::; 2771our @ISA = CFClient::UI::ScrolledWindow::;
2703
2704sub _item_to_desc {
2705 my ($item) = @_;
2706
2707 my $desc =
2708 $item->{nrof} < 2
2709 ? $item->{name}
2710 : "$item->{nrof} × $item->{name_pl}";
2711
2712 $item->{flags} & Crossfire::Protocol::F_OPEN
2713 and $desc .= " (open)";
2714 $item->{flags} & Crossfire::Protocol::F_APPLIED
2715 and $desc .= " (applied)";
2716 $item->{flags} & Crossfire::Protocol::F_UNPAID
2717 and $desc .= " (unpaid)";
2718 $item->{flags} & Crossfire::Protocol::F_MAGIC
2719 and $desc .= " (magic)";
2720 $item->{flags} & Crossfire::Protocol::F_CURSED
2721 and $desc .= " (cursed)";
2722 $item->{flags} & Crossfire::Protocol::F_DAMNED
2723 and $desc .= " (damned)";
2724 $item->{flags} & Crossfire::Protocol::F_LOCKED
2725 and $desc .= " *";
2726
2727 $desc
2728}
2729 2772
2730sub new { 2773sub new {
2731 my $class = shift; 2774 my $class = shift;
2732 2775
2733 my %args = @_;
2734
2735 my $item = delete $args{item};
2736
2737 my $desc = _item_to_desc ($item);
2738
2739 my $self = $class->SUPER::new ( 2776 my $self = $class->SUPER::new (
2740 can_hover => 1,
2741 can_events => 1,
2742 tooltip => ((CFClient::UI::Label::escape $desc)
2743 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2744 connect_button_down => sub {
2745 my ($self, $ev, $x, $y) = @_;
2746
2747 # todo: maybe put examine on 1? but should just be a tooltip :(
2748 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2749 my $targ = $::CONN->{player}{tag};
2750
2751 if ($item->{container} == $::CONN->{player}{tag}) {
2752 $targ = $main::OPENCONT;
2753 }
2754
2755 $::CONN->send ("move $targ $item->{tag} 0");
2756 } elsif ($ev->{button} == 1) {
2757 $::CONN->send ("examine $item->{tag}");
2758 } elsif ($ev->{button} == 2) {
2759 $::CONN->send ("apply $item->{tag}");
2760 } elsif ($ev->{button} == 3) {
2761 my @menu_items = (
2762 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2763 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2764 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2765 (
2766 $item->{flags} & Crossfire::Protocol::F_LOCKED
2767 ? (
2768 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2769 )
2770 : (
2771 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2772 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2773 )
2774 ),
2775 );
2776
2777 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2778 }
2779
2780 1
2781 },
2782 %args
2783 );
2784
2785
2786 $self->add (new CFClient::UI::Face
2787 can_events => 0,
2788 face => $item->{face},
2789 anim => $item->{anim},
2790 animspeed => $item->{animspeed},
2791 );
2792
2793 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2794
2795 $self->{item} = $item;
2796
2797 $self->update_item;
2798
2799 $self
2800}
2801
2802sub update_item {
2803 my ($self) = @_;
2804
2805 my $desc = _item_to_desc ($self->{item});
2806
2807 $self->{name_lbl}->set_text ($desc);
2808}
2809
2810#############################################################################
2811
2812package CFClient::UI::Inventory;
2813
2814our @ISA = CFClient::UI::ScrolledWindow::;
2815
2816sub new {
2817 my $class = shift;
2818
2819 my $self = $class->SUPER::new (
2820 scrolled => (new CFClient::UI::Table), 2777 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2821 @_, 2778 @_,
2822 ); 2779 );
2823 2780
2824 $self 2781 $self
2825} 2782}
2835 or ($a->{name} cmp $b->{name}) 2792 or ($a->{name} cmp $b->{name})
2836 } @$items; 2793 } @$items;
2837 2794
2838 $self->{real_items} = \@items; 2795 $self->{real_items} = \@items;
2839 2796
2797 my $row = 0;
2840 for my $item (@items) { 2798 for my $item (@items) {
2841 $item->{item} = $item; 2799 CFClient::Item::update_widgets $item;
2842 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2843 $item->update_item ();
2844 }
2845 2800
2846 my $i = 0; 2801 $self->{scrolled}->add (0, $row, $item->{face_widget});
2847 for (@items) { 2802 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2848 $self->{scrolled}->add (0, $i, $_); 2803 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2849 my $nrof = $_->{item}->{nrof} || 1;
2850 $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000);
2851 }
2852 2804
2853# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2805 $row++;
2806 }
2854} 2807}
2855 2808
2856sub size_request { 2809sub size_request {
2857 my ($self) = @_; 2810 my ($self) = @_;
2858 ($self->{req_w}, $self->{req_h}); 2811 ($self->{req_w}, $self->{req_h});
2995sub add { 2948sub add {
2996 my ($self, $text, %arg) = @_; 2949 my ($self, $text, %arg) = @_;
2997 2950
2998 $text =~ s/^\s+//; 2951 $text =~ s/^\s+//;
2999 $text =~ s/\s+$//; 2952 $text =~ s/\s+$//;
2953
2954 return unless $text;
3000 2955
3001 my $timeout = time + ((delete $arg{timeout}) || 60); 2956 my $timeout = time + ((delete $arg{timeout}) || 60);
3002 2957
3003 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2958 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3004 2959
3048 3003
3049sub new { 3004sub new {
3050 my $class = shift; 3005 my $class = shift;
3051 3006
3052 $class->SUPER::new ( 3007 $class->SUPER::new (
3008 visible => 1,
3053 @_, 3009 @_,
3054 ) 3010 )
3055} 3011}
3056 3012
3057sub configure { 3013sub configure {
3084 if exists $child->{req_x}; 3040 if exists $child->{req_x};
3085 3041
3086 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 3042 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
3087 if exists $child->{req_y}; 3043 if exists $child->{req_y};
3088 3044
3045 $X = $self->{user_x} if exists $self->{user_x};
3046 $Y = $self->{user_y} if exists $self->{user_y};
3047
3089 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; 3048 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
3090 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; 3049 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
3091 3050
3092 $child->configure ($X, $Y, $W, $H); 3051 $child->configure ($X, $Y, $W, $H);
3093 } 3052 }
3115sub add { 3074sub add {
3116 my ($self, @children) = @_; 3075 my ($self, @children) = @_;
3117 3076
3118 for (my @widgets = @children; my $w = pop @widgets; ) { 3077 for (my @widgets = @children; my $w = pop @widgets; ) {
3119 push @widgets, $w->children; 3078 push @widgets, $w->children;
3120 $w->{root} = $self; 3079 $w->{root} = $self;
3121 $w->{visible} = 1; 3080 $w->{visible} = $self->{visible} + 1;
3122 } 3081 }
3123 3082
3124 for my $child (@children) { 3083 for my $child (@children) {
3125 $child->{is_toplevel} = 1; 3084 $child->{is_toplevel} = 1;
3126 3085
3163 $_->() 3122 $_->()
3164 for values %{delete $self->{refresh_hook}}; 3123 for values %{delete $self->{refresh_hook}};
3165 } 3124 }
3166 3125
3167 if ($self->{check_size}) { 3126 if ($self->{check_size}) {
3168 my @queue = ([], []); 3127 my @queue;
3169 3128
3170 for (;;) { 3129 for (;;) {
3171 if ($self->{check_size}) { 3130 if ($self->{check_size}) {
3172 # heuristic: check containers last 3131 #TODO use array-of-depth approach
3173 push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_ 3132
3133 @queue = sort { $a->{visible} <=> $b->{visible} }
3174 for values %{delete $self->{check_size}} 3134 @queue, values %{delete $self->{check_size}};
3175 } 3135 }
3176 3136
3177 my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last; 3137 my $widget = pop @queue || last;
3138
3139 defined $widget->{visible} or last; # do not resize invisible widgets
3178 3140
3179 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 3141 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
3180 ? @$widget{qw(user_w user_h)} 3142 ? @$widget{qw(user_w user_h)}
3181 : $widget->size_request; 3143 : $widget->size_request;
3182 3144

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines