… | |
… | |
2750 | |
2750 | |
2751 | # todo: base offset on lines or so, not on pixels |
2751 | # todo: base offset on lines or so, not on pixels |
2752 | $self->{children}[1]->set_value ($offset); |
2752 | $self->{children}[1]->set_value ($offset); |
2753 | } |
2753 | } |
2754 | |
2754 | |
|
|
2755 | sub current_paragraph { |
|
|
2756 | my ($self) = @_; |
|
|
2757 | |
|
|
2758 | $self->force_uptodate; |
|
|
2759 | $self->{top_paragraph} - 1 |
|
|
2760 | } |
|
|
2761 | |
|
|
2762 | sub scroll_to { |
|
|
2763 | my ($self, $para) = @_; |
|
|
2764 | |
|
|
2765 | $self->force_uptodate; |
|
|
2766 | |
|
|
2767 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
|
|
2768 | |
|
|
2769 | $self->{children}[1]->set_value ($self->{par}[$para]{y}); |
|
|
2770 | } |
|
|
2771 | |
2755 | sub clear { |
2772 | sub clear { |
2756 | my ($self) = @_; |
2773 | my ($self) = @_; |
2757 | |
2774 | |
2758 | my (undef, undef, @other) = @{ $self->{children} }; |
2775 | my (undef, undef, @other) = @{ $self->{children} }; |
2759 | $self->remove ($_) for @other; |
2776 | $self->remove ($_) for @other; |
… | |
… | |
2790 | |
2807 | |
2791 | $self->{scroll_to_bottom} = 1; |
2808 | $self->{scroll_to_bottom} = 1; |
2792 | $self->update; |
2809 | $self->update; |
2793 | } |
2810 | } |
2794 | |
2811 | |
|
|
2812 | sub force_uptodate { |
|
|
2813 | my ($self) = @_; |
|
|
2814 | |
|
|
2815 | if (delete $self->{need_reflow}) { |
|
|
2816 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2817 | |
|
|
2818 | my $height = 0; |
|
|
2819 | my $paridx; |
|
|
2820 | my $top_paragraph; |
|
|
2821 | my $top = int $self->{children}[1]{range}[0]; |
|
|
2822 | |
|
|
2823 | for my $para (@{$self->{par}}) { |
|
|
2824 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2825 | my $layout = $self->get_layout ($para); |
|
|
2826 | my ($w, $h) = $layout->size; |
|
|
2827 | |
|
|
2828 | $para->{w} = $w + $para->{indent}; |
|
|
2829 | $para->{h} = $h; |
|
|
2830 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2831 | } |
|
|
2832 | |
|
|
2833 | $para->{y} = $height; |
|
|
2834 | |
|
|
2835 | $paridx++; |
|
|
2836 | $top_paragraph ||= $paridx if $height >= $top; |
|
|
2837 | |
|
|
2838 | $height += $para->{h}; |
|
|
2839 | } |
|
|
2840 | |
|
|
2841 | $self->{top_paragraph} = $top_paragraph; |
|
|
2842 | $self->{height} = $height; |
|
|
2843 | |
|
|
2844 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2845 | |
|
|
2846 | delete $self->{texture}; |
|
|
2847 | } |
|
|
2848 | |
|
|
2849 | if (delete $self->{scroll_to_bottom}) { |
|
|
2850 | $self->{children}[1]->set_value (1e10); |
|
|
2851 | } |
|
|
2852 | } |
|
|
2853 | |
2795 | sub update { |
2854 | sub update { |
2796 | my ($self) = @_; |
2855 | my ($self) = @_; |
2797 | |
2856 | |
2798 | $self->SUPER::update; |
2857 | $self->SUPER::update; |
2799 | |
2858 | |
2800 | return unless $self->{h} > 0; |
2859 | return unless $self->{h} > 0; |
2801 | |
2860 | |
2802 | delete $self->{texture}; |
2861 | delete $self->{texture}; |
2803 | |
2862 | |
2804 | $ROOT->on_post_alloc ($self => sub { |
2863 | $ROOT->on_post_alloc ($self => sub { |
|
|
2864 | $self->force_uptodate; |
|
|
2865 | |
2805 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2866 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2806 | |
|
|
2807 | if (delete $self->{need_reflow}) { |
|
|
2808 | my $height = 0; |
|
|
2809 | |
|
|
2810 | for my $para (@{$self->{par}}) { |
|
|
2811 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2812 | my $layout = $self->get_layout ($para); |
|
|
2813 | my ($w, $h) = $layout->size; |
|
|
2814 | |
|
|
2815 | $para->{w} = $w + $para->{indent}; |
|
|
2816 | $para->{h} = $h; |
|
|
2817 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2818 | } |
|
|
2819 | |
|
|
2820 | $height += $para->{h}; |
|
|
2821 | } |
|
|
2822 | |
|
|
2823 | $self->{height} = $height; |
|
|
2824 | |
|
|
2825 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2826 | |
|
|
2827 | delete $self->{texture}; |
|
|
2828 | } |
|
|
2829 | |
|
|
2830 | if (delete $self->{scroll_to_bottom}) { |
|
|
2831 | $self->{children}[1]->set_value (1e10); |
|
|
2832 | } |
|
|
2833 | |
2867 | |
2834 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2868 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2835 | glClearColor 0, 0, 0, 0; |
2869 | glClearColor 0, 0, 0, 0; |
2836 | glClear GL_COLOR_BUFFER_BIT; |
2870 | glClear GL_COLOR_BUFFER_BIT; |
2837 | |
2871 | |
2838 | my $top = int $self->{children}[1]{range}[0]; |
2872 | my $top = int $self->{children}[1]{range}[0]; |
2839 | |
2873 | |
2840 | my $y0 = $top; |
2874 | my $y0 = $top; |
2841 | my $y1 = $top + $H; |
2875 | my $y1 = $top + $H; |
2842 | |
2876 | |
2843 | my $y = 0; |
|
|
2844 | |
|
|
2845 | for my $para (@{$self->{par}}) { |
2877 | for my $para (@{$self->{par}}) { |
2846 | my $h = $para->{h}; |
2878 | my $h = $para->{h}; |
|
|
2879 | my $y = $para->{y}; |
2847 | |
2880 | |
2848 | if ($y0 < $y + $h && $y < $y1) { |
2881 | if ($y0 < $y + $h && $y < $y1) { |
2849 | |
|
|
2850 | my $layout = $self->get_layout ($para); |
2882 | my $layout = $self->get_layout ($para); |
2851 | |
2883 | |
2852 | $layout->render ($para->{indent}, $y - $y0); |
2884 | $layout->render ($para->{indent}, $y - $y0); |
2853 | |
2885 | |
2854 | if (my @w = @{ $para->{widget} }) { |
2886 | if (my @w = @{ $para->{widget} }) { |
… | |
… | |
2862 | |
2894 | |
2863 | $_->draw; |
2895 | $_->draw; |
2864 | } |
2896 | } |
2865 | } |
2897 | } |
2866 | } |
2898 | } |
2867 | |
|
|
2868 | $y += $h; |
|
|
2869 | } |
2899 | } |
2870 | }; |
2900 | }; |
2871 | }); |
2901 | }); |
2872 | } |
2902 | } |
2873 | |
2903 | |