diff options
author | Matthias Richter <vrld@vrld.org> | 2012-05-09 21:27:45 +0200 |
---|---|---|
committer | Matthias Richter <vrld@vrld.org> | 2012-05-09 21:27:45 +0200 |
commit | adc78875875a64d40b4cf65a8618fb49a77e8080 (patch) | |
tree | 132bc89a60cf3bc60cf9acacdf0c31aad6df969e /label.lua | |
parent | 7b1b6e4176829d4c9d897821c8a2d51da78e0243 (diff) | |
download | Quickie-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.lua | 36 |
1 files changed, 31 insertions, 5 deletions
@@ -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 |