… | |
… | |
215 | #$self->deactivate; |
215 | #$self->deactivate; |
216 | } |
216 | } |
217 | |
217 | |
218 | ############################################################################# |
218 | ############################################################################# |
219 | |
219 | |
|
|
220 | package CFClient::Widget::Empty; |
|
|
221 | |
|
|
222 | our @ISA = CFClient::Widget::; |
|
|
223 | |
|
|
224 | sub size_request { |
|
|
225 | (0, 0) |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub draw { } |
|
|
229 | |
|
|
230 | ############################################################################# |
|
|
231 | |
220 | package CFClient::Widget::Container; |
232 | package CFClient::Widget::Container; |
221 | |
233 | |
222 | our @ISA = CFClient::Widget::; |
234 | our @ISA = CFClient::Widget::; |
223 | |
235 | |
224 | sub new { |
236 | sub new { |
… | |
… | |
236 | my ($self, $chld, $expand) = @_; |
248 | my ($self, $chld, $expand) = @_; |
237 | |
249 | |
238 | $chld->{expand} = $expand; |
250 | $chld->{expand} = $expand; |
239 | $chld->set_parent ($self); |
251 | $chld->set_parent ($self); |
240 | |
252 | |
241 | @{$self->{children}} = |
253 | $self->{children} = [ |
242 | sort { $a->{z} <=> $b->{z} } |
254 | sort { $a->{z} <=> $b->{z} } |
243 | @{$self->{children}}, $chld; |
255 | @{$self->{children}}, $chld |
|
|
256 | ]; |
244 | |
257 | |
245 | $self->size_allocate ($self->{w}, $self->{h}) |
258 | $self->size_allocate ($self->{w}, $self->{h}) |
246 | if $self->{w}; #TODO: check for "realised state" |
259 | if $self->{w}; #TODO: check for "realised state" |
247 | } |
260 | } |
248 | |
261 | |
… | |
… | |
279 | ############################################################################# |
292 | ############################################################################# |
280 | |
293 | |
281 | package CFClient::Widget::Bin; |
294 | package CFClient::Widget::Bin; |
282 | |
295 | |
283 | our @ISA = CFClient::Widget::Container::; |
296 | our @ISA = CFClient::Widget::Container::; |
|
|
297 | |
|
|
298 | sub new { |
|
|
299 | my ($class, %arg) = @_; |
|
|
300 | |
|
|
301 | my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; |
|
|
302 | |
|
|
303 | $class->SUPER::new (children => [$child], %arg) |
|
|
304 | } |
|
|
305 | |
|
|
306 | sub add { |
|
|
307 | my ($self, $widget) = @_; |
|
|
308 | |
|
|
309 | $self->{children} = []; |
|
|
310 | |
|
|
311 | $self->SUPER::add ($widget); |
|
|
312 | } |
|
|
313 | |
|
|
314 | sub remove { |
|
|
315 | my ($self, $widget) = @_; |
|
|
316 | |
|
|
317 | $self->SUPER::remove ($widget); |
|
|
318 | |
|
|
319 | $self->{children} = [new CFClient::Widget::Empty] |
|
|
320 | unless @{$self->{children}}; |
|
|
321 | } |
284 | |
322 | |
285 | sub child { $_[0]->{children}[0] } |
323 | sub child { $_[0]->{children}[0] } |
286 | |
324 | |
287 | sub size_request { |
325 | sub size_request { |
288 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
326 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
… | |
… | |
438 | $w -= $tex[3]->{width}; |
476 | $w -= $tex[3]->{width}; |
439 | |
477 | |
440 | $h = $h < 0 ? 0 : $h; |
478 | $h = $h < 0 ? 0 : $h; |
441 | $w = $w < 0 ? 0 : $w; |
479 | $w = $w < 0 ? 0 : $w; |
442 | |
480 | |
|
|
481 | my $child = $self->child; |
|
|
482 | |
443 | $self->child->size_allocate ($w, $h); |
483 | $child->size_allocate ($w, $h); |
444 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
484 | $child->move ($tex[3]->{width}, $tex[1]->{height}); |
445 | } |
485 | } |
446 | |
486 | |
447 | sub _draw { |
487 | sub _draw { |
448 | my ($self) = @_; |
488 | my ($self) = @_; |
449 | |
489 | |