require "phi" ; include Phi

form = Form.new :form , "Form#active_control .. hit TAB key"

edit1 = Edit.new form , :edit1 , "edit1"
edit2 = Edit.new form , :edit2 , "edit2"
edit3 = Edit.new form , :edit3 , "edit3"
button = Button.new form , :button , "button"

timer = Timer.new
## puts timer.methods.sort
timer.interval = 50
timer.on_timer = proc {
  edit = form.active_control
  ##break if not edit.is_a? Edit
  if     ( ( edit.top == 0 ) and 
           ( edit.left + edit.width < form.client_width ) ) or
         (   edit.left < 0 )
    edit.left += 1
  elsif  ( ( edit.left + edit.width  == form.client_width  ) and 
           ( edit.top  + edit.height <  form.client_height ) ) or
         (   edit.top < 0 )
    edit.top += 1
  elsif  ( ( edit.top  + edit.height == form.client_height ) and
           ( edit.left > 0 ) ) or
         ( edit.left + edit.width > form.client_width )
    edit.left -= 1
  else
    edit.top -= 1
  end
}

form.show ; mainloop
