Class: AGTkFramePlaceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/tk/al-tk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_main_frame = nil) {|_self| ... } ⇒ AGTkFramePlaceManager

Returns a new instance of AGTkFramePlaceManager.

Yields:

  • (_self)

Yield Parameters:



1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
# File 'lib/tk/al-tk.rb', line 1542

def initialize(_main_frame = nil)
  @main_frame = _main_frame
  @frames = Hash.new
  @frames_seq = Array.new

  @frames_left = Hash.new
  @frames_right = Hash.new
  @frames_top = Hash.new
  @frames_bottom = Hash.new

  @Info = Struct.new("Info", :obj, :splitter, :side, :objp, :visible)
  @motion = false
  @nx= 0
  yield(self) if block_given?
end

Instance Attribute Details

#main_frameObject (readonly)

Returns the value of attribute main_frame.



1540
1541
1542
# File 'lib/tk/al-tk.rb', line 1540

def main_frame
  @main_frame
end

Instance Method Details

#[](_name) ⇒ Object



1678
1679
1680
# File 'lib/tk/al-tk.rb', line 1678

def [](_name)
  @frames[_name].obj
end

#add(_name, _frame = TkFrame.new(@main_frame), _ndim = -1,, _splitter = false, _side = 'x') ⇒ Object



1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
# File 'lib/tk/al-tk.rb', line 1558

def add(_name, _frame=TkFrame.new(@main_frame), _ndim=-1, _splitter=false, _side='x' )
  if _frame == nil
    _frame=TkFrame.new(@main_frame)
  end
  case _side
  when 'x'
    @frames_right.each_value{|value|
      value << _name
    }
    if @frames_right[_name]==nil
      @frames_right[_name] = Array.new
    end
  when 'y'
    @frames_bottom.each_value{|value|
      value << _name
    }
  end
  case _side
  when 'x'
    @frames_left[_name]= Array.new
    @frames_seq.each{|item|
      @frames_left[_name] << item
    }
    (_ndim>0)?(_rw=0):_rw=1
    _frame.place(
    'relwidth' => _rw,
    'relx' => 0,
    'x' => @nx,
    'y' => '0',
    'relheight' => '1',
    'rely' => 0,
    'height' => 1,
    'bordermode' => 'inside',
    'width' => _ndim
    )
    if _splitter
      _xbutton = TkButton.new(@main_frame){
        text  '<'
        overrelief  'ridge'
        relief  'groove'
      }
      _xbutton.place(
      'x' => @nx - 20,
      'y' => 0,
      'height' => 20,
      'bordermode' => 'outside',
      'width' => 20
      )
      _xbutton.bind_append(
      "ButtonPress-1",
      proc{
        @frames[@frames_left[_name][0]].objp.obj.unplace
        @frames[_name].objp.amove(1,0)
        do_resize(_name)
        _xbutton.place('x'=>0)
        _xbutton.raise
        if _xbutton.cget('text') == '<'
          _xbutton.configure('text'=>'>')
        else
          _xbutton.configure('text'=>'<')
        end
      }
      )
      if @motion
        _frame.bind_append(
        "B1-Motion",
        proc{do_resize(_name)}
        )
      else
        _frame.bind_append(
        "B1-Motion",
        proc{_frame.raise}
        )
      end
      _frame.bind_append(
      "ButtonRelease-1",
      proc{do_resize(_name)}
      )
    end

    @nx = @nx + _ndim if _ndim > 0

  when 'y'
    @frames_top[_name]= Array.new
    @frames_bottom[_name]= Array.new
    @frames_seq.each{|item|
      @frames_top[_name] << item
    }
  end
  @frames[_name] = @Info.new(
    _frame,
    _splitter,
    _side,
    AGTkObjPlace.new(_frame, _side),
    true
  )
  @frames_seq << _name
  return _frame
end

#do_resize(_name_splitter) ⇒ Object



1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
# File 'lib/tk/al-tk.rb', line 1658

def do_resize (_name_splitter)
  case @frames[_name_splitter].side
  when 'x'
    _x = @frames[_name_splitter].objp.x0
    if (_x > 0)&&(@frames_left.length > 0)
      _w = @frames[_name_splitter].objp.w
      _index = @frames_left[_name_splitter].length - 1
      if (@frames_left.length == 1)||(_x > @frames[@frames_left[_name_splitter][_index]].objp.x0)
        @frames[@frames_left[_name_splitter][_index]].objp.go(_x,0)
      end
      _gap = _w
      @frames_right[_name_splitter].each{|i|
        @frames[i].objp.amove(_x + _gap,0)
        _gap = _gap + @frames[i].objp.w
      }
    end
  when 'y'
  end
end

#frame(_name) ⇒ Object



1682
1683
1684
# File 'lib/tk/al-tk.rb', line 1682

def frame(_name)
  @frames[_name].obj
end

#hide(_name) ⇒ Object



1686
1687
1688
1689
1690
1691
1692
1693
# File 'lib/tk/al-tk.rb', line 1686

def hide(_name)
  _w = @frames[_name].objp.w
  @frames[_name].obj.unplace
  @frames[_name].visible = false
  @frames_right[_name].each{|i|
    @frames[i].objp.move(-_w,0) if @frames[i].visible
  }
end

#show(_name) ⇒ Object



1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
# File 'lib/tk/al-tk.rb', line 1694

def show(_name)
  _x = @frames[_name].objp.x0
  _w = @frames[_name].objp.w0
  @frames[_name].obj.place(
  'x' => _x,
  'relheight' => '1',
  'width' => _w
  )
  @frames[_name].visible = true
  _x = _x + _w
  @frames_right[_name].each{|i|
    if @frames[i].visible
      @frames[i].obj.place('x' =>_x)
      _x = _x + @frames[i].objp.w
    end
  }
end