… | |
… | |
175 | for my $widget (values %WIDGET) { |
175 | for my $widget (values %WIDGET) { |
176 | if ($widget->{is_toplevel}) { |
176 | if ($widget->{is_toplevel}) { |
177 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
177 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
178 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
178 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
179 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
179 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
180 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
181 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
180 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
182 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
181 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
182 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
184 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
185 | } |
183 | } |
186 | } |
184 | } |
187 | |
185 | |
188 | reconfigure_widgets; |
186 | reconfigure_widgets; |
189 | } |
187 | } |
… | |
… | |
214 | } |
212 | } |
215 | |
213 | |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
214 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
217 | |
215 | |
218 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
216 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
219 | $self->{user_x} = $layout->{x} * $::WIDTH; |
217 | $self->{req_x} = $layout->{x} * $::WIDTH; |
220 | $self->{user_y} = $layout->{y} * $::HEIGHT; |
218 | $self->{req_y} = $layout->{y} * $::HEIGHT; |
221 | $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
219 | $self->{def_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
222 | $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
220 | $self->{def_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
223 | } |
221 | } |
224 | |
222 | |
225 | $self |
223 | $self |
226 | } |
224 | } |
227 | |
225 | |
… | |
… | |
232 | %$self = (); |
230 | %$self = (); |
233 | } |
231 | } |
234 | |
232 | |
235 | sub show { |
233 | sub show { |
236 | my ($self) = @_; |
234 | my ($self) = @_; |
|
|
235 | |
237 | return if $self->{parent}; |
236 | return if $self->{parent}; |
238 | |
237 | |
239 | $CFClient::UI::ROOT->add ($self); |
238 | $CFClient::UI::ROOT->add ($self); |
240 | } |
239 | } |
241 | |
240 | |
242 | sub show_centered { |
241 | sub center { |
243 | my ($self) = @_; |
242 | my ($self) = @_; |
244 | return if $self->{parent}; |
|
|
245 | |
|
|
246 | $self->show; |
|
|
247 | |
243 | |
248 | $CFClient::UI::ROOT->on_post_alloc ( |
244 | $CFClient::UI::ROOT->on_post_alloc ( |
249 | "centered $self" => sub { |
245 | "center_$self" => sub { |
250 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
246 | $self->move (($self->{parent}{w} - $self->{w}) * 0.5, ($self->{parent}{h} - $self->{h}) * 0.5); |
251 | }, |
247 | }, |
252 | ); |
248 | ); |
|
|
249 | |
|
|
250 | $self->update; |
|
|
251 | } |
|
|
252 | |
|
|
253 | sub set_visible { |
|
|
254 | my ($self) = @_; |
|
|
255 | |
|
|
256 | return if $self->{visible}; |
|
|
257 | |
|
|
258 | $self->{root} = $self->{parent}{root}; |
|
|
259 | $self->{visible} = $self->{parent}{visible} + 1; |
|
|
260 | |
|
|
261 | $self->emit (visibility_change => 1); |
253 | } |
262 | } |
254 | |
263 | |
255 | sub set_invisible { |
264 | sub set_invisible { |
256 | my ($self) = @_; |
265 | my ($self) = @_; |
257 | |
266 | |
… | |
… | |
269 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
278 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
270 | |
279 | |
271 | $self->focus_out; |
280 | $self->focus_out; |
272 | |
281 | |
273 | $self->emit (visibility_change => 0); |
282 | $self->emit (visibility_change => 0); |
|
|
283 | } |
|
|
284 | |
|
|
285 | sub set_visibility { |
|
|
286 | my ($self, $visible) = @_; |
|
|
287 | |
|
|
288 | return if $self->{visible} == $visible; |
|
|
289 | |
|
|
290 | $visible ? $self->hide |
|
|
291 | : $self->show; |
|
|
292 | } |
|
|
293 | |
|
|
294 | sub toggle_visibility { |
|
|
295 | my ($self) = @_; |
|
|
296 | |
|
|
297 | $self->{visible} |
|
|
298 | ? $self->hide |
|
|
299 | : $self->show; |
274 | } |
300 | } |
275 | |
301 | |
276 | sub hide { |
302 | sub hide { |
277 | my ($self) = @_; |
303 | my ($self) = @_; |
278 | |
304 | |
… | |
… | |
293 | } |
319 | } |
294 | |
320 | |
295 | sub set_size { |
321 | sub set_size { |
296 | my ($self, $w, $h) = @_; |
322 | my ($self, $w, $h) = @_; |
297 | |
323 | |
298 | $self->{user_w} = $w; |
324 | $self->{def_w} = $w; |
299 | $self->{user_h} = $h; |
325 | $self->{def_h} = $h; |
300 | |
326 | |
301 | $self->check_size; |
327 | $self->check_size; |
302 | } |
328 | } |
303 | |
329 | |
304 | sub size_request { |
330 | sub size_request { |
… | |
… | |
326 | $self->{y} = $y; |
352 | $self->{y} = $y; |
327 | $self->update; |
353 | $self->update; |
328 | } |
354 | } |
329 | |
355 | |
330 | if ($self->{w} != $w || $self->{h} != $h) { |
356 | if ($self->{w} != $w || $self->{h} != $h) { |
331 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h]; |
357 | $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h]; |
332 | } |
358 | } |
333 | } |
359 | } |
334 | |
360 | |
335 | sub size_allocate { |
361 | sub size_allocate { |
336 | # nothing to be done |
362 | # nothing to be done |
… | |
… | |
490 | sub set_parent { |
516 | sub set_parent { |
491 | my ($self, $parent) = @_; |
517 | my ($self, $parent) = @_; |
492 | |
518 | |
493 | Scalar::Util::weaken ($self->{parent} = $parent); |
519 | Scalar::Util::weaken ($self->{parent} = $parent); |
494 | |
520 | |
495 | if ($parent->{visible} || 1) { |
521 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
496 | $self->{root} = $parent->{root}; |
|
|
497 | $self->{visible} = $parent->{visible} + 1; |
|
|
498 | |
522 | |
499 | $self->emit (visibility_change => 1) |
|
|
500 | unless $self->{parent}{visible}; |
|
|
501 | } |
|
|
502 | |
|
|
503 | # TODO: req_w _does_change after ->reconfigure |
|
|
504 | $self->check_size |
523 | $self->check_size; |
505 | unless exists $self->{req_w}; |
|
|
506 | |
|
|
507 | $self->show; |
|
|
508 | } |
524 | } |
509 | |
525 | |
510 | sub check_size { |
526 | sub check_size { |
511 | my ($self, $forced) = @_; |
527 | my ($self, $forced) = @_; |
512 | |
528 | |
… | |
… | |
825 | } |
841 | } |
826 | |
842 | |
827 | sub size_request { |
843 | sub size_request { |
828 | my ($self) = @_; |
844 | my ($self) = @_; |
829 | |
845 | |
830 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
846 | my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
831 | |
847 | |
832 | @$self{qw(child_w child_h)} |
848 | $w = 10 if $self->{scroll_x}; |
|
|
849 | $h = 10 if $self->{scroll_y}; |
|
|
850 | |
|
|
851 | ($w, $h) |
833 | } |
852 | } |
834 | |
853 | |
835 | sub size_allocate { |
854 | sub size_allocate { |
836 | my ($self, $w, $h) = @_; |
855 | my ($self, $w, $h) = @_; |
837 | |
856 | |
… | |
… | |
993 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1012 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
994 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1013 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
995 | |
1014 | |
996 | sub new { |
1015 | sub new { |
997 | my $class = shift; |
1016 | my $class = shift; |
998 | |
|
|
999 | # TODO: user_x, user_y, overwrite moveto? |
|
|
1000 | |
1017 | |
1001 | my $self = $class->SUPER::new ( |
1018 | my $self = $class->SUPER::new ( |
1002 | bg => [1, 1, 1, 1], |
1019 | bg => [1, 1, 1, 1], |
1003 | border_bg => [1, 1, 1, 1], |
1020 | border_bg => [1, 1, 1, 1], |
1004 | border => 0.6, |
1021 | border => 0.6, |
… | |
… | |
1066 | my $dx = $ev->{x} - $ox; |
1083 | my $dx = $ev->{x} - $ox; |
1067 | my $dy = $ev->{y} - $oy; |
1084 | my $dy = $ev->{y} - $oy; |
1068 | |
1085 | |
1069 | $self->{user_x} = $wx + $dx * $mx; |
1086 | $self->{user_x} = $wx + $dx * $mx; |
1070 | $self->{user_y} = $wy + $dy * $my; |
1087 | $self->{user_y} = $wy + $dy * $my; |
1071 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
1088 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1072 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
1089 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1073 | $self->move ($self->{user_x}, $self->{user_y}); |
1090 | $self->move ($self->{user_x}, $self->{user_y}); |
1074 | $self->check_size; |
1091 | $self->check_size; |
1075 | }; |
1092 | }; |
1076 | |
1093 | |
1077 | } elsif ($lr ^ $td) { |
1094 | } elsif ($lr ^ $td) { |
… | |
… | |
1083 | |
1100 | |
1084 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1101 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1085 | |
1102 | |
1086 | $self->{user_x} = $bx + $x - $ox; |
1103 | $self->{user_x} = $bx + $x - $ox; |
1087 | $self->{user_y} = $by + $y - $oy; |
1104 | $self->{user_y} = $by + $y - $oy; |
|
|
1105 | |
1088 | $self->move ($self->{user_x}, $self->{user_y}); |
1106 | $self->move ($self->{user_x}, $self->{user_y}); |
1089 | $self->update; |
1107 | $self->update; |
1090 | }; |
1108 | }; |
1091 | } |
1109 | } |
1092 | } |
1110 | } |
… | |
… | |
1291 | } |
1309 | } |
1292 | } |
1310 | } |
1293 | |
1311 | |
1294 | ############################################################################# |
1312 | ############################################################################# |
1295 | |
1313 | |
1296 | package CFClient::UI::HBox; |
1314 | package CFClient::UI::Box; |
1297 | |
|
|
1298 | # TODO: wrap into common Box base class |
|
|
1299 | |
1315 | |
1300 | our @ISA = CFClient::UI::Container::; |
1316 | our @ISA = CFClient::UI::Container::; |
1301 | |
1317 | |
1302 | sub size_request { |
1318 | sub size_request { |
1303 | my ($self) = @_; |
1319 | my ($self) = @_; |
1304 | |
1320 | |
1305 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1321 | $self->{vertical} |
1306 | |
1322 | ? ( |
1307 | ( |
1323 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1308 | (List::Util::sum map $_->[0], @alloc), |
1324 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1309 | (List::Util::max map $_->[1], @alloc), |
1325 | ) |
1310 | ) |
1326 | : ( |
|
|
1327 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
|
|
1328 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
|
|
1329 | ) |
1311 | } |
1330 | } |
1312 | |
1331 | |
1313 | sub size_allocate { |
1332 | sub size_allocate { |
1314 | my ($self, $w, $h) = @_; |
1333 | my ($self, $w, $h) = @_; |
1315 | |
1334 | |
1316 | ($h, $w) = ($w, $h); |
1335 | my $space = $self->{vertical} ? $h : $w; |
1317 | |
|
|
1318 | my $children = $self->{children}; |
1336 | my $children = $self->{children}; |
1319 | |
1337 | |
1320 | my @h = map $_->{req_w}, @$children; |
1338 | my @req; |
1321 | |
1339 | |
1322 | my $req_h = List::Util::sum @h; |
1340 | if ($self->{homogeneous}) { |
1323 | |
1341 | @req = ($space / (@$children || 1)) x @$children; |
1324 | if ($req_h > $h) { |
|
|
1325 | # ah well, not enough space |
|
|
1326 | $_ *= $h / $req_h for @h; |
|
|
1327 | } else { |
1342 | } else { |
|
|
1343 | @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
|
|
1344 | my $req = List::Util::sum @req; |
|
|
1345 | |
|
|
1346 | if ($req > $space) { |
|
|
1347 | # ah well, not enough space |
|
|
1348 | $_ *= $space / $req for @req; |
|
|
1349 | } else { |
1328 | my $exp = List::Util::sum map $_->{expand}, @$children; |
1350 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1329 | $exp ||= 1; |
|
|
1330 | |
1351 | |
|
|
1352 | $space = ($space - $req) / $expand; # remaining space to give away |
|
|
1353 | |
|
|
1354 | $req[$_] += $space * $children->[$_]{expand} |
1331 | for (0 .. $#$children) { |
1355 | for 0 .. $#$children; |
1332 | my $child = $children->[$_]; |
|
|
1333 | |
|
|
1334 | my $alloc_h = $h[$_]; |
|
|
1335 | $alloc_h += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1336 | $h[$_] = $alloc_h; |
|
|
1337 | } |
1356 | } |
1338 | } |
1357 | } |
1339 | |
1358 | |
1340 | CFClient::UI::harmonize \@h; |
1359 | CFClient::UI::harmonize \@req; |
1341 | |
1360 | |
1342 | my $y = 0; |
1361 | my $pos = 0; |
1343 | for (0 .. $#$children) { |
1362 | for (0 .. $#$children) { |
1344 | my $child = $children->[$_]; |
|
|
1345 | my $h = $h[$_]; |
1363 | my $alloc = $req[$_]; |
1346 | $child->configure ($y, 0, $h, $w); |
1364 | $children->[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1347 | |
1365 | |
1348 | $y += $h; |
1366 | $pos += $alloc; |
1349 | } |
1367 | } |
1350 | |
1368 | |
1351 | 1 |
1369 | 1 |
1352 | } |
1370 | } |
1353 | |
1371 | |
1354 | ############################################################################# |
1372 | ############################################################################# |
1355 | |
1373 | |
|
|
1374 | package CFClient::UI::HBox; |
|
|
1375 | |
|
|
1376 | our @ISA = CFClient::UI::Box::; |
|
|
1377 | |
|
|
1378 | sub new { |
|
|
1379 | my $class = shift; |
|
|
1380 | |
|
|
1381 | $class->SUPER::new ( |
|
|
1382 | vertical => 0, |
|
|
1383 | @_, |
|
|
1384 | ) |
|
|
1385 | } |
|
|
1386 | |
|
|
1387 | ############################################################################# |
|
|
1388 | |
1356 | package CFClient::UI::VBox; |
1389 | package CFClient::UI::VBox; |
1357 | |
1390 | |
1358 | # TODO: wrap into common Box base class |
|
|
1359 | |
|
|
1360 | our @ISA = CFClient::UI::Container::; |
1391 | our @ISA = CFClient::UI::Box::; |
1361 | |
1392 | |
1362 | sub size_request { |
1393 | sub new { |
1363 | my ($self) = @_; |
1394 | my $class = shift; |
1364 | |
1395 | |
1365 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1396 | $class->SUPER::new ( |
1366 | |
1397 | vertical => 1, |
1367 | ( |
1398 | @_, |
1368 | (List::Util::max map $_->[0], @alloc), |
|
|
1369 | (List::Util::sum map $_->[1], @alloc), |
|
|
1370 | ) |
1399 | ) |
1371 | } |
|
|
1372 | |
|
|
1373 | sub size_allocate { |
|
|
1374 | my ($self, $w, $h) = @_; |
|
|
1375 | |
|
|
1376 | Carp::confess "negative size" if $w < 0 || $h < 0;#d# |
|
|
1377 | |
|
|
1378 | my $children = $self->{children}; |
|
|
1379 | |
|
|
1380 | my @h = map $_->{req_h}, @$children; |
|
|
1381 | |
|
|
1382 | my $req_h = List::Util::sum @h; |
|
|
1383 | |
|
|
1384 | if ($req_h > $h) { |
|
|
1385 | # ah well, not enough space |
|
|
1386 | $_ *= $h / $req_h for @h; |
|
|
1387 | } else { |
|
|
1388 | my $exp = List::Util::sum map $_->{expand}, @$children; |
|
|
1389 | $exp ||= 1; |
|
|
1390 | |
|
|
1391 | for (0 .. $#$children) { |
|
|
1392 | my $child = $children->[$_]; |
|
|
1393 | |
|
|
1394 | $h[$_] += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1395 | } |
|
|
1396 | } |
|
|
1397 | |
|
|
1398 | CFClient::UI::harmonize \@h; |
|
|
1399 | |
|
|
1400 | my $y = 0; |
|
|
1401 | for (0 .. $#$children) { |
|
|
1402 | my $child = $children->[$_]; |
|
|
1403 | my $h = $h[$_]; |
|
|
1404 | $child->configure (0, $y, $w, $h); |
|
|
1405 | |
|
|
1406 | $y += $h; |
|
|
1407 | } |
|
|
1408 | |
|
|
1409 | 1 |
|
|
1410 | } |
1400 | } |
1411 | |
1401 | |
1412 | ############################################################################# |
1402 | ############################################################################# |
1413 | |
1403 | |
1414 | package CFClient::UI::Label; |
1404 | package CFClient::UI::Label; |
… | |
… | |
2592 | state => 0, |
2582 | state => 0, |
2593 | on_activate => \&toggle_flopper, |
2583 | on_activate => \&toggle_flopper, |
2594 | @_ |
2584 | @_ |
2595 | ); |
2585 | ); |
2596 | |
2586 | |
2597 | if ($self->{state}) { |
|
|
2598 | $self->{state} = 0; |
|
|
2599 | $self->toggle_flopper; |
|
|
2600 | } |
|
|
2601 | |
|
|
2602 | $self |
2587 | $self |
2603 | } |
2588 | } |
2604 | |
2589 | |
2605 | sub toggle_flopper { |
2590 | sub toggle_flopper { |
2606 | my ($self) = @_; |
2591 | my ($self) = @_; |
2607 | |
2592 | |
2608 | # TODO: use animation |
2593 | $self->{other}->toggle_visibility; |
2609 | if ($self->{state} = !$self->{state}) { |
|
|
2610 | $CFClient::UI::ROOT->add ($self->{other}); |
|
|
2611 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
|
|
2612 | $self->_emit ("open"); |
|
|
2613 | } else { |
|
|
2614 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
2615 | $self->_emit ("close"); |
|
|
2616 | } |
|
|
2617 | |
|
|
2618 | $self->_emit (changed => $self->{state}); |
|
|
2619 | } |
2594 | } |
2620 | |
2595 | |
2621 | ############################################################################# |
2596 | ############################################################################# |
2622 | |
2597 | |
2623 | package CFClient::UI::Tooltip; |
2598 | package CFClient::UI::Tooltip; |
… | |
… | |
2807 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2782 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2808 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2783 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2809 | |
2784 | |
2810 | $row++; |
2785 | $row++; |
2811 | } |
2786 | } |
2812 | } |
|
|
2813 | |
|
|
2814 | sub size_request { |
|
|
2815 | my ($self) = @_; |
|
|
2816 | ($self->{req_w}, $self->{req_h}); |
|
|
2817 | } |
2787 | } |
2818 | |
2788 | |
2819 | ############################################################################# |
2789 | ############################################################################# |
2820 | |
2790 | |
2821 | package CFClient::UI::Menu; |
2791 | package CFClient::UI::Menu; |
… | |
… | |
3045 | if exists $child->{req_x}; |
3015 | if exists $child->{req_x}; |
3046 | |
3016 | |
3047 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3017 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3048 | if exists $child->{req_y}; |
3018 | if exists $child->{req_y}; |
3049 | |
3019 | |
3050 | $X = $self->{user_x} if exists $self->{user_x}; |
3020 | #delete @$child{qw(req_x req_y)};#d# def_x, def_y |
3051 | $Y = $self->{user_y} if exists $self->{user_y}; |
|
|
3052 | |
3021 | |
3053 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3022 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3054 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3023 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3055 | |
3024 | |
3056 | $child->configure ($X, $Y, $W, $H); |
3025 | $child->configure ($X, $Y, $W, $H); |
… | |
… | |
3076 | $::WANT_REFRESH++; |
3045 | $::WANT_REFRESH++; |
3077 | } |
3046 | } |
3078 | |
3047 | |
3079 | sub add { |
3048 | sub add { |
3080 | my ($self, @children) = @_; |
3049 | my ($self, @children) = @_; |
3081 | |
|
|
3082 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3083 | push @widgets, $w->children; |
|
|
3084 | $w->{root} = $self; |
|
|
3085 | $w->{visible} = $self->{visible} + 1; |
|
|
3086 | } |
|
|
3087 | |
3050 | |
3088 | for my $child (@children) { |
3051 | for my $child (@children) { |
3089 | $child->{is_toplevel} = 1; |
3052 | $child->{is_toplevel} = 1; |
3090 | |
3053 | |
3091 | # integerise window positions |
3054 | # integerise window positions |
3092 | $child->{x} = int $child->{x}; |
3055 | $child->{x} = int $child->{x}; |
3093 | $child->{y} = int $child->{y}; |
3056 | $child->{y} = int $child->{y}; |
3094 | } |
3057 | } |
3095 | |
3058 | |
3096 | $self->SUPER::add (@children); |
3059 | $self->SUPER::add (@children); |
|
|
3060 | |
|
|
3061 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3062 | push @widgets, $w->children; |
|
|
3063 | $w->set_visible; |
|
|
3064 | } |
|
|
3065 | |
3097 | } |
3066 | } |
3098 | |
3067 | |
3099 | sub remove { |
3068 | sub remove { |
3100 | my ($self, @children) = @_; |
3069 | my ($self, @children) = @_; |
3101 | |
3070 | |
… | |
… | |
3129 | } |
3098 | } |
3130 | |
3099 | |
3131 | if ($self->{check_size}) { |
3100 | if ($self->{check_size}) { |
3132 | my @queue; |
3101 | my @queue; |
3133 | |
3102 | |
3134 | for (;;) { |
3103 | while () { |
3135 | if ($self->{check_size}) { |
3104 | if ($self->{check_size}) { |
3136 | #TODO use array-of-depth approach |
3105 | #TODO use array-of-depth approach |
3137 | |
3106 | |
3138 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3107 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3139 | @queue, values %{delete $self->{check_size}}; |
3108 | @queue, values %{delete $self->{check_size}}; |
… | |
… | |
3141 | |
3110 | |
3142 | my $widget = pop @queue || last; |
3111 | my $widget = pop @queue || last; |
3143 | |
3112 | |
3144 | defined $widget->{visible} or last; # do not resize invisible widgets |
3113 | defined $widget->{visible} or last; # do not resize invisible widgets |
3145 | |
3114 | |
3146 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3115 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3147 | ? @$widget{qw(user_w user_h)} |
3116 | ? @$widget{qw(def_w def_h)} |
3148 | : $widget->size_request; |
3117 | : $widget->size_request; |
3149 | |
3118 | |
3150 | if (delete $widget->{force_alloc} |
3119 | if (delete $widget->{force_alloc} |
3151 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
3120 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
3152 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3121 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
… | |
… | |
3160 | if $widget->{parent}; |
3129 | if $widget->{parent}; |
3161 | } |
3130 | } |
3162 | } |
3131 | } |
3163 | } |
3132 | } |
3164 | |
3133 | |
3165 | while ($self->{size_alloc}) { |
3134 | while (my $size_alloc = delete $self->{size_alloc}) { |
3166 | for (values %{delete $self->{size_alloc}}) { |
3135 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3167 | my ($widget, $w, $h) = @$_; |
3136 | values %$size_alloc; |
|
|
3137 | |
|
|
3138 | while () { |
|
|
3139 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3168 | |
3140 | |
3169 | $w = 0 if $w < 0; |
3141 | $w = 0 if $w < 0; |
3170 | $h = 0 if $h < 0; |
3142 | $h = 0 if $h < 0; |
3171 | |
3143 | |
3172 | $widget->{w} = $w; |
3144 | $widget->{w} = $w; |