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
1944 1945 1946 |
# File 'lib/a-tkcommons.rb', line 1944 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
1948 1949 1950 |
# File 'lib/a-tkcommons.rb', line 1948 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 |
# File 'lib/a-tkcommons.rb', line 1952 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
2000 2001 2002 |
# File 'lib/a-tkcommons.rb', line 2000 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
1977 1978 1979 |
# File 'lib/a-tkcommons.rb', line 1977 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 |
# File 'lib/a-tkcommons.rb', line 2066 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
1969 1970 1971 |
# File 'lib/a-tkcommons.rb', line 1969 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
1973 1974 1975 |
# File 'lib/a-tkcommons.rb', line 1973 def call_after_next_show_v_scroll(_proc_to_call=nil) @v_proc = _proc_to_call end |
#destroy ⇒ Object
1964 1965 1966 1967 |
# File 'lib/a-tkcommons.rb', line 1964 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
2081 2082 2083 2084 2085 2086 |
# File 'lib/a-tkcommons.rb', line 2081 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
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 |
# File 'lib/a-tkcommons.rb', line 2004 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
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 |
# File 'lib/a-tkcommons.rb', line 1981 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
2059 2060 2061 2062 2063 2064 |
# File 'lib/a-tkcommons.rb', line 2059 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 |
# File 'lib/a-tkcommons.rb', line 2144 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
2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 |
# File 'lib/a-tkcommons.rb', line 2130 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
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 |
# File 'lib/a-tkcommons.rb', line 2030 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
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 |
# File 'lib/a-tkcommons.rb', line 2109 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
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 |
# File 'lib/a-tkcommons.rb', line 2088 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 |