From 5298f31d06d277b31e0835cb8407db6cc38a5570 Mon Sep 17 00:00:00 2001 From: Andrew Minnich Date: Sat, 5 Mar 2016 16:13:04 -0500 Subject: [PATCH 1/2] Have theme.drawBox take options argument It can optionally still take a colors argument. --- theme.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/theme.lua b/theme.lua index 0f69a45..ea26e8a 100644 --- a/theme.lua +++ b/theme.lua @@ -18,7 +18,8 @@ function theme.getColorForState(opt) return (opt.color and opt.color[opt.state]) or theme.color[s] end -function theme.drawBox(x,y,w,h, colors) +function theme.drawBox(x,y,w,h, opt, colors) + local colors = colors or theme.getColorForState(opt) love.graphics.setColor(colors.bg) love.graphics.rectangle('fill', x,y, w,h, theme.cornerRadius) end @@ -45,7 +46,7 @@ end function theme.Button(text, opt, x,y,w,h) local c = theme.getColorForState(opt) - theme.drawBox(x,y,w,h, c) + theme.drawBox(x,y,w,h, opt) love.graphics.setColor(c.fg) love.graphics.setFont(opt.font) @@ -57,7 +58,7 @@ function theme.Checkbox(chk, opt, x,y,w,h) local c = theme.getColorForState(opt) local th = opt.font:getHeight() - theme.drawBox(x+h/10,y+h/10,h*.8,h*.8, c) + theme.drawBox(x+h/10,y+h/10,h*.8,h*.8, opt) love.graphics.setColor(c.fg) if chk.checked then love.graphics.setLineStyle('smooth') @@ -85,8 +86,8 @@ function theme.Slider(fraction, opt, x,y,w,h) end local c = theme.getColorForState(opt) - theme.drawBox(x,y,w,h, c) - theme.drawBox(x,yb,wb,hb, {bg=c.fg}) + theme.drawBox(x,y,w,h, opt) + theme.drawBox(x,yb,wb,hb, opt, {bg=c.fg}) if opt.state ~= nil and opt.state ~= "normal" then love.graphics.setColor((opt.color and opt.color.active or {}).fg or theme.color.active.fg) @@ -100,7 +101,7 @@ end function theme.Input(input, opt, x,y,w,h) local utf8 = require 'utf8' - theme.drawBox(x,y,w,h, (opt.color and opt.color.normal) or theme.color.normal) + theme.drawBox(x,y,w,h, opt, (opt.color and opt.color.normal) or theme.color.normal) x = x + 3 w = w - 6 From 01f7cd88fb0d145af16bdc77681626a15891c4e1 Mon Sep 17 00:00:00 2001 From: Andrew Minnich Date: Sat, 5 Mar 2016 16:20:43 -0500 Subject: [PATCH 2/2] Add cornerRadius option to override theme corner radius --- docs/widgets.rst | 3 +++ theme.lua | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/widgets.rst b/docs/widgets.rst index 3f2fb44..0e78a0c 100644 --- a/docs/widgets.rst +++ b/docs/widgets.rst @@ -166,6 +166,9 @@ Common Options ``color`` A table to overwrite the color. Undefined colors default to the theme colors. +``cornerRadius`` + The corner radius for boxes. Overwrites the theme corner radius. + ``draw`` A function to replace the drawing function. Refer to :doc:`themes` for more information about the function signatures. diff --git a/theme.lua b/theme.lua index ea26e8a..2318319 100644 --- a/theme.lua +++ b/theme.lua @@ -20,8 +20,10 @@ end function theme.drawBox(x,y,w,h, opt, colors) local colors = colors or theme.getColorForState(opt) + local cornerRadius = opt.cornerRadius or theme.cornerRadius + love.graphics.setColor(colors.bg) - love.graphics.rectangle('fill', x,y, w,h, theme.cornerRadius) + love.graphics.rectangle('fill', x,y, w,h, cornerRadius) end function theme.getVerticalOffsetForAlign(valign, font, h)