< Components | UserGuide | Graphics >


GUICallbacks

Most components allow interaction with the user and you can overload certain functions to be called once an action occures.

We can "overload" functions of instances of classes. Some classes like the button class provide dummy functions that can be easily overwritten without calling the parent function (which is overwritten):

---% Code tested with Luxinia 0.95 build Nov 15 2006
---% at 11/17/06 12:49:59

  -- create a Button at 10,10 width width=100 and height=20
btn = Button:new(10,10,100,20,"Hello World")
  -- add Button to rootcontainer to make it visible
Container.getRootContainer():add(btn) 

  -- overload the onClicked function from the button
  -- which is called every time when the button is clicked
function btn:onClicked()
  print("Hello World")
end

However, in some cases, it is necessary to call the parent function in order not to break the functionality:

---% Code tested with Luxinia 0.95 build Nov 15 2006
---% at 11/16/06 22:35:27

  -- create a textfield at 10,10
tx = TextField:new(10,10,100,20)
tx:setText("OK")

  -- overload the onKeyTyped event
function tx:onKeyTyped (keyevent)
    -- call the parent function first
  TextField.onKeyTyped(self,keyevent)

    -- if enter was pressed, let's print out the text
    -- and reset the textfield
  if keyevent.key == "\n" then
    print(tx:getText())
    tx:setText("")
  end
end

  -- add it to the rootcontainer
Container.getRootContainer():add(tx)