From 4f3d285218ff73d38c4dda8b6ca212c61f3b3390 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 16 Jan 2016 02:33:41 +0100 Subject: [PATCH] Allow to overwrite draw function per widget --- button.lua | 2 +- checkbox.lua | 2 +- docs/index.rst | 3 +++ docs/layout.rst | 2 +- docs/widgets.rst | 4 +++- imagebutton.lua | 6 ++++-- input.lua | 2 +- label.lua | 2 +- slider.lua | 2 +- 9 files changed, 16 insertions(+), 9 deletions(-) diff --git a/button.lua b/button.lua index e985f06..c063ffa 100644 --- a/button.lua +++ b/button.lua @@ -11,7 +11,7 @@ return function(core, text, ...) h = h or opt.font:getHeight() + 4 opt.state = core:registerHitbox(opt.id, x,y,w,h) - core:registerDraw(core.theme.Button, text, opt, x,y,w,h) + core:registerDraw(opt.draw or core.theme.Button, text, opt, x,y,w,h) return { id = opt.id, diff --git a/checkbox.lua b/checkbox.lua index ce6b357..5244c4f 100644 --- a/checkbox.lua +++ b/checkbox.lua @@ -15,7 +15,7 @@ return function(core, checkbox, ...) if hit then checkbox.checked = not checkbox.checked end - core:registerDraw(core.theme.Checkbox, checkbox, opt, x,y,w,h) + core:registerDraw(opt.draw or core.theme.Checkbox, checkbox, opt, x,y,w,h) return { id = opt.id, diff --git a/docs/index.rst b/docs/index.rst index 830b19f..bfb3156 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -111,6 +111,9 @@ The following code will create this UI: -- nested content, whichever is bigger suit.layout:push(suit.layout:row()) + -- change cell padding to 3 pixels in either direction + suit.layout:padding(3) + -- put a slider in the cell -- the inner cell will be 160 px wide and 20 px high suit.Slider(slider, suit.layout:col(160, 20)) diff --git a/docs/layout.rst b/docs/layout.rst index 9b10f1b..d2f97ea 100644 --- a/docs/layout.rst +++ b/docs/layout.rst @@ -116,7 +116,7 @@ Used to provide the last four arguments to a widget, e.g.:: Precomputed Layouts ------------------- +------------------- Apart from immediate mode layouts, you can specify layouts in advance. The specification is a table of tables, where each inner table follows the diff --git a/docs/widgets.rst b/docs/widgets.rst index bac5bc9..3f2fb44 100644 --- a/docs/widgets.rst +++ b/docs/widgets.rst @@ -164,8 +164,10 @@ Common Options ``"bottom"``. Defaults to ``"middle"``. ``color`` - Table overwriting the color. Undefined colors default to the theme colors. + A table to overwrite the color. Undefined colors default to the theme colors. +``draw`` + A function to replace the drawing function. Refer to :doc:`themes` for more information about the function signatures. Common Return States diff --git a/imagebutton.lua b/imagebutton.lua index f34ca83..0cf544a 100644 --- a/imagebutton.lua +++ b/imagebutton.lua @@ -28,8 +28,10 @@ return function(core, normal, ...) img = opt.hovered end - core:registerDraw(love.graphics.setColor, 255,255,255) - core:registerDraw(love.graphics.draw, img, x,y) + core:registerDraw(opt.draw or function(img,x,y, r,g,b,a) + love.graphics.setColor(r,g,b,a) + love.graphics.draw(img,x,y) + end, img, x,y, love.graphics.getColor()) return { id = opt.id, diff --git a/input.lua b/input.lua index ff2d842..ba0737e 100644 --- a/input.lua +++ b/input.lua @@ -86,7 +86,7 @@ return function(core, input, ...) input.drawoffset = text_width - w end - core:registerDraw(core.theme.Input, input, opt, x,y,w,h) + core:registerDraw(opt.draw or core.theme.Input, input, opt, x,y,w,h) return { id = opt.id, diff --git a/label.lua b/label.lua index 57ba5c1..9f45a86 100644 --- a/label.lua +++ b/label.lua @@ -11,7 +11,7 @@ return function(core, text, ...) h = h or opt.font:getHeight() + 4 opt.state = core:registerHitbox(opt.id, x,y,w,h) - core:registerDraw(core.theme.Label, text, opt, x,y,w,h) + core:registerDraw(opt.draw or core.theme.Label, text, opt, x,y,w,h) return { id = opt.id, diff --git a/slider.lua b/slider.lua index db25faf..d540348 100644 --- a/slider.lua +++ b/slider.lua @@ -41,7 +41,7 @@ return function(core, info, ...) end end - core:registerDraw(core.theme.Slider, fraction, opt, x,y,w,h) + core:registerDraw(opt.draw or core.theme.Slider, fraction, opt, x,y,w,h) return { id = opt.id,