… | |
… | |
1686 | |
1686 | |
1687 | use List::Util qw(min max); |
1687 | use List::Util qw(min max); |
1688 | |
1688 | |
1689 | our @ISA = CFPlus::UI::Container::; |
1689 | our @ISA = CFPlus::UI::Container::; |
1690 | |
1690 | |
1691 | sub add_fixed { |
|
|
1692 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1693 | |
|
|
1694 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1695 | $self->SUPER::add ($child); |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub _scale($$$) { |
1691 | sub _scale($$$) { |
1699 | my ($mode, $val, $max) = @_; |
1692 | my ($rel, $val, $max) = @_; |
1700 | |
1693 | |
1701 | $mode eq "abs" ? $val |
1694 | $rel ? $val * $max : $val |
1702 | : $mode eq "rel" ? $val * $max |
|
|
1703 | : 0 |
|
|
1704 | } |
1695 | } |
1705 | |
1696 | |
1706 | sub size_request { |
1697 | sub size_request { |
1707 | my ($self) = @_; |
1698 | my ($self) = @_; |
1708 | |
1699 | |
1709 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1700 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1710 | |
1701 | |
1711 | # determine overall size by querying abs widgets |
1702 | # determine overall size by querying abs widgets |
1712 | for my $child ($self->visible_children) { |
1703 | for my $child ($self->visible_children) { |
1713 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1704 | unless ($child->{c_rel}) { |
|
|
1705 | my $x = $child->{c_x}; |
|
|
1706 | my $y = $child->{c_y}; |
1714 | |
1707 | |
1715 | if ($pos eq "abs") { |
|
|
1716 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1717 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1718 | |
|
|
1719 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1708 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1720 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1709 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1721 | } |
1710 | } |
1722 | } |
1711 | } |
1723 | |
1712 | |
1724 | my $W = $x2 - $x1; |
1713 | my $W = $x2 - $x1; |
1725 | my $H = $y2 - $y1; |
1714 | my $H = $y2 - $y1; |
1726 | |
1715 | |
1727 | # now layout remaining widgets |
1716 | # now layout remaining widgets |
1728 | for my $child ($self->visible_children) { |
1717 | for my $child ($self->visible_children) { |
1729 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1718 | if ($child->{c_rel}) { |
|
|
1719 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1720 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1730 | |
1721 | |
1731 | if ($pos ne "abs") { |
|
|
1732 | $x = _scale $pos, $x, $W; |
|
|
1733 | $y = _scale $pos, $x, $H; |
|
|
1734 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1735 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1736 | |
|
|
1737 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1722 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1738 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1723 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1739 | } |
1724 | } |
1740 | } |
1725 | } |
1741 | |
1726 | |
1742 | my $W = $x2 - $x1; |
1727 | my $W = $x2 - $x1; |
1743 | my $H = $y2 - $y1; |
1728 | my $H = $y2 - $y1; |
… | |
… | |
1747 | |
1732 | |
1748 | sub invoke_size_allocate { |
1733 | sub invoke_size_allocate { |
1749 | my ($self, $W, $H) = @_; |
1734 | my ($self, $W, $H) = @_; |
1750 | |
1735 | |
1751 | for my $child ($self->visible_children) { |
1736 | for my $child ($self->visible_children) { |
1752 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1737 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1738 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1753 | |
1739 | |
1754 | $x = _scale $pos, $x, $W; |
1740 | $x += $child->{c_halign} * $child->{req_w}; |
1755 | $y = _scale $pos, $x, $H; |
1741 | $y += $child->{c_valign} * $child->{req_h}; |
1756 | $w = _scale $size, $w, $W; |
|
|
1757 | $h = _scale $size, $h, $H; |
|
|
1758 | |
1742 | |
1759 | $child->configure ($x, $y, $w, $h); |
1743 | $child->configure ($x, $y, $child->{req_w}, $child->{req_h}); |
1760 | } |
1744 | } |
1761 | |
1745 | |
1762 | 1 |
1746 | 1 |
1763 | } |
1747 | } |
1764 | |
1748 | |