… | |
… | |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
23 | if (!$GRAB) { |
23 | if (!$GRAB) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | if (length $widget->{tooltip}) { |
25 | if (length $widget->{tooltip}) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
|
|
27 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
27 | $TOOLTIP->hide; |
28 | $TOOLTIP->hide; |
28 | |
29 | |
29 | $TOOLTIP->{owner} = $widget; |
30 | $TOOLTIP->{owner} = $widget; |
|
|
31 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
30 | |
32 | |
31 | return if $ENV{CFPLUS_DEBUG} & 8; |
33 | return if $ENV{CFPLUS_DEBUG} & 8; |
32 | |
34 | |
33 | my $tip = $widget->{tooltip}; |
35 | my $tip = $widget->{tooltip}; |
34 | |
36 | |
… | |
… | |
42 | } |
44 | } |
43 | } |
45 | } |
44 | } |
46 | } |
45 | |
47 | |
46 | $TOOLTIP->hide; |
48 | $TOOLTIP->hide; |
|
|
49 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
47 | delete $TOOLTIP->{owner}; |
50 | delete $TOOLTIP->{owner}; |
48 | }); |
51 | }); |
49 | |
52 | |
50 | sub get_layout { |
53 | sub get_layout { |
51 | my $layout; |
54 | my $layout; |
… | |
… | |
265 | $self->hide; |
268 | $self->hide; |
266 | $self->emit ("destroy"); |
269 | $self->emit ("destroy"); |
267 | %$self = (); |
270 | %$self = (); |
268 | } |
271 | } |
269 | |
272 | |
|
|
273 | sub TO_JSON { |
|
|
274 | { __widget_ref__ => $_[0]{s_id} } |
|
|
275 | } |
|
|
276 | |
270 | sub show { |
277 | sub show { |
271 | my ($self) = @_; |
278 | my ($self) = @_; |
272 | |
279 | |
273 | return if $self->{parent}; |
280 | return if $self->{parent}; |
274 | |
281 | |
… | |
… | |
313 | sub set_visibility { |
320 | sub set_visibility { |
314 | my ($self, $visible) = @_; |
321 | my ($self, $visible) = @_; |
315 | |
322 | |
316 | return if $self->{visible} == $visible; |
323 | return if $self->{visible} == $visible; |
317 | |
324 | |
318 | $visible ? $self->hide |
325 | $visible ? $self->show |
319 | : $self->show; |
326 | : $self->hide; |
320 | } |
327 | } |
321 | |
328 | |
322 | sub toggle_visibility { |
329 | sub toggle_visibility { |
323 | my ($self) = @_; |
330 | my ($self) = @_; |
324 | |
331 | |
… | |
… | |
1026 | |
1033 | |
1027 | ############################################################################# |
1034 | ############################################################################# |
1028 | |
1035 | |
1029 | package CFPlus::UI::ScrolledWindow; |
1036 | package CFPlus::UI::ScrolledWindow; |
1030 | |
1037 | |
1031 | our @ISA = CFPlus::UI::HBox::; |
1038 | our @ISA = CFPlus::UI::Table::; |
1032 | |
1039 | |
1033 | sub new { |
1040 | sub new { |
1034 | my ($class, %arg) = @_; |
1041 | my ($class, %arg) = @_; |
1035 | |
1042 | |
1036 | my $child = delete $arg{child}; |
1043 | my $child = delete $arg{child}; |
1037 | |
1044 | |
1038 | my $self; |
1045 | my $self; |
1039 | |
1046 | |
1040 | my $slider = new CFPlus::UI::Slider |
1047 | my $hslider = new CFPlus::UI::Slider |
|
|
1048 | vertical => 0, |
|
|
1049 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
1050 | on_changed => sub { |
|
|
1051 | $self->{hpos} = $_[1]; |
|
|
1052 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
|
|
1053 | }, |
|
|
1054 | ; |
|
|
1055 | |
|
|
1056 | my $vslider = new CFPlus::UI::Slider |
1041 | vertical => 1, |
1057 | vertical => 1, |
1042 | range => [0, 0, 1, 0.01], # HACK fix |
1058 | range => [0, 0, 1, 0.01], # HACK fix |
1043 | on_changed => sub { |
1059 | on_changed => sub { |
1044 | $self->{vp}->set_offset (0, $_[1]); |
1060 | $self->{vpos} = $_[1]; |
|
|
1061 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1045 | }, |
1062 | }, |
1046 | ; |
1063 | ; |
1047 | |
1064 | |
1048 | $self = $class->SUPER::new ( |
1065 | $self = $class->SUPER::new ( |
1049 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1066 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1050 | can_events => 1, |
1067 | can_events => 1, |
1051 | slider => $slider, |
1068 | hslider => $hslider, |
|
|
1069 | vslider => $vslider, |
|
|
1070 | col_expand => [1, 0], |
|
|
1071 | row_expand => [1, 0], |
1052 | %arg, |
1072 | %arg, |
1053 | ); |
1073 | ); |
1054 | |
1074 | |
|
|
1075 | $self->SUPER::add (0, 0, $self->{vp}); |
1055 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
1076 | $self->SUPER::add (1, 0, $self->{vslider}); |
|
|
1077 | $self->SUPER::add (0, 1, $self->{hslider}); |
|
|
1078 | |
1056 | $self->add ($child) if $child; |
1079 | $self->add ($child) if $child; |
1057 | |
1080 | |
1058 | $self |
1081 | $self |
1059 | } |
1082 | } |
1060 | |
1083 | |
… | |
… | |
1069 | sub invoke_mouse_wheel { |
1092 | sub invoke_mouse_wheel { |
1070 | my ($self, $ev) = @_; |
1093 | my ($self, $ev) = @_; |
1071 | |
1094 | |
1072 | return 0 unless $ev->{dy}; # only vertical movements |
1095 | return 0 unless $ev->{dy}; # only vertical movements |
1073 | |
1096 | |
1074 | $self->{slider}->emit (mouse_wheel => $ev); |
1097 | $self->{vslider}->emit (mouse_wheel => $ev); |
1075 | |
1098 | |
1076 | 1 |
1099 | 1 |
1077 | } |
1100 | } |
1078 | |
1101 | |
1079 | sub update_slider { |
1102 | sub update_slider { |
1080 | my ($self) = @_; |
1103 | my ($self) = @_; |
1081 | |
1104 | |
|
|
1105 | my ($w1, $w2) = ($self->{vp}->child->{w}, $self->{vp}{w}); |
1082 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1106 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
|
|
1107 | #$self->{hslider}->set_visibility ($w1 != $w2); |
|
|
1108 | |
|
|
1109 | my ($h1, $h2) = ($self->{vp}->child->{h}, $self->{vp}{h}); |
|
|
1110 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
|
|
1111 | #$self->{vslider}->set_visibility ($h1 != $h2); |
1083 | } |
1112 | } |
1084 | |
1113 | |
1085 | sub update { |
1114 | sub update { |
1086 | my ($self) = @_; |
1115 | my ($self) = @_; |
1087 | |
1116 | |
… | |
… | |
1474 | sub new { |
1503 | sub new { |
1475 | my $class = shift; |
1504 | my $class = shift; |
1476 | |
1505 | |
1477 | $class->SUPER::new ( |
1506 | $class->SUPER::new ( |
1478 | col_expand => [], |
1507 | col_expand => [], |
|
|
1508 | row_expand => [], |
1479 | @_, |
1509 | @_, |
1480 | ) |
1510 | ) |
1481 | } |
1511 | } |
1482 | |
1512 | |
1483 | sub children { |
1513 | sub children { |
… | |
… | |
1558 | my ($ws, $hs) = $self->get_wh; |
1588 | my ($ws, $hs) = $self->get_wh; |
1559 | |
1589 | |
1560 | my $req_w = (sum @$ws) || 1; |
1590 | my $req_w = (sum @$ws) || 1; |
1561 | my $req_h = (sum @$hs) || 1; |
1591 | my $req_h = (sum @$hs) || 1; |
1562 | |
1592 | |
1563 | # TODO: nicer code && do row_expand |
1593 | # TODO: nicer code |
1564 | my @col_expand = @{$self->{col_expand}}; |
1594 | my @col_expand = @{$self->{col_expand}}; |
1565 | @col_expand = (1) x @$ws unless @col_expand; |
1595 | @col_expand = (1) x @$ws unless @col_expand; |
1566 | my $col_expand = (sum @col_expand) || 1; |
1596 | my $col_expand = (sum @col_expand) || 1; |
1567 | |
1597 | |
1568 | # linearly scale sizes |
|
|
1569 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1598 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1570 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
|
|
1571 | |
1599 | |
1572 | CFPlus::UI::harmonize $ws; |
1600 | CFPlus::UI::harmonize $ws; |
|
|
1601 | |
|
|
1602 | my @row_expand = @{$self->{row_expand}}; |
|
|
1603 | @row_expand = (1) x @$ws unless @row_expand; |
|
|
1604 | my $row_expand = (sum @row_expand) || 1; |
|
|
1605 | |
|
|
1606 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
|
|
1607 | |
1573 | CFPlus::UI::harmonize $hs; |
1608 | CFPlus::UI::harmonize $hs; |
1574 | |
1609 | |
1575 | my $y; |
1610 | my $y; |
1576 | |
1611 | |
1577 | for my $r (0 .. $#{$self->{children}}) { |
1612 | for my $r (0 .. $#{$self->{children}}) { |
… | |
… | |
1966 | my $mod = $ev->{mod}; |
2001 | my $mod = $ev->{mod}; |
1967 | my $sym = $ev->{sym}; |
2002 | my $sym = $ev->{sym}; |
1968 | my $uni = $ev->{unicode}; |
2003 | my $uni = $ev->{unicode}; |
1969 | |
2004 | |
1970 | my $text = $self->get_text; |
2005 | my $text = $self->get_text; |
|
|
2006 | |
|
|
2007 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
1971 | |
2008 | |
1972 | if ($uni == 8) { |
2009 | if ($uni == 8) { |
1973 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2010 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1974 | } elsif ($uni == 127) { |
2011 | } elsif ($uni == 127) { |
1975 | substr $text, $self->{cursor}, 1, ""; |
2012 | substr $text, $self->{cursor}, 1, ""; |