… | |
… | |
207 | sub new_switchable_inlay { |
207 | sub new_switchable_inlay { |
208 | my ($self, $header, $cb, $visible) = @_; |
208 | my ($self, $header, $cb, $visible) = @_; |
209 | |
209 | |
210 | my $inlay; |
210 | my $inlay; |
211 | |
211 | |
212 | my $setvisible = sub { |
|
|
213 | if ($inlay->{visible}) { |
|
|
214 | $inlay->{cb}->($inlay); |
|
|
215 | } else { |
|
|
216 | $inlay->clear; |
|
|
217 | } |
|
|
218 | }; |
|
|
219 | |
|
|
220 | my $tag = $self->new_eventtag (sub { |
212 | my $tag = $self->new_eventtag (sub { |
221 | my ($tag, $view, $event, $iter) = @_; |
213 | my ($tag, $view, $event, $iter) = @_; |
222 | |
214 | |
223 | if ($event->type eq "button-press") { |
215 | if ($event->type eq "button-press") { |
224 | $inlay->{visible} = !$inlay->{visible}; |
216 | $inlay->set_visible (!$inlay->{visible}); |
225 | $setvisible->(); |
|
|
226 | } |
217 | } |
227 | |
218 | |
228 | 1; |
219 | 1; |
229 | }); |
220 | }); |
230 | |
221 | |
231 | $tag->set (background => "#e0e0ff"); |
222 | $tag->set (background => "#e0e0ff"); |
232 | |
223 | |
233 | $self->{buffer}->insert ($self->{buffer}->get_end_iter, "\n"); |
224 | $self->{buffer}->insert ($self->{buffer}->get_end_iter, "\n"); |
234 | $self->{buffer}->insert_with_tags ($self->{buffer}->get_end_iter, util::xmlto "$header \x{21f3}", $tag); |
225 | $self->{buffer}->insert_with_tags ($self->{buffer}->get_end_iter, util::xmlto "\x{21f3} $header", $tag); |
235 | |
226 | |
236 | $inlay = $self->new_inlay; |
227 | $inlay = $self->new_inlay; |
237 | |
228 | |
238 | $inlay->{visible} = $visible; |
229 | $inlay->{visible} = 0; |
239 | $inlay->{tag} = $tag; |
230 | $inlay->{tag} = $tag; |
240 | $inlay->{cb} = $cb; |
231 | $inlay->{cb} = $cb; |
241 | |
232 | |
242 | Scalar::Util::weaken $inlay->{tag}; |
233 | Scalar::Util::weaken $inlay->{tag}; |
243 | |
234 | |
244 | $setvisible->(); |
235 | $inlay->set_visible ($visible); |
245 | |
236 | |
246 | $inlay; |
237 | $inlay; |
247 | } |
238 | } |
248 | |
239 | |
249 | package superchat::inlay; |
240 | package superchat::inlay; |
… | |
… | |
260 | my ($self, $text) = @_; |
251 | my ($self, $text) = @_; |
261 | |
252 | |
262 | $self->{parent}->_append_text ($self->{r}, $text); |
253 | $self->{parent}->_append_text ($self->{r}, $text); |
263 | } |
254 | } |
264 | |
255 | |
|
|
256 | sub visible { $_[0]{visible} } |
|
|
257 | sub set_visible { |
|
|
258 | my ($self, $visible) = @_; |
|
|
259 | |
|
|
260 | return if $self->{visible} == $visible; |
|
|
261 | $self->{visible} = $visible; |
|
|
262 | |
|
|
263 | $self->refresh; |
|
|
264 | } |
|
|
265 | |
|
|
266 | sub refresh { |
|
|
267 | my ($self) = @_; |
|
|
268 | |
|
|
269 | $self->clear; |
|
|
270 | return unless $self->{visible}; |
|
|
271 | |
|
|
272 | $self->{cb}->($self); |
|
|
273 | } |
|
|
274 | |
265 | sub DESTROY { |
275 | sub DESTROY { |
266 | my ($self) = @_; |
276 | my ($self) = @_; |
267 | |
277 | |
268 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag}; |
278 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag}; |
269 | } |
279 | } |