Label.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require "Polycode/Image"
  2. class "Label" (Image)
  3. ANTIALIAS_FULL = 0
  4. ANTIALIAS_NONE = 1
  5. function Label:Label(...)
  6. for k,v in pairs(arg) do
  7. if type(v) == "table" then
  8. if v.__ptr ~= nil then
  9. arg[k] = v.__ptr
  10. end
  11. end
  12. end
  13. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  14. self.__ptr = Polycore.Label(unpack(arg))
  15. Polycore.__ptr_lookup[self.__ptr] = self
  16. end
  17. end
  18. function Label:setText(text)
  19. local retVal = Polycore.Label_setText(self.__ptr, text)
  20. end
  21. function Label:getText()
  22. local retVal = Polycore.Label_getText(self.__ptr)
  23. return retVal
  24. end
  25. function Label:getTextWidth(font, text, size)
  26. local retVal = Polycore.Label_getTextWidth(self.__ptr, font.__ptr, text, size)
  27. return retVal
  28. end
  29. function Label:getTextHeight(font, text, size)
  30. local retVal = Polycore.Label_getTextHeight(self.__ptr, font.__ptr, text, size)
  31. return retVal
  32. end
  33. function Label:getFont()
  34. local retVal = Polycore.Label_getFont(self.__ptr)
  35. if Polycore.__ptr_lookup[retVal] ~= nil then
  36. return Polycore.__ptr_lookup[retVal]
  37. else
  38. Polycore.__ptr_lookup[retVal] = Font("__skip_ptr__")
  39. Polycore.__ptr_lookup[retVal].__ptr = retVal
  40. return Polycore.__ptr_lookup[retVal]
  41. end
  42. end