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
1 changed files with 18 additions and 0 deletions

View File

@ -1,6 +1,7 @@
local Widget = {}
BaseWidget = Object:extend()
TextWidget = BaseWidget:extend()
function BaseWidget:new(menu)
self.menu = menu
@ -75,6 +76,23 @@ function BaseWidget:destroy()
self.destroyed = true
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.Text = TextWidget
return Widget