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
1822 1823 1824 |
# File 'lib/a-tkcommons.rb', line 1822 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
1826 1827 1828 |
# File 'lib/a-tkcommons.rb', line 1826 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 |
# File 'lib/a-tkcommons.rb', line 1830 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
1878 1879 1880 |
# File 'lib/a-tkcommons.rb', line 1878 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
1855 1856 1857 |
# File 'lib/a-tkcommons.rb', line 1855 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 |
# File 'lib/a-tkcommons.rb', line 1944 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
1847 1848 1849 |
# File 'lib/a-tkcommons.rb', line 1847 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
1851 1852 1853 |
# File 'lib/a-tkcommons.rb', line 1851 def call_after_next_show_v_scroll(_proc_to_call=nil) @v_proc = _proc_to_call end |
#destroy ⇒ Object
1842 1843 1844 1845 |
# File 'lib/a-tkcommons.rb', line 1842 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
1959 1960 1961 1962 1963 1964 |
# File 'lib/a-tkcommons.rb', line 1959 def disarm_scroll_binding @widget.yscrollcommand(proc{}) @widget.xscrollcommand(proc{}) @v_scroll.command(proc{}) @h_scroll.command(proc{}) end |
#do_xscrollcommand(first, last) ⇒ Object
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 |
# File 'lib/a-tkcommons.rb', line 1882 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
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 |
# File 'lib/a-tkcommons.rb', line 1859 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
1937 1938 1939 1940 1941 1942 |
# File 'lib/a-tkcommons.rb', line 1937 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 |
# File 'lib/a-tkcommons.rb', line 2022 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
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 |
# File 'lib/a-tkcommons.rb', line 2008 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
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 |
# File 'lib/a-tkcommons.rb', line 1908 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
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 |
# File 'lib/a-tkcommons.rb', line 1987 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
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 |
# File 'lib/a-tkcommons.rb', line 1966 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 |