ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.457 by root, Fri Dec 28 15:05:20 2007 UTC vs.
Revision 1.467 by root, Wed Sep 3 06:07:39 2008 UTC

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
370sub get_max_wh { 370sub 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
379sub size_request { 387sub 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 (
1336our @ISA = DC::UI::Bin::; 1344our @ISA = DC::UI::Bin::;
1337 1345
1338use DC::OpenGL; 1346use DC::OpenGL;
1339 1347
1340my $bg = 1348my $bg =
1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png", 1349 new_from_resource DC::Texture "d1_bg.png",
1342 mipmap => 1, wrap => 1; 1350 mipmap => 1, wrap => 1;
1343 1351
1344my @border = 1352my @border =
1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1353 map { new_from_resource DC::Texture $_, mipmap => 1 }
1346 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1354 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1347 1355
1348my @icon = 1356my @icon =
1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1357 map { new_from_resource DC::Texture $_, mipmap => 1 }
1350 qw(x1_move.png x1_resize.png); 1358 qw(x1_move.png x1_resize.png);
1351 1359
1352sub new { 1360sub new {
1353 my ($class, %arg) = @_; 1361 my ($class, %arg) = @_;
1354 1362
1355 my $self = $class->SUPER::new ( 1363 my $self = $class->SUPER::new (
1356 bg => [1, 1, 1, 1], 1364 bg => [1, 1, 1, 1],
1357 border_bg => [1, 1, 1, 1], 1365 border_bg => [1, 1, 1, 1],
1358 border => 0.6, 1366 border => 1,
1359 can_events => 1, 1367 can_events => 1,
1360 min_w => 64, 1368 min_w => 64,
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 => ...
2154 2158
2155 my $text = $self->get_text; 2159 my $text = $self->get_text;
2156 2160
2157 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2161 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2158 2162
2159 if ($uni == 8) { 2163 if ($sym == DC::SDLK_BACKSPACE) {
2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2164 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2161 } elsif ($uni == 127) { 2165 } elsif ($sym == DC::SDLK_DELETE) {
2162 substr $text, $self->{cursor}, 1, ""; 2166 substr $text, $self->{cursor}, 1, "";
2163 } elsif ($sym == DC::SDLK_LEFT) { 2167 } elsif ($sym == DC::SDLK_LEFT) {
2164 --$self->{cursor} if $self->{cursor}; 2168 --$self->{cursor} if $self->{cursor};
2165 } elsif ($sym == DC::SDLK_RIGHT) { 2169 } elsif ($sym == DC::SDLK_RIGHT) {
2166 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2170 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2287 2291
2288our @ISA = DC::UI::EntryBase::; 2292our @ISA = DC::UI::EntryBase::;
2289 2293
2290use DC::OpenGL; 2294use DC::OpenGL;
2291 2295
2296sub new {
2297 my $class = shift;
2298
2299 $class->SUPER::new (
2300 history_pointer => -1,
2301 @_
2302 )
2303}
2304
2305
2292sub invoke_key_down { 2306sub invoke_key_down {
2293 my ($self, $ev) = @_; 2307 my ($self, $ev) = @_;
2294 2308
2295 my $sym = $ev->{sym}; 2309 my $sym = $ev->{sym};
2296 2310
2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2334 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2321 2335
2322 if ($self->{history_pointer} >= 0) { 2336 if ($self->{history_pointer} >= 0) {
2323 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2337 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2324 } else { 2338 } else {
2339 if (defined $self->{history_saveback}) {
2325 $self->set_text ($self->{history_saveback}); 2340 $self->set_text ($self->{history_saveback});
2341 $self->{history_saveback} = undef;
2342 }
2326 } 2343 }
2327 2344
2328 } else { 2345 } else {
2329 return $self->SUPER::invoke_key_down ($ev) 2346 return $self->SUPER::invoke_key_down ($ev)
2330 } 2347 }
2352 2369
2353sub move_cursor_ver { 2370sub move_cursor_ver {
2354 my ($self, $dy) = @_; 2371 my ($self, $dy) = @_;
2355 2372
2356 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2373 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2357 warn "cursor $self->{cursor} => $x $line\n";#d#
2358 2374
2359 $line += $dy; 2375 $line += $dy;
2360 2376
2361 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { 2377 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2362 warn "index $x $line => $index\n";#d#
2363 $self->{cursor} = $index; 2378 $self->{cursor} = $index;
2364 delete $self->{cur_h}; 2379 delete $self->{cur_h};
2365 $self->update; 2380 $self->update;
2366 return; 2381 return;
2367 } 2382 }
2390our @ISA = DC::UI::Bin::; 2405our @ISA = DC::UI::Bin::;
2391 2406
2392use DC::OpenGL; 2407use DC::OpenGL;
2393 2408
2394my @tex = 2409my @tex =
2395 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2410 map { new_from_resource DC::Texture $_, mipmap => 1 }
2396 qw(b1_button_inactive.png b1_button_active.png); 2411 qw(b1_button_inactive.png b1_button_active.png);
2397 2412
2398sub new { 2413sub new {
2399 my $class = shift; 2414 my $class = shift;
2400 2415
2401 $class->SUPER::new ( 2416 $class->SUPER::new (
2402 can_hover => 1, 2417 can_hover => 1,
2403 align => 0, 2418 align => 0.5,
2404 valign => 0, 2419 valign => 0.5,
2405 can_events => 1, 2420 can_events => 1,
2406 @_ 2421 @_
2407 ) 2422 )
2408} 2423}
2409 2424
2439our @ISA = DC::UI::Label::; 2454our @ISA = DC::UI::Label::;
2440 2455
2441use DC::OpenGL; 2456use DC::OpenGL;
2442 2457
2443my @tex = 2458my @tex =
2444 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2459 map { new_from_resource DC::Texture $_, mipmap => 1 }
2445 qw(b1_button_inactive.png b1_button_active.png); 2460 qw(b1_button_inactive.png b1_button_active.png);
2446 2461
2447sub new { 2462sub new {
2448 my $class = shift; 2463 my $class = shift;
2449 2464
2451 padding_x => 8, 2466 padding_x => 8,
2452 padding_y => 4, 2467 padding_y => 4,
2453 fg => [1.0, 1.0, 1.0], 2468 fg => [1.0, 1.0, 1.0],
2454 active_fg => [0.8, 0.8, 0.8], 2469 active_fg => [0.8, 0.8, 0.8],
2455 can_hover => 1, 2470 can_hover => 1,
2456 align => 0, 2471 align => 0.5,
2457 valign => 0, 2472 valign => 0.5,
2458 can_events => 1, 2473 can_events => 1,
2459 @_ 2474 @_
2460 ) 2475 )
2461} 2476}
2462 2477
2492package DC::UI::CheckBox; 2507package DC::UI::CheckBox;
2493 2508
2494our @ISA = DC::UI::DrawBG::; 2509our @ISA = DC::UI::DrawBG::;
2495 2510
2496my @tex = 2511my @tex =
2497 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2512 map { new_from_resource DC::Texture $_, mipmap => 1 }
2498 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2513 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2499 2514
2500use DC::OpenGL; 2515use DC::OpenGL;
2501 2516
2502sub new { 2517sub new {
2583 2598
2584 $self->{path} || $self->{tex} 2599 $self->{path} || $self->{tex}
2585 or Carp::croak "'path' or 'tex' attributes required"; 2600 or Carp::croak "'path' or 'tex' attributes required";
2586 2601
2587 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2602 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2588 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1; 2603 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2589 2604
2590 DC::weaken $texture_cache{$self->{path}}; 2605 DC::weaken $texture_cache{$self->{path}};
2591 2606
2592 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2607 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2593 2608
2654 padding_x => 4, 2669 padding_x => 4,
2655 padding_y => 4, 2670 padding_y => 4,
2656 fg => [1, 1, 1], 2671 fg => [1, 1, 1],
2657 active_fg => [0, 0, 1], 2672 active_fg => [0, 0, 1],
2658 can_hover => 1, 2673 can_hover => 1,
2659 align => 0, 2674 align => 0.5,
2660 valign => 0, 2675 valign => 0.5,
2661 can_events => 1, 2676 can_events => 1,
2662 @_ 2677 @_
2663 ); 2678 );
2664} 2679}
2665 2680
2689 2704
2690use DC::OpenGL; 2705use DC::OpenGL;
2691 2706
2692my %tex = ( 2707my %tex = (
2693 food => [ 2708 food => [
2694 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2709 map { new_from_resource DC::Texture $_, mipmap => 1 }
2695 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2710 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2696 ], 2711 ],
2697 grace => [ 2712 grace => [
2698 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2713 map { new_from_resource DC::Texture $_, mipmap => 1 }
2699 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2714 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2700 ], 2715 ],
2701 hp => [ 2716 hp => [
2702 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2717 map { new_from_resource DC::Texture $_, mipmap => 1 }
2703 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2718 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2704 ], 2719 ],
2705 mana => [ 2720 mana => [
2706 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2721 map { new_from_resource DC::Texture $_, mipmap => 1 }
2707 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2722 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2708 ], 2723 ],
2709); 2724);
2710 2725
2711# eg. VGauge->new (gauge => 'food'), default gauge: food 2726# eg. VGauge->new (gauge => 'food'), default gauge: food
2829 fg => [1, 1, 1], 2844 fg => [1, 1, 1],
2830 bg => [0, 0, 1, 0.2], 2845 bg => [0, 0, 1, 0.2],
2831 bar => [0.7, 0.5, 0.1, 0.8], 2846 bar => [0.7, 0.5, 0.1, 0.8],
2832 outline => [0.4, 0.3, 0], 2847 outline => [0.4, 0.3, 0],
2833 fontsize => 0.9, 2848 fontsize => 0.9,
2834 valign => 0, 2849 valign => 0.5,
2835 align => 0, 2850 align => 0.5,
2836 can_events => 1, 2851 can_events => 1,
2837 ellipsise => 1, 2852 ellipsise => 1,
2838 label => "%d%%", 2853 label => "%d%%",
2839 %arg, 2854 %arg,
2840 ); 2855 );
2966 can_hover => 1, 2981 can_hover => 1,
2967 can_events => 1, 2982 can_events => 1,
2968 %arg, 2983 %arg,
2969 ); 2984 );
2970 2985
2971 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); 2986 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2972 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2987 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2973 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); 2988 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2974 2989
2975 $self 2990 $self
2976} 2991}
2977 2992
2978sub set_fontsize { 2993sub set_fontsize {
3008use DC::OpenGL; 3023use DC::OpenGL;
3009 3024
3010our @ISA = DC::UI::DrawBG::; 3025our @ISA = DC::UI::DrawBG::;
3011 3026
3012my @tex = 3027my @tex =
3013 map { new_from_file DC::Texture DC::find_rcfile $_ } 3028 map { new_from_resource DC::Texture $_ }
3014 qw(s1_slider.png s1_slider_bg.png); 3029 qw(s1_slider.png s1_slider_bg.png);
3015 3030
3016sub new { 3031sub new {
3017 my $class = shift; 3032 my $class = shift;
3018 3033
3055sub set_value { 3070sub set_value {
3056 my ($self, $value) = @_; 3071 my ($self, $value) = @_;
3057 3072
3058 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3073 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3059 3074
3060 $hi = $lo + 1 if $hi <= $lo; 3075 $hi = $lo if $hi < $lo;
3061 3076
3062 $page = $hi - $lo if $page > $hi - $lo; 3077 $value = $hi - $page if $value > $hi - $page;
3063
3064 $value = $lo if $value < $lo; 3078 $value = $lo if $value < $lo;
3065 $value = $hi - $page if $value > $hi - $page;
3066 3079
3067 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3080 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3068 if $unit; 3081 if $unit;
3069 3082
3070 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3083 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3134 my ($self) = @_; 3147 my ($self) = @_;
3135 3148
3136 unless ($self->{knob_w}) { 3149 unless ($self->{knob_w}) {
3137 $self->set_value ($self->{range}[0]); 3150 $self->set_value ($self->{range}[0]);
3138 3151
3139 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3152 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3140 my $range = ($hi - $page - $lo) || 1e-100; 3153 my $range = ($hi - $page - $lo) || 1e-10;
3141 3154
3142 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3155 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3143 3156
3144 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3157 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3145 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3158 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3146 3159
3147 $value = ($value - $lo) / $range; 3160 $value = ($value - $lo) / $range;
3306 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3319 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3307 $layout->set_markup ($para->{markup}); 3320 $layout->set_markup ($para->{markup});
3308 3321
3309 $layout->set_shapes ( 3322 $layout->set_shapes (
3310 map 3323 map
3311 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3324 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3312 @{$para->{widget}} 3325 @{$para->{widget}}
3313 ); 3326 );
3314 3327
3315 $layout 3328 $layout
3316} 3329}
3609 $tip =~ s/\n+$//; 3622 $tip =~ s/\n+$//;
3610 3623
3611 $self->add (new DC::UI::Label 3624 $self->add (new DC::UI::Label
3612 markup => $tip, 3625 markup => $tip,
3613 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3626 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3627 align => 0,
3614 fontsize => 0.8, 3628 fontsize => 0.8,
3615 style => 1, # FLAG_INVERSE 3629 style => 1, # FLAG_INVERSE
3616 ellipsise => 0, 3630 ellipsise => 0,
3617 font => ($widget->{tooltip_font} || $::FONT_PROP), 3631 font => ($widget->{tooltip_font} || $::FONT_PROP),
3618 ); 3632 );
3842 $widget = new DC::UI::HBox 3856 $widget = new DC::UI::HBox
3843 can_hover => 1, 3857 can_hover => 1,
3844 can_events => 1, 3858 can_events => 1,
3845 tooltip => $tooltip, 3859 tooltip => $tooltip,
3846 children => [ 3860 children => [
3847 (new DC::UI::Label markup => $left, expand => 1), 3861 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3848 (new DC::UI::Label markup => $right, align => +1), 3862 (new DC::UI::Label markup => $right, align => 1),
3849 ], 3863 ],
3850 ; 3864 ;
3851 3865
3852 } else { 3866 } else {
3853 $widget = new DC::UI::Label 3867 $widget = new DC::UI::Label
3854 can_hover => 1, 3868 can_hover => 1,
3855 can_events => 1, 3869 can_events => 1,
3870 align => 0,
3856 markup => $widget, 3871 markup => $widget,
3857 tooltip => $tooltip; 3872 tooltip => $tooltip;
3858 } 3873 }
3859 } 3874 }
3860 3875
4051} 4066}
4052 4067
4053sub pages { 4068sub pages {
4054 my ($self) = @_; 4069 my ($self) = @_;
4055 $self->{multiplexer}->children 4070 $self->{multiplexer}->children
4071}
4072
4073sub page_index {
4074 my ($self, $widget) = @_;
4075
4076 my $i = 0;
4077 for ($self->pages) {
4078 if ($_ eq $widget) { return $i };
4079 $i++;
4080 }
4081
4082 undef
4056} 4083}
4057 4084
4058sub add_tab { 4085sub add_tab {
4059 my ($self, $title, $widget, $tooltip) = @_; 4086 my ($self, $title, $widget, $tooltip) = @_;
4060 4087
4224 tooltip => $item->{tooltip}, 4251 tooltip => $item->{tooltip},
4225 tooltip_font => $::FONT_PROP, 4252 tooltip_font => $::FONT_PROP,
4226 tooltip_width => 0.67, 4253 tooltip_width => 0.67,
4227 fontsize => $item->{fontsize} || $self->{fontsize}, 4254 fontsize => $item->{fontsize} || $self->{fontsize},
4228 max_w => $::WIDTH * 0.44, 4255 max_w => $::WIDTH * 0.44,
4256 align => 0,
4229 fg => [@{ $item->{fg} }], 4257 fg => [@{ $item->{fg} }],
4230 can_events => 1, 4258 can_events => 1,
4231 can_hover => 1 4259 can_hover => 1
4232 }; 4260 };
4233 4261
4457 4485
4458 delete $queue{$widget+0}; 4486 delete $queue{$widget+0};
4459 4487
4460 my ($w, $h) = $widget->size_request; 4488 my ($w, $h) = $widget->size_request;
4461 4489
4462 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4490 $w += $widget->{padding_x} * 2;
4463 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4491 $h += $widget->{padding_y} * 2;
4492
4493 $w = max $widget->{min_w}, $w;
4494 $h = max $widget->{min_h}, $h;
4464 4495
4465 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4496 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4466 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4497 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4467 4498
4468 $w = $widget->{force_w} if exists $widget->{force_w}; 4499 $w = $widget->{force_w} if exists $widget->{force_w};
4548 4579
4549############################################################################# 4580#############################################################################
4550 4581
4551package DC::UI; 4582package DC::UI;
4552 4583
4553$ROOT = new DC::UI::Root; 4584$ROOT = new DC::UI::Root;
4554$TOOLTIP = new DC::UI::Tooltip z => 900; 4585$TOOLTIP = new DC::UI::Tooltip z => 900;
4555 4586
45561 45871
4557 4588

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines