… | |
… | |
587 | } |
587 | } |
588 | |
588 | |
589 | sub DESTROY { |
589 | sub DESTROY { |
590 | my ($self) = @_; |
590 | my ($self) = @_; |
591 | |
591 | |
|
|
592 | return if CFClient::in_destruct; |
|
|
593 | |
592 | delete $WIDGET{$self+0}; |
594 | delete $WIDGET{$self+0}; |
593 | |
595 | |
594 | eval { $self->destroy }; |
596 | eval { $self->destroy }; |
595 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
597 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
596 | } |
598 | } |
… | |
… | |
1080 | my $self = $class->SUPER::new ( |
1082 | my $self = $class->SUPER::new ( |
1081 | bg => [1, 1, 1, 1], |
1083 | bg => [1, 1, 1, 1], |
1082 | border_bg => [1, 1, 1, 1], |
1084 | border_bg => [1, 1, 1, 1], |
1083 | border => 0.6, |
1085 | border => 0.6, |
1084 | can_events => 1, |
1086 | can_events => 1, |
1085 | min_w => 16, |
1087 | min_w => 64, |
1086 | min_h => 16, |
1088 | min_h => 32, |
1087 | %arg, |
1089 | %arg, |
1088 | ); |
1090 | ); |
1089 | |
1091 | |
1090 | $self->{title_widget} = new CFClient::UI::Label |
1092 | $self->{title_widget} = new CFClient::UI::Label |
1091 | align => 0, |
1093 | align => 0, |
… | |
… | |
1536 | #font => default_font |
1538 | #font => default_font |
1537 | #text => initial text |
1539 | #text => initial text |
1538 | #markup => initial narkup |
1540 | #markup => initial narkup |
1539 | #max_w => maximum pixel width |
1541 | #max_w => maximum pixel width |
1540 | ellipsise => 3, # end |
1542 | ellipsise => 3, # end |
1541 | layout => (new CFClient::Layout 2), |
1543 | layout => (new CFClient::Layout), |
1542 | fontsize => 1, |
1544 | fontsize => 1, |
1543 | align => -1, |
1545 | align => -1, |
1544 | valign => -1, |
1546 | valign => -1, |
1545 | padding_x => 2, |
1547 | padding_x => 2, |
1546 | padding_y => 2, |
1548 | padding_y => 2, |
1547 | can_events => 0, |
1549 | can_events => 0, |
1548 | %arg |
1550 | %arg |
1549 | ); |
1551 | ); |
1550 | |
1552 | |
1551 | if (exists $self->{template}) { |
1553 | if (exists $self->{template}) { |
1552 | my $layout = new CFClient::Layout 2; |
1554 | my $layout = new CFClient::Layout; |
1553 | $layout->set_text (delete $self->{template}); |
1555 | $layout->set_text (delete $self->{template}); |
1554 | $self->{template} = $layout; |
1556 | $self->{template} = $layout; |
1555 | } |
1557 | } |
1556 | |
1558 | |
1557 | if (exists $self->{markup}) { |
1559 | if (exists $self->{markup}) { |
… | |
… | |
1627 | |
1629 | |
1628 | my ($w, $h) = $self->{layout}->size; |
1630 | my ($w, $h) = $self->{layout}->size; |
1629 | |
1631 | |
1630 | if (exists $self->{template}) { |
1632 | if (exists $self->{template}) { |
1631 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1633 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
|
|
1634 | $self->{template}->set_width ($self->{max_w} || -1); |
1632 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1635 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1633 | |
1636 | |
1634 | my ($w2, $h2) = $self->{template}->size; |
1637 | my ($w2, $h2) = $self->{template}->size; |
1635 | |
1638 | |
1636 | $w = List::Util::max $w, $w2; |
1639 | $w = List::Util::max $w, $w2; |
… | |
… | |
1688 | $self->{layout}->set_width ($self->{w}); |
1691 | $self->{layout}->set_width ($self->{w}); |
1689 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1692 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1690 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1693 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1691 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1694 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1692 | |
1695 | |
1693 | $self->{size_req} |
1696 | [$self->{layout}->size] |
1694 | }; |
1697 | }; |
1695 | |
1698 | |
1696 | unless (exists $self->{ox}) { |
1699 | unless (exists $self->{ox}) { |
1697 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1700 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1698 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
1701 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
… | |
… | |
1825 | |
1828 | |
1826 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
1829 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
1827 | |
1830 | |
1828 | # byte-index to char-index |
1831 | # byte-index to char-index |
1829 | my $text = $self->{text}; |
1832 | my $text = $self->{text}; |
1830 | utf8::encode $text; |
1833 | utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text; |
1831 | $self->{cursor} = length substr $text, 0, $idx; |
1834 | $self->{cursor} = length $text; |
1832 | |
1835 | |
1833 | $self->_set_text ($self->{text}); |
1836 | $self->_set_text ($self->{text}); |
1834 | $self->update; |
1837 | $self->update; |
1835 | |
1838 | |
1836 | 1 |
1839 | 1 |
… | |
… | |
2561 | can_events => 0, |
2564 | can_events => 0, |
2562 | indent => 0, |
2565 | indent => 0, |
2563 | #font => default_font |
2566 | #font => default_font |
2564 | @_, |
2567 | @_, |
2565 | |
2568 | |
2566 | layout => (new CFClient::Layout 2), |
2569 | layout => (new CFClient::Layout), |
2567 | par => [], |
2570 | par => [], |
2568 | height => 0, |
2571 | height => 0, |
2569 | children => [ |
2572 | children => [ |
2570 | (new CFClient::UI::Empty expand => 1), |
2573 | (new CFClient::UI::Empty expand => 1), |
2571 | (new CFClient::UI::Slider vertical => 1), |
2574 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
3813 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
3816 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
3814 | |
3817 | |
3815 | $w = 0 if $w < 0; |
3818 | $w = 0 if $w < 0; |
3816 | $h = 0 if $h < 0; |
3819 | $h = 0 if $h < 0; |
3817 | |
3820 | |
|
|
3821 | $w = max $widget->{min_w}, $w; |
|
|
3822 | $h = max $widget->{min_h}, $h; |
|
|
3823 | |
|
|
3824 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
|
|
3825 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
|
|
3826 | |
3818 | $w = int $w + 0.5; |
3827 | $w = int $w + 0.5; |
3819 | $h = int $h + 0.5; |
3828 | $h = int $h + 0.5; |
3820 | |
3829 | |
3821 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3830 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3822 | $widget->{old_w} = $widget->{w}; |
3831 | $widget->{old_w} = $widget->{w}; |