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
1838 1839 1840 |
# File 'lib/a-tkcommons.rb', line 1838 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
1842 1843 1844 |
# File 'lib/a-tkcommons.rb', line 1842 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 |
# File 'lib/a-tkcommons.rb', line 1846 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
1894 1895 1896 |
# File 'lib/a-tkcommons.rb', line 1894 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
1871 1872 1873 |
# File 'lib/a-tkcommons.rb', line 1871 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 |
# File 'lib/a-tkcommons.rb', line 1960 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
1863 1864 1865 |
# File 'lib/a-tkcommons.rb', line 1863 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
1867 1868 1869 |
# File 'lib/a-tkcommons.rb', line 1867 def call_after_next_show_v_scroll(_proc_to_call=nil) @v_proc = _proc_to_call end |
#destroy ⇒ Object
1858 1859 1860 1861 |
# File 'lib/a-tkcommons.rb', line 1858 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
1975 1976 1977 1978 1979 1980 |
# File 'lib/a-tkcommons.rb', line 1975 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
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 |
# File 'lib/a-tkcommons.rb', line 1898 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
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 |
# File 'lib/a-tkcommons.rb', line 1875 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
1953 1954 1955 1956 1957 1958 |
# File 'lib/a-tkcommons.rb', line 1953 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 |
# File 'lib/a-tkcommons.rb', line 2038 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
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 |
# File 'lib/a-tkcommons.rb', line 2024 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
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 |
# File 'lib/a-tkcommons.rb', line 1924 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
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 |
# File 'lib/a-tkcommons.rb', line 2003 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
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 |
# File 'lib/a-tkcommons.rb', line 1982 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 |