… | |
… | |
368 | |
368 | |
369 | # traverse the widget chain up to find the maximum "physical" size constraints |
369 | # traverse the widget chain up to find the maximum "physical" size constraints |
370 | sub get_max_wh { |
370 | sub get_max_wh { |
371 | my ($self) = @_; |
371 | my ($self) = @_; |
372 | |
372 | |
|
|
373 | my ($w, $h) = @$self{qw(max_w max_h)}; |
|
|
374 | |
|
|
375 | if ($w <= 0 || $h <= 0) { |
|
|
376 | my ($mw, $mh) = $self->{parent} |
373 | return $self->{parent}->get_max_wh |
377 | ? $self->{parent}->get_max_wh |
374 | if $self->{parent}; |
|
|
375 | |
|
|
376 | ($::WIDTH, $::HEIGHT) |
378 | : ($::WIDTH, $::HEIGHT); |
|
|
379 | |
|
|
380 | $w = $mw if $w <= 0; |
|
|
381 | $h = $mh if $h <= 0; |
|
|
382 | } |
|
|
383 | |
|
|
384 | ($w, $h) |
377 | } |
385 | } |
378 | |
386 | |
379 | sub size_request { |
387 | sub size_request { |
380 | require Carp; |
388 | require Carp; |
381 | Carp::confess "size_request is abstract"; |
389 | Carp::confess "size_request is abstract"; |
… | |
… | |
1241 | my ($class, %arg) = @_; |
1249 | my ($class, %arg) = @_; |
1242 | |
1250 | |
1243 | if ((exists $arg{label}) && !ref $arg{label}) { |
1251 | if ((exists $arg{label}) && !ref $arg{label}) { |
1244 | $arg{label} = new DC::UI::Label |
1252 | $arg{label} = new DC::UI::Label |
1245 | align => 1, |
1253 | align => 1, |
1246 | valign => 0, |
1254 | valign => 0.5, |
1247 | text => $arg{label}, |
1255 | text => $arg{label}, |
1248 | fontsize => ($arg{border} || 0.8) * 0.75; |
1256 | fontsize => ($arg{border} || 0.8) * 0.75; |
1249 | } |
1257 | } |
1250 | |
1258 | |
1251 | my $self = $class->SUPER::new ( |
1259 | my $self = $class->SUPER::new ( |
… | |
… | |
1361 | min_h => 32, |
1369 | min_h => 32, |
1362 | %arg, |
1370 | %arg, |
1363 | ); |
1371 | ); |
1364 | |
1372 | |
1365 | $self->{title_widget} = new DC::UI::Label |
1373 | $self->{title_widget} = new DC::UI::Label |
1366 | align => 0, |
1374 | align => 0.5, |
1367 | valign => 1, |
1375 | valign => 1, |
1368 | text => $self->{title}, |
1376 | text => $self->{title}, |
1369 | fontsize => $self->{border}, |
1377 | fontsize => $self->{border}, |
1370 | if exists $self->{title}; |
1378 | if exists $self->{title}; |
1371 | |
1379 | |
… | |
… | |
1889 | #max_w => maximum pixel width |
1897 | #max_w => maximum pixel width |
1890 | #style => 0, # render flags |
1898 | #style => 0, # render flags |
1891 | ellipsise => 3, # end |
1899 | ellipsise => 3, # end |
1892 | layout => (new DC::Layout), |
1900 | layout => (new DC::Layout), |
1893 | fontsize => 1, |
1901 | fontsize => 1, |
1894 | align => -1, |
1902 | align => 0.5, |
1895 | valign => -1, |
1903 | valign => 0.5, |
1896 | padding_x => 2, |
1904 | padding_x => 4, |
1897 | padding_y => 2, |
1905 | padding_y => 2, |
1898 | can_events => 0, |
1906 | can_events => 0, |
1899 | %arg |
1907 | %arg |
1900 | ); |
1908 | ); |
1901 | |
1909 | |
… | |
… | |
1967 | |
1975 | |
1968 | $self->{size_req} ||= do { |
1976 | $self->{size_req} ||= do { |
1969 | my ($max_w, $max_h) = $self->get_max_wh; |
1977 | my ($max_w, $max_h) = $self->get_max_wh; |
1970 | |
1978 | |
1971 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1979 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1972 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1980 | $self->{layout}->set_width ($max_w); |
1973 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1981 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1974 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1982 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1975 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1983 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1976 | |
1984 | |
1977 | my ($w, $h) = $self->{layout}->size; |
1985 | my ($w, $h) = $self->{layout}->size; |
1978 | |
1986 | |
1979 | if (exists $self->{template}) { |
1987 | if (exists $self->{template}) { |
1980 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1988 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1981 | $self->{template}->set_width ($self->{max_w} || -1); |
1989 | $self->{template}->set_width ($max_w); |
1982 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1990 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1983 | |
1991 | |
1984 | my ($w2, $h2) = $self->{template}->size; |
1992 | my ($w2, $h2) = $self->{template}->size; |
1985 | |
1993 | |
1986 | $w = List::Util::max $w, $w2; |
1994 | $w = List::Util::max $w, $w2; |
… | |
… | |
2042 | |
2050 | |
2043 | [$self->{layout}->size] |
2051 | [$self->{layout}->size] |
2044 | }; |
2052 | }; |
2045 | |
2053 | |
2046 | unless (exists $self->{ox}) { |
2054 | unless (exists $self->{ox}) { |
2047 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
2055 | $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2); |
2048 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
2056 | $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2); |
2049 | : ($self->{w} - $size->[0]) * 0.5); |
|
|
2050 | |
|
|
2051 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
|
|
2052 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
|
|
2053 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2054 | |
2057 | |
2055 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2058 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2056 | }; |
2059 | }; |
2057 | |
2060 | |
2058 | # unless ($self->{list}) { |
2061 | # unless ($self->{list}) { |
… | |
… | |
2093 | active_bg => [0, 0, 1, .2], |
2096 | active_bg => [0, 0, 1, .2], |
2094 | active_fg => [1, 1, 1], |
2097 | active_fg => [1, 1, 1], |
2095 | active_outline => [1, 1, 0], |
2098 | active_outline => [1, 1, 0], |
2096 | can_hover => 1, |
2099 | can_hover => 1, |
2097 | can_focus => 1, |
2100 | can_focus => 1, |
|
|
2101 | align => 0, |
2098 | valign => 0, |
2102 | valign => 0.5, |
2099 | can_events => 1, |
2103 | can_events => 1, |
2100 | ellipsise => 0, |
2104 | ellipsise => 0, |
2101 | padding_x => 4, |
2105 | padding_x => 4, |
2102 | padding_y => 2, |
2106 | padding_y => 2, |
2103 | #text => ... |
2107 | #text => ... |
… | |
… | |
2351 | } |
2355 | } |
2352 | |
2356 | |
2353 | sub move_cursor_ver { |
2357 | sub move_cursor_ver { |
2354 | my ($self, $dy) = @_; |
2358 | my ($self, $dy) = @_; |
2355 | |
2359 | |
2356 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2360 | my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2357 | |
2361 | |
2358 | $y += $dy; |
2362 | $line += $dy; |
2359 | |
2363 | |
2360 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
2364 | if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { |
2361 | $self->{cursor} = $index; |
2365 | $self->{cursor} = $index; |
2362 | delete $self->{cur_h}; |
2366 | delete $self->{cur_h}; |
2363 | $self->update; |
2367 | $self->update; |
2364 | return; |
2368 | return; |
2365 | } |
2369 | } |
… | |
… | |
2396 | sub new { |
2400 | sub new { |
2397 | my $class = shift; |
2401 | my $class = shift; |
2398 | |
2402 | |
2399 | $class->SUPER::new ( |
2403 | $class->SUPER::new ( |
2400 | can_hover => 1, |
2404 | can_hover => 1, |
2401 | align => 0, |
2405 | align => 0.5, |
2402 | valign => 0, |
2406 | valign => 0.5, |
2403 | can_events => 1, |
2407 | can_events => 1, |
2404 | @_ |
2408 | @_ |
2405 | ) |
2409 | ) |
2406 | } |
2410 | } |
2407 | |
2411 | |
… | |
… | |
2449 | padding_x => 8, |
2453 | padding_x => 8, |
2450 | padding_y => 4, |
2454 | padding_y => 4, |
2451 | fg => [1.0, 1.0, 1.0], |
2455 | fg => [1.0, 1.0, 1.0], |
2452 | active_fg => [0.8, 0.8, 0.8], |
2456 | active_fg => [0.8, 0.8, 0.8], |
2453 | can_hover => 1, |
2457 | can_hover => 1, |
2454 | align => 0, |
2458 | align => 0.5, |
2455 | valign => 0, |
2459 | valign => 0.5, |
2456 | can_events => 1, |
2460 | can_events => 1, |
2457 | @_ |
2461 | @_ |
2458 | ) |
2462 | ) |
2459 | } |
2463 | } |
2460 | |
2464 | |
… | |
… | |
2652 | padding_x => 4, |
2656 | padding_x => 4, |
2653 | padding_y => 4, |
2657 | padding_y => 4, |
2654 | fg => [1, 1, 1], |
2658 | fg => [1, 1, 1], |
2655 | active_fg => [0, 0, 1], |
2659 | active_fg => [0, 0, 1], |
2656 | can_hover => 1, |
2660 | can_hover => 1, |
2657 | align => 0, |
2661 | align => 0.5, |
2658 | valign => 0, |
2662 | valign => 0.5, |
2659 | can_events => 1, |
2663 | can_events => 1, |
2660 | @_ |
2664 | @_ |
2661 | ); |
2665 | ); |
2662 | } |
2666 | } |
2663 | |
2667 | |
… | |
… | |
2827 | fg => [1, 1, 1], |
2831 | fg => [1, 1, 1], |
2828 | bg => [0, 0, 1, 0.2], |
2832 | bg => [0, 0, 1, 0.2], |
2829 | bar => [0.7, 0.5, 0.1, 0.8], |
2833 | bar => [0.7, 0.5, 0.1, 0.8], |
2830 | outline => [0.4, 0.3, 0], |
2834 | outline => [0.4, 0.3, 0], |
2831 | fontsize => 0.9, |
2835 | fontsize => 0.9, |
2832 | valign => 0, |
2836 | valign => 0.5, |
2833 | align => 0, |
2837 | align => 0.5, |
2834 | can_events => 1, |
2838 | can_events => 1, |
2835 | ellipsise => 1, |
2839 | ellipsise => 1, |
2836 | label => "%d%%", |
2840 | label => "%d%%", |
2837 | %arg, |
2841 | %arg, |
2838 | ); |
2842 | ); |
… | |
… | |
2964 | can_hover => 1, |
2968 | can_hover => 1, |
2965 | can_events => 1, |
2969 | can_events => 1, |
2966 | %arg, |
2970 | %arg, |
2967 | ); |
2971 | ); |
2968 | |
2972 | |
2969 | $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); |
2973 | $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999"); |
2970 | $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2974 | $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2971 | $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); |
2975 | $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999"); |
2972 | |
2976 | |
2973 | $self |
2977 | $self |
2974 | } |
2978 | } |
2975 | |
2979 | |
2976 | sub set_fontsize { |
2980 | sub set_fontsize { |
… | |
… | |
3304 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3308 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3305 | $layout->set_markup ($para->{markup}); |
3309 | $layout->set_markup ($para->{markup}); |
3306 | |
3310 | |
3307 | $layout->set_shapes ( |
3311 | $layout->set_shapes ( |
3308 | map |
3312 | map |
3309 | +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3313 | +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3310 | @{$para->{widget}} |
3314 | @{$para->{widget}} |
3311 | ); |
3315 | ); |
3312 | |
3316 | |
3313 | $layout |
3317 | $layout |
3314 | } |
3318 | } |
… | |
… | |
3607 | $tip =~ s/\n+$//; |
3611 | $tip =~ s/\n+$//; |
3608 | |
3612 | |
3609 | $self->add (new DC::UI::Label |
3613 | $self->add (new DC::UI::Label |
3610 | markup => $tip, |
3614 | markup => $tip, |
3611 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3615 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
3616 | align => 0, |
3612 | fontsize => 0.8, |
3617 | fontsize => 0.8, |
3613 | style => 1, # FLAG_INVERSE |
3618 | style => 1, # FLAG_INVERSE |
3614 | ellipsise => 0, |
3619 | ellipsise => 0, |
3615 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3620 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3616 | ); |
3621 | ); |
… | |
… | |
3841 | can_hover => 1, |
3846 | can_hover => 1, |
3842 | can_events => 1, |
3847 | can_events => 1, |
3843 | tooltip => $tooltip, |
3848 | tooltip => $tooltip, |
3844 | children => [ |
3849 | children => [ |
3845 | (new DC::UI::Label markup => $left, expand => 1), |
3850 | (new DC::UI::Label markup => $left, expand => 1), |
3846 | (new DC::UI::Label markup => $right, align => +1), |
3851 | (new DC::UI::Label markup => $right, align => 1), |
3847 | ], |
3852 | ], |
3848 | ; |
3853 | ; |
3849 | |
3854 | |
3850 | } else { |
3855 | } else { |
3851 | $widget = new DC::UI::Label |
3856 | $widget = new DC::UI::Label |
3852 | can_hover => 1, |
3857 | can_hover => 1, |
3853 | can_events => 1, |
3858 | can_events => 1, |
|
|
3859 | align => 0, |
3854 | markup => $widget, |
3860 | markup => $widget, |
3855 | tooltip => $tooltip; |
3861 | tooltip => $tooltip; |
3856 | } |
3862 | } |
3857 | } |
3863 | } |
3858 | |
3864 | |
… | |
… | |
4049 | } |
4055 | } |
4050 | |
4056 | |
4051 | sub pages { |
4057 | sub pages { |
4052 | my ($self) = @_; |
4058 | my ($self) = @_; |
4053 | $self->{multiplexer}->children |
4059 | $self->{multiplexer}->children |
|
|
4060 | } |
|
|
4061 | |
|
|
4062 | sub page_index { |
|
|
4063 | my ($self, $widget) = @_; |
|
|
4064 | |
|
|
4065 | my $i = 0; |
|
|
4066 | for ($self->pages) { |
|
|
4067 | if ($_ eq $widget) { return $i }; |
|
|
4068 | $i++; |
|
|
4069 | } |
|
|
4070 | |
|
|
4071 | undef |
4054 | } |
4072 | } |
4055 | |
4073 | |
4056 | sub add_tab { |
4074 | sub add_tab { |
4057 | my ($self, $title, $widget, $tooltip) = @_; |
4075 | my ($self, $title, $widget, $tooltip) = @_; |
4058 | |
4076 | |
… | |
… | |
4222 | tooltip => $item->{tooltip}, |
4240 | tooltip => $item->{tooltip}, |
4223 | tooltip_font => $::FONT_PROP, |
4241 | tooltip_font => $::FONT_PROP, |
4224 | tooltip_width => 0.67, |
4242 | tooltip_width => 0.67, |
4225 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4243 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4226 | max_w => $::WIDTH * 0.44, |
4244 | max_w => $::WIDTH * 0.44, |
|
|
4245 | align => 0, |
4227 | fg => [@{ $item->{fg} }], |
4246 | fg => [@{ $item->{fg} }], |
4228 | can_events => 1, |
4247 | can_events => 1, |
4229 | can_hover => 1 |
4248 | can_hover => 1 |
4230 | }; |
4249 | }; |
4231 | |
4250 | |
… | |
… | |
4455 | |
4474 | |
4456 | delete $queue{$widget+0}; |
4475 | delete $queue{$widget+0}; |
4457 | |
4476 | |
4458 | my ($w, $h) = $widget->size_request; |
4477 | my ($w, $h) = $widget->size_request; |
4459 | |
4478 | |
4460 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
4479 | $w += $widget->{padding_x} * 2; |
4461 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
4480 | $h += $widget->{padding_y} * 2; |
|
|
4481 | |
|
|
4482 | $w = max $widget->{min_w}, $w; |
|
|
4483 | $h = max $widget->{min_h}, $h; |
4462 | |
4484 | |
4463 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4485 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4464 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4486 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4465 | |
4487 | |
4466 | $w = $widget->{force_w} if exists $widget->{force_w}; |
4488 | $w = $widget->{force_w} if exists $widget->{force_w}; |