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