local Element = require("gfx.element")
local Text = Element:new{ text = "" }

function Text:new(o)
  o.width = nil
  o.height = nil

  return Element.new(self, o)
end

function Text:setText(text)
  local current = self:getText()
  if current ~= text then
    self:setDirty()

    local needReload = #current ~= #text
    self.text = text
    if needReload then
        self:_reload()
    end
  end
end

function Text:getText()
  return self.text
end

function Text:draw()
  local dirty = Element.draw(self)
  if dirty then
    self:_getWindow().write(self:getText())
  end
  return dirty
end

function Text:getHeight()
  return 1
end

function Text:getWidth()
  return #self:getText()
end

function Text:setWidth()
  
end

function Text:setHeight()
  
end

function Text:resize()
  
end

return Text