feat: add a way to colorize widgets
This commit is contained in:
parent
dbdc2b9b18
commit
5c0f4dd48a
4 changed files with 15 additions and 3 deletions
|
@ -130,17 +130,20 @@ end
|
|||
-- TEXT WIDGET
|
||||
-- Simple text widget
|
||||
|
||||
function TextWidget:new(menu, font, label)
|
||||
function TextWidget:new(menu, font, label, color)
|
||||
TextWidget.super.new(self, menu)
|
||||
self.font = font
|
||||
self.label = label
|
||||
self.color = color or {1, 1, 1}
|
||||
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:setColor(self.color[1], self.color[2], self.color[3], 1)
|
||||
self.font:draw(self.label, w, h, -1, "center")
|
||||
self.font:setColor(1, 1, 1, 1)
|
||||
end
|
||||
|
||||
-- Add the widget as subvariable to the returned table
|
||||
|
|
|
@ -52,8 +52,11 @@ end
|
|||
function fancy.BaseWidget:drawCanvas()
|
||||
love.graphics.draw(self.box, 0, 0)
|
||||
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2
|
||||
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
|
||||
self.font:draw(self.label, 16, h, -1, "left")
|
||||
self.font:draw(self.label2, self.width -8, h, -1, "right")
|
||||
self.font:setColor(1, 1, 1, 1)
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
-- Widget de sous-menu
|
||||
|
|
|
@ -123,7 +123,10 @@ end
|
|||
|
||||
function list.CenteredWidget:drawCanvas()
|
||||
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2
|
||||
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
|
||||
self.font:draw(self.label, self.width / 2, h, -1, "center")
|
||||
self.font:setColor(1, 1, 1, 1)
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
-- Widget avec deux bouts de textes
|
||||
|
@ -134,8 +137,11 @@ end
|
|||
|
||||
function list.DualTextWidget:drawCanvas()
|
||||
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
|
||||
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
|
||||
self.font:draw(self.label, 16, h, -1, "left")
|
||||
self.font:draw(self.label2, self.width - 8, h, -1, "right")
|
||||
self.font:setColor(1, 1, 1, 1)
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
-- Widget de sous-menu
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
local Widget = require "core.modules.menusystem.widgets"
|
||||
local RadianceWidget = Widget.Text:extend()
|
||||
|
||||
function RadianceWidget:new(scene, name, label)
|
||||
function RadianceWidget:new(scene, name, label, color)
|
||||
self.scene = scene
|
||||
local label = label or ""
|
||||
local font = scene.assets.fonts["small"]
|
||||
font:setFilter("shadow")
|
||||
local widgetMenu = scene.menusystem.menus[name]
|
||||
RadianceWidget.super.new(self, widgetMenu, font, label)
|
||||
RadianceWidget.super.new(self, widgetMenu, font, label, color)
|
||||
end
|
||||
|
||||
return RadianceWidget
|
||||
|
|
Loading…
Reference in a new issue