aboutsummaryrefslogtreecommitdiffstats
path: root/label.lua
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2012-05-09 21:27:45 +0200
committerMatthias Richter <vrld@vrld.org>2012-05-09 21:27:45 +0200
commitadc78875875a64d40b4cf65a8618fb49a77e8080 (patch)
tree132bc89a60cf3bc60cf9acacdf0c31aad6df969e /label.lua
parent7b1b6e4176829d4c9d897821c8a2d51da78e0243 (diff)
downloadQuickie-adc78875875a64d40b4cf65a8618fb49a77e8080.tar.gz
Quickie-adc78875875a64d40b4cf65a8618fb49a77e8080.tar.bz2
Quickie-adc78875875a64d40b4cf65a8618fb49a77e8080.tar.xz
Quickie-adc78875875a64d40b4cf65a8618fb49a77e8080.zip
Mega update: Auto layout, code cleanup, api change.
Basically half a rewrite.
Diffstat (limited to 'label.lua')
-rw-r--r--label.lua36
1 files changed, 31 insertions, 5 deletions
diff --git a/label.lua b/label.lua
index ed7ad80..62b3950 100644
--- a/label.lua
+++ b/label.lua
@@ -24,12 +24,38 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]--
-local core = require((...):match("(.-)[^%.]+$") .. 'core')
+local BASE = (...):match("(.-)[^%.]+$")
+local core = require(BASE .. 'core')
+local group = require(BASE .. 'group')
+local mouse = require(BASE .. 'mouse')
+local keyboard = require(BASE .. 'keyboard')
+
+-- {text = text, align = align, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
+return function(w)
+ assert(type(w) == "table" and w.text, "Invalid argument")
+ w.align = w.align or 'left'
+
+ local tight = w.size and (w.size[1] == 'tight' or w.size[2] == 'tight')
+ if tight then
+ local f = assert(love.graphics.getFont())
+ if w.size[1] == 'tight' then
+ w.size[1] = f:getWidth(w.text)
+ end
+ if w.size[2] == 'tight' then
+ w.size[2] = f:getHeight(w.text)
+ end
+ end
-return function(text, x,y,w,h,align, draw)
local id = core.generateID()
- w, h, align = w or 0, h or 0, align or 'left'
- core.registerDraw(id, draw or core.style.Label, text,x,y,w,h,align)
- return false
+ local pos, size = group.getRect(w.pos, w.size)
+
+ if keyboard.hasFocus(id) then
+ keyboard.clearFocus()
+ end
+
+ core.registerDraw(id, draw or core.style.Label,
+ w.text, w.align, pos[1],pos[2], size[1],size[2])
+
+ return mouse.releasedOn(id)
end