… | |
… | |
1311 | $item->{render} ||= sub { $_[0]{text} }; |
1311 | $item->{render} ||= sub { $_[0]{text} }; |
1312 | |
1312 | |
1313 | push @{ $self->{item} }, $item; |
1313 | push @{ $self->{item} }, $item; |
1314 | } |
1314 | } |
1315 | |
1315 | |
|
|
1316 | =item $popup->add_title ($title) |
|
|
1317 | |
|
|
1318 | Adds a non-clickable title to the popup. |
|
|
1319 | |
|
|
1320 | =cut |
|
|
1321 | |
|
|
1322 | sub add_title { |
|
|
1323 | my ($self, $title) = @_; |
|
|
1324 | |
|
|
1325 | $self->add_item ({ |
|
|
1326 | rend => { normal => "\x1b[38;5;11;44m", hover => "\x1b[38;5;11;44m", active => "\x1b[38;5;11;44m" }, |
|
|
1327 | text => $title, |
|
|
1328 | activate => sub { }, |
|
|
1329 | }); |
|
|
1330 | } |
|
|
1331 | |
|
|
1332 | =item $popup->add_separator ([$sepchr]) |
|
|
1333 | |
|
|
1334 | Creates a separator, optionally using the character given as C<$sepchr>. |
|
|
1335 | |
|
|
1336 | =cut |
|
|
1337 | |
1316 | sub add_separator { |
1338 | sub add_separator { |
1317 | my ($self, $sep) = @_; |
1339 | my ($self, $sep) = @_; |
1318 | |
1340 | |
1319 | $sep ||= "="; |
1341 | $sep ||= "="; |
1320 | |
1342 | |
… | |
… | |
1324 | render => sub { $sep x $self->{term}->ncol }, |
1346 | render => sub { $sep x $self->{term}->ncol }, |
1325 | activate => sub { }, |
1347 | activate => sub { }, |
1326 | }); |
1348 | }); |
1327 | } |
1349 | } |
1328 | |
1350 | |
1329 | sub add_title { |
1351 | =item $popup->add_button ($text, $cb) |
1330 | my ($self, $title) = @_; |
|
|
1331 | |
1352 | |
1332 | $self->add_item ({ |
1353 | Adds a clickable button to the popup. C<$cb> is called whenever it is |
1333 | rend => { normal => "\x1b[38;5;11;44m", hover => "\x1b[38;5;11;44m", active => "\x1b[38;5;11;44m" }, |
1354 | selected. |
1334 | text => $title, |
1355 | |
1335 | activate => sub { }, |
1356 | =cut |
1336 | }); |
|
|
1337 | } |
|
|
1338 | |
1357 | |
1339 | sub add_button { |
1358 | sub add_button { |
1340 | my ($self, $text, $cb) = @_; |
1359 | my ($self, $text, $cb) = @_; |
1341 | |
1360 | |
1342 | $self->add_item ({ type => "button", text => $text, activate => $cb}); |
1361 | $self->add_item ({ type => "button", text => $text, activate => $cb}); |
1343 | } |
1362 | } |
|
|
1363 | |
|
|
1364 | =item $popup->add_toggle ($text, $cb, $initial_value) |
|
|
1365 | |
|
|
1366 | Adds a toggle/checkbox item to the popup. Teh callback gets called |
|
|
1367 | whenever it gets toggled, with a boolean indicating its value as its first |
|
|
1368 | argument. |
|
|
1369 | |
|
|
1370 | =cut |
1344 | |
1371 | |
1345 | sub add_toggle { |
1372 | sub add_toggle { |
1346 | my ($self, $text, $cb, $value) = @_; |
1373 | my ($self, $text, $cb, $value) = @_; |
1347 | |
1374 | |
1348 | my $item; $item = { |
1375 | my $item; $item = { |
1349 | type => "button", |
1376 | type => "button", |
1350 | text => " $text", |
1377 | text => " $text", |
1351 | value => $value, |
1378 | value => $value, |
1352 | render => sub { ($_[0]{value} ? "* " : " ") . $text }, |
1379 | render => sub { ($_[0]{value} ? "* " : " ") . $text }, |
1353 | activate => sub { $cb->($_[0]{value} = !$_[0]{value}); }, |
1380 | activate => sub { $cb->($_[1]{value} = !$_[1]{value}); }, |
1354 | }; |
1381 | }; |
1355 | |
1382 | |
1356 | $self->add_item ($item); |
1383 | $self->add_item ($item); |
1357 | } |
1384 | } |
|
|
1385 | |
|
|
1386 | =item $popup->show |
|
|
1387 | |
|
|
1388 | Displays the popup (which is initially hidden). |
|
|
1389 | |
|
|
1390 | =cut |
1358 | |
1391 | |
1359 | sub show { |
1392 | sub show { |
1360 | my ($self) = @_; |
1393 | my ($self) = @_; |
1361 | |
1394 | |
1362 | local $urxvt::popup::self = $self; |
1395 | local $urxvt::popup::self = $self; |