Module: TkScrollableWidget
- Defined in:
- lib/a-tkcommons.rb
Class Method Summary collapse
Instance Method Summary collapse
- #__initialize_scrolling(_widget = self) ⇒ Object
- #add_xscrollcommand(cmd = Proc.new) ⇒ Object
- #add_yscrollcommand(cmd = Proc.new) ⇒ Object
- #arm_scroll_binding ⇒ Object
- #call_after_next_show_h_scroll(_proc_to_call = nil) ⇒ Object
- #call_after_next_show_v_scroll(_proc_to_call = nil) ⇒ Object
- #destroy ⇒ Object
- #disarm_scroll_binding ⇒ Object
- #do_xscrollcommand(first, last) ⇒ Object
- #do_yscrollcommand(first, last) ⇒ Object
- #hide ⇒ Object
- #hide_h_scroll ⇒ Object
- #hide_v_scroll ⇒ Object
- #show(_x = 0, _y = 0, _w = nil, _h = nil, _border_mode = 'inside') ⇒ Object
- #show_h_scroll(_force = false) ⇒ Object
- #show_v_scroll(_force = false) ⇒ Object
Class Method Details
.extended(_widget) ⇒ Object
2578 2579 2580 |
# File 'lib/a-tkcommons.rb', line 2578 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
2582 2583 2584 |
# File 'lib/a-tkcommons.rb', line 2582 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 |
# File 'lib/a-tkcommons.rb', line 2586 def __initialize_scrolling(=self) @widget = @parent = TkWinfo.parent(@widget) @scroll_width = Arcadia.style('scrollbar')['width'].to_i @x=0 @y=0 @v_scroll_on = false @h_scroll_on = false @v_scroll = Arcadia.wf.(@parent,{'orient'=>'vertical'}) @h_scroll = Arcadia.wf.(@parent,{'orient'=>'horizontal'}) end |
#add_xscrollcommand(cmd = Proc.new) ⇒ Object
2634 2635 2636 |
# File 'lib/a-tkcommons.rb', line 2634 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
2611 2612 2613 |
# File 'lib/a-tkcommons.rb', line 2611 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 |
# File 'lib/a-tkcommons.rb', line 2700 def arm_scroll_binding @widget.yscrollcommand(proc{|first,last| do_yscrollcommand(first,last) }) @v_scroll.command(proc{|*args| @widget.yview *args }) @widget.xscrollcommand(proc{|first,last| do_xscrollcommand(first,last) }) @h_scroll.command(proc{|*args| @widget.xview *args }) end |
#call_after_next_show_h_scroll(_proc_to_call = nil) ⇒ Object
2603 2604 2605 |
# File 'lib/a-tkcommons.rb', line 2603 def call_after_next_show_h_scroll(_proc_to_call=nil) @h_proc = _proc_to_call end |
#call_after_next_show_v_scroll(_proc_to_call = nil) ⇒ Object
2607 2608 2609 |
# File 'lib/a-tkcommons.rb', line 2607 def call_after_next_show_v_scroll(_proc_to_call=nil) @v_proc = _proc_to_call end |
#destroy ⇒ Object
2598 2599 2600 2601 |
# File 'lib/a-tkcommons.rb', line 2598 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
2715 2716 2717 2718 2719 2720 |
# File 'lib/a-tkcommons.rb', line 2715 def disarm_scroll_binding @widget.yscrollcommand(proc{}) @widget.xscrollcommand(proc{}) @v_scroll.command(proc{}) if @v_scroll @h_scroll.command(proc{}) if @h_scroll end |
#do_xscrollcommand(first, last) ⇒ Object
2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 |
# File 'lib/a-tkcommons.rb', line 2638 def do_xscrollcommand(first,last) if first != nil && last != nil delta = last.to_f - first.to_f if delta < 1 && delta > 0 && last != @last_x_last show_h_scroll begin @h_scroll.set(first,last) #if TkWinfo.mapped?(@h_scroll) rescue Exception => e Arcadia.runtime_error(e) #p "#{e.message}" end elsif delta == 1 || delta == 0 hide_h_scroll end @h_scroll_command.call(first,last) if !@h_scroll_command.nil? @last_x_last = last if last.to_f < 1 end if @x_proc begin @x_proc.call ensure @x_proc=nil end end end |
#do_yscrollcommand(first, last) ⇒ Object
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
# File 'lib/a-tkcommons.rb', line 2615 def do_yscrollcommand(first,last) if first != nil && last != nil delta = last.to_f - first.to_f if delta < 1 && delta > 0 && last != @last_y_last show_v_scroll begin @v_scroll.set(first,last) #if TkWinfo.mapped?(@v_scroll) rescue Exception => e Arcadia.runtime_error(e) #p "#{e.message}" end elsif delta == 1 || delta == 0 hide_v_scroll end @v_scroll_command.call(first,last) if !@v_scroll_command.nil? @last_y_last = last if last.to_f < 1 end end |
#hide ⇒ Object
2693 2694 2695 2696 2697 2698 |
# File 'lib/a-tkcommons.rb', line 2693 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 |
# File 'lib/a-tkcommons.rb', line 2778 def hide_h_scroll if @h_scroll_on begin @widget.place('height' => 0) @h_scroll.unpack @h_scroll_on = false rescue RuntimeError => e Arcadia.runtime_error(e) #p "RuntimeError : #{e.message}" end end end |
#hide_v_scroll ⇒ Object
2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 |
# File 'lib/a-tkcommons.rb', line 2764 def hide_v_scroll if @v_scroll_on begin @widget.place('width' => 0) @v_scroll.unpack @v_scroll_on = false rescue RuntimeError => e Arcadia.runtime_error(e) #p "RuntimeError : #{e.message}" end end end |
#show(_x = 0, _y = 0, _w = nil, _h = nil, _border_mode = 'inside') ⇒ Object
2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 |
# File 'lib/a-tkcommons.rb', line 2664 def show(_x=0,_y=0,_w=nil,_h=nil,_border_mode='inside') @x=_x @y=_y _w != nil ? @w=_w : @w=-@x _h != nil ? @h=_h : @h=-@y @widget.place( 'x'=>@x, 'y'=>@y, 'width' => @w, 'height' => @h, 'relheight'=>1, 'relwidth'=>1, 'bordermode'=>_border_mode ) @widget.raise if @v_scroll_on show_v_scroll(true) end if @h_scroll_on show_h_scroll(true) end begin arm_scroll_binding rescue Exception => e Arcadia.runtime_error(e) #p "#{e.message}" end end |
#show_h_scroll(_force = false) ⇒ Object
2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 |
# File 'lib/a-tkcommons.rb', line 2743 def show_h_scroll(_force=false) if _force || !@h_scroll_on begin @widget.place('height' => -@scroll_width-@y) @h_scroll.pack('side' => 'bottom', 'fill' => 'x') @h_scroll_on = true @h_scroll.raise if @h_proc begin @h_proc.call ensure @h_proc=nil end end rescue RuntimeError => e #p "RuntimeError : #{e.message}" Arcadia.runtime_error(e) end end end |
#show_v_scroll(_force = false) ⇒ Object
2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 |
# File 'lib/a-tkcommons.rb', line 2722 def show_v_scroll(_force=false) if _force || !@v_scroll_on begin @widget.place('width' => -@scroll_width-@x) @v_scroll.pack('side' => 'right', 'fill' => 'y') @v_scroll_on = true @v_scroll.raise if @v_proc begin @v_proc.call ensure @v_proc=nil end end rescue RuntimeError => e #p "RuntimeError : #{e.message}" Arcadia.runtime_error(e) end end end |