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
- #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
1584 1585 1586 |
# File 'lib/a-tkcommons.rb', line 1584 def self.extended() .__initialize_scrolling() end |
.included(_widget) ⇒ Object
1588 1589 1590 |
# File 'lib/a-tkcommons.rb', line 1588 def self.included() .__initialize_scrolling() end |
Instance Method Details
#__initialize_scrolling(_widget = self) ⇒ Object
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 |
# File 'lib/a-tkcommons.rb', line 1592 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
1631 1632 1633 |
# File 'lib/a-tkcommons.rb', line 1631 def add_xscrollcommand(cmd=Proc.new) @h_scroll_command = cmd end |
#add_yscrollcommand(cmd = Proc.new) ⇒ Object
1609 1610 1611 |
# File 'lib/a-tkcommons.rb', line 1609 def add_yscrollcommand(cmd=Proc.new) @v_scroll_command = cmd end |
#arm_scroll_binding ⇒ Object
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 |
# File 'lib/a-tkcommons.rb', line 1688 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 |
#destroy ⇒ Object
1604 1605 1606 1607 |
# File 'lib/a-tkcommons.rb', line 1604 def destroy @h_scroll.destroy @v_scroll.destroy end |
#disarm_scroll_binding ⇒ Object
1703 1704 1705 1706 1707 1708 |
# File 'lib/a-tkcommons.rb', line 1703 def disarm_scroll_binding @widget.yscrollcommand(proc{}) @widget.xscrollcommand(proc{}) @v_scroll.command(proc{}) @h_scroll.command(proc{}) end |
#do_xscrollcommand(first, last) ⇒ Object
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 |
# File 'lib/a-tkcommons.rb', line 1635 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 p "#{e.}" 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 end |
#do_yscrollcommand(first, last) ⇒ Object
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 |
# File 'lib/a-tkcommons.rb', line 1613 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 p "#{e.}" 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
1681 1682 1683 1684 1685 1686 |
# File 'lib/a-tkcommons.rb', line 1681 def hide disarm_scroll_binding @widget.unplace @v_scroll.unpack @h_scroll.unpack end |
#hide_h_scroll ⇒ Object
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 |
# File 'lib/a-tkcommons.rb', line 1749 def hide_h_scroll if @h_scroll_on begin @widget.place('height' => 0) @h_scroll.unpack @h_scroll_on = false rescue RuntimeError => e p "RuntimeError : #{e.}" end end end |
#hide_v_scroll ⇒ Object
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
# File 'lib/a-tkcommons.rb', line 1736 def hide_v_scroll if @v_scroll_on begin @widget.place('width' => 0) @v_scroll.unpack @v_scroll_on = false rescue RuntimeError => e p "RuntimeError : #{e.}" end end end |
#show(_x = 0, _y = 0, _w = nil, _h = nil, _border_mode = 'inside') ⇒ Object
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 |
# File 'lib/a-tkcommons.rb', line 1653 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 p "#{e.}" end end |
#show_h_scroll(_force = false) ⇒ Object
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 |
# File 'lib/a-tkcommons.rb', line 1723 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 rescue RuntimeError => e p "RuntimeError : #{e.}" end end end |
#show_v_scroll(_force = false) ⇒ Object
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 |
# File 'lib/a-tkcommons.rb', line 1710 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 rescue RuntimeError => e p "RuntimeError : #{e.}" end end end |