core/menusystem: add a basic text widget

This commit is contained in:
Kazhnuz 2019-02-15 18:26:45 +01:00
parent b98bf1af67
commit 1cc8acd4c3

View file

@ -1,6 +1,7 @@
local Widget = {} local Widget = {}
BaseWidget = Object:extend() BaseWidget = Object:extend()
TextWidget = BaseWidget:extend()
function BaseWidget:new(menu) function BaseWidget:new(menu)
self.menu = menu self.menu = menu
@ -75,6 +76,23 @@ function BaseWidget:destroy()
self.destroyed = true self.destroyed = true
end end
-- Simple text widget
function TextWidget:new(menu, font, label)
TextWidget.super.new(self, menu)
self.font = font
self.label = label
end
function TextWidget:drawCanvas()
local w, h
w = math.floor(self.width / 2)
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:draw(self.label, w, h, -1, "center")
end
Widget.Base = BaseWidget Widget.Base = BaseWidget
Widget.Text = TextWidget
return Widget return Widget