Compare commits
2 commits
5b3dcdad9c
...
07a1731419
Author | SHA1 | Date | |
---|---|---|---|
|
07a1731419 | ||
|
45a4b65053 |
3 changed files with 17 additions and 4 deletions
|
@ -6,6 +6,7 @@ return function(core, text, ...)
|
||||||
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
||||||
opt.id = opt.id or text
|
opt.id = opt.id or text
|
||||||
opt.font = opt.font or love.graphics.getFont()
|
opt.font = opt.font or love.graphics.getFont()
|
||||||
|
opt.color = opt.color or core.theme.color
|
||||||
|
|
||||||
w = w or opt.font:getWidth(text) + 4
|
w = w or opt.font:getWidth(text) + 4
|
||||||
h = h or opt.font:getHeight() + 4
|
h = h or opt.font:getHeight() + 4
|
||||||
|
|
|
@ -6,6 +6,7 @@ return function(core, text, ...)
|
||||||
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
||||||
opt.id = opt.id or text
|
opt.id = opt.id or text
|
||||||
opt.font = opt.font or love.graphics.getFont()
|
opt.font = opt.font or love.graphics.getFont()
|
||||||
|
opt.color = opt.color or core.theme.color
|
||||||
|
|
||||||
w = w or opt.font:getWidth(text) + 4
|
w = w or opt.font:getWidth(text) + 4
|
||||||
h = h or opt.font:getHeight() + 4
|
h = h or opt.font:getHeight() + 4
|
||||||
|
|
19
theme.lua
19
theme.lua
|
@ -18,14 +18,25 @@ function theme.getColorForState(opt)
|
||||||
return (opt.color and opt.color[opt.state]) or theme.color[s]
|
return (opt.color and opt.color[opt.state]) or theme.color[s]
|
||||||
end
|
end
|
||||||
|
|
||||||
function theme.drawBox(x,y,w,h, colors, cornerRadius, outline)
|
function theme.drawBox(x,y,w,h, colors, cornerRadius, outline, scale)
|
||||||
colors = colors or theme.getColorForState(opt)
|
colors = colors or theme.getColorForState(opt)
|
||||||
cornerRadius = cornerRadius or theme.cornerRadius
|
cornerRadius = (cornerRadius or theme.cornerRadius)
|
||||||
w = math.max(cornerRadius/2, w)
|
w = math.max(cornerRadius/2, w)
|
||||||
if h < cornerRadius/2 then
|
if h < cornerRadius/2 then
|
||||||
y,h = y - (cornerRadius - h), cornerRadius/2
|
y,h = y - (cornerRadius - h), cornerRadius/2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- by default, scale will operate about the center of the box. meaning it grows
|
||||||
|
-- out/in in all directions
|
||||||
|
if scale and scale ~= 1.0 then
|
||||||
|
local baseW, baseH = w, h
|
||||||
|
w = w * scale
|
||||||
|
h = h * scale
|
||||||
|
x = x - (w - baseW) / 2
|
||||||
|
y = y - (h - baseH) / 2
|
||||||
|
cornerRadius = cornerRadius * scale
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.setColor(colors.bg)
|
love.graphics.setColor(colors.bg)
|
||||||
love.graphics.rectangle('fill', x,y, w,h, cornerRadius)
|
love.graphics.rectangle('fill', x,y, w,h, cornerRadius)
|
||||||
if outline ~= nil then
|
if outline ~= nil then
|
||||||
|
@ -56,13 +67,13 @@ end
|
||||||
|
|
||||||
function theme.Button(text, opt, x,y,w,h)
|
function theme.Button(text, opt, x,y,w,h)
|
||||||
local c = theme.getColorForState(opt)
|
local c = theme.getColorForState(opt)
|
||||||
|
local scale = opt.scale or 1.0
|
||||||
|
|
||||||
theme.drawBox(x,y,w,h, c, opt.cornerRadius, opt.outline)
|
theme.drawBox(x,y,w,h, c, opt.cornerRadius, opt.outline, scale)
|
||||||
love.graphics.setColor(c.fg)
|
love.graphics.setColor(c.fg)
|
||||||
love.graphics.setFont(opt.font)
|
love.graphics.setFont(opt.font)
|
||||||
|
|
||||||
-- ensure text remains aligned regardless of scale
|
-- ensure text remains aligned regardless of scale
|
||||||
local scale = opt.scale or 1.0
|
|
||||||
local align = opt.align or "center"
|
local align = opt.align or "center"
|
||||||
local textX = x
|
local textX = x
|
||||||
local textY = y
|
local textY = y
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue