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
1929 1930 1931 |
# File 'lib/a-tkcommons.rb', line 1929 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
1933 1934 1935 |
# File 'lib/a-tkcommons.rb', line 1933 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 |
# File 'lib/a-tkcommons.rb', line 1937 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
1985 1986 1987 |
# File 'lib/a-tkcommons.rb', line 1985 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
1962 1963 1964 |
# File 'lib/a-tkcommons.rb', line 1962 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 |
# File 'lib/a-tkcommons.rb', line 2051 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
1954 1955 1956 |
# File 'lib/a-tkcommons.rb', line 1954 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
1958 1959 1960 |
# File 'lib/a-tkcommons.rb', line 1958 def call_after_next_show_v_scroll(_proc_to_call=nil) @v_proc = _proc_to_call end |
#destroy ⇒ Object
1949 1950 1951 1952 |
# File 'lib/a-tkcommons.rb', line 1949 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
2066 2067 2068 2069 2070 2071 |
# File 'lib/a-tkcommons.rb', line 2066 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
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 |
# File 'lib/a-tkcommons.rb', line 1989 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
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'lib/a-tkcommons.rb', line 1966 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
2044 2045 2046 2047 2048 2049 |
# File 'lib/a-tkcommons.rb', line 2044 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 |
# File 'lib/a-tkcommons.rb', line 2129 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
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 |
# File 'lib/a-tkcommons.rb', line 2115 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
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
# File 'lib/a-tkcommons.rb', line 2015 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
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 |
# File 'lib/a-tkcommons.rb', line 2094 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
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 |
# File 'lib/a-tkcommons.rb', line 2073 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 |