feat: add a way to colorize widgets

This commit is contained in:
Kazhnuz 2021-03-13 17:26:36 +01:00
parent dbdc2b9b18
commit 5c0f4dd48a
4 changed files with 15 additions and 3 deletions

View file

@ -130,17 +130,20 @@ end
-- TEXT WIDGET -- TEXT WIDGET
-- Simple text widget -- Simple text widget
function TextWidget:new(menu, font, label) function TextWidget:new(menu, font, label, color)
TextWidget.super.new(self, menu) TextWidget.super.new(self, menu)
self.font = font self.font = font
self.label = label self.label = label
self.color = color or {1, 1, 1}
end end
function TextWidget:drawCanvas() function TextWidget:drawCanvas()
local w, h local w, h
w = math.floor(self.width / 2) w = math.floor(self.width / 2)
h = math.floor(self.height / 2) - (self.font:getHeight() / 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:draw(self.label, w, h, -1, "center")
self.font:setColor(1, 1, 1, 1)
end end
-- Add the widget as subvariable to the returned table -- Add the widget as subvariable to the returned table

View file

@ -52,8 +52,11 @@ end
function fancy.BaseWidget:drawCanvas() function fancy.BaseWidget:drawCanvas()
love.graphics.draw(self.box, 0, 0) love.graphics.draw(self.box, 0, 0)
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2 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.label, 16, h, -1, "left")
self.font:draw(self.label2, self.width -8, h, -1, "right") self.font:draw(self.label2, self.width -8, h, -1, "right")
self.font:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end end
-- Widget de sous-menu -- Widget de sous-menu

View file

@ -123,7 +123,10 @@ end
function list.CenteredWidget:drawCanvas() function list.CenteredWidget:drawCanvas()
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2 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:draw(self.label, self.width / 2, h, -1, "center")
self.font:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end end
-- Widget avec deux bouts de textes -- Widget avec deux bouts de textes
@ -134,8 +137,11 @@ end
function list.DualTextWidget:drawCanvas() function list.DualTextWidget:drawCanvas()
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) 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.label, 16, h, -1, "left")
self.font:draw(self.label2, self.width - 8, h, -1, "right") self.font:draw(self.label2, self.width - 8, h, -1, "right")
self.font:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end end
-- Widget de sous-menu -- Widget de sous-menu

View file

@ -1,13 +1,13 @@
local Widget = require "core.modules.menusystem.widgets" local Widget = require "core.modules.menusystem.widgets"
local RadianceWidget = Widget.Text:extend() local RadianceWidget = Widget.Text:extend()
function RadianceWidget:new(scene, name, label) function RadianceWidget:new(scene, name, label, color)
self.scene = scene self.scene = scene
local label = label or "" local label = label or ""
local font = scene.assets.fonts["small"] local font = scene.assets.fonts["small"]
font:setFilter("shadow") font:setFilter("shadow")
local widgetMenu = scene.menusystem.menus[name] local widgetMenu = scene.menusystem.menus[name]
RadianceWidget.super.new(self, widgetMenu, font, label) RadianceWidget.super.new(self, widgetMenu, font, label, color)
end end
return RadianceWidget return RadianceWidget