aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2012-03-14 14:14:16 +0100
committerMatthias Richter <vrld@vrld.org>2012-03-14 14:14:16 +0100
commit465aaf18853e0e96f4a26642fea884919f9a2f88 (patch)
tree2a0ff552d2bd14886fc94d6a23f387a939788d3f
parent370c10c78770bc3c1a70a086b238e7a8e5197fb9 (diff)
downloadQuickie-465aaf18853e0e96f4a26642fea884919f9a2f88.tar.gz
Quickie-465aaf18853e0e96f4a26642fea884919f9a2f88.tar.bz2
Quickie-465aaf18853e0e96f4a26642fea884919f9a2f88.tar.xz
Quickie-465aaf18853e0e96f4a26642fea884919f9a2f88.zip
Add gui.core.(disable|clear)KeyFocus
-rw-r--r--README.md9
-rw-r--r--core.lua50
2 files changed, 35 insertions, 24 deletions
diff --git a/README.md b/README.md
index 0a4aa0d..478d058 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,11 @@ Quickie is an [immediate mode gui][IMGUI] library for [L&Ouml;VE][LOVE]
-- checkboxes have only a `checked' status
local checkbox = {checked = false}
+ function love.load()
+ -- disable tabbing through the widgets
+ gui.core.disableKeyFocus()
+ end
+
function love.update(dt)
-- widgets are defined by simply calling them. usually a widget returns true if
-- if its value changed or if it was activated (click on button, ...)
@@ -37,8 +42,8 @@ Quickie is an [immediate mode gui][IMGUI] library for [L&Ouml;VE][LOVE]
end
function love.keypressed(key,code)
- -- forward keyboard events to the gui. If you don't want widget tabbing and
- -- input widgets, skip this line
+ -- forward keyboard events to the gui. If you don't want keyboard support
+ -- skip this line
gui.core.keyboard.pressed(key, code)
end
diff --git a/core.lua b/core.lua
index bb5295a..3df98e8 100644
--- a/core.lua
+++ b/core.lua
@@ -17,6 +17,9 @@ local function isActive(id) return context.active == id end
local function setKeyFocus(id) context.keyfocus = id end
local function hasKeyFocus(id) return context.keyfocus == id end
+local function disableKeyFocus() return setKeyFocus{} end
+local function clearKeyFocus() return setKeyFocus(nil) end
+
-- input
local mouse = {x = 0, y = 0, down = false}
local keyboard = {key = nil, code = -1}
@@ -50,7 +53,7 @@ end
function keyboard.tryGrab(id)
if not context.keyfocus then
- context.keyfocus = id
+ setKeyFocus(id)
end
end
@@ -136,25 +139,28 @@ local function draw()
end
return {
- mouse = mouse,
- keyboard = keyboard,
-
- generateID = generateID,
- setHot = setHot,
- setActive = setActive,
- setKeyFocus = setKeyFocus,
- isHot = isHot,
- isActive = isActive,
- hasKeyFocus = hasKeyFocus,
- makeCyclable = makeCyclable,
-
- style = require((...):match("(.-)[^%.]+$") .. '.style-default'),
- color = color,
- registerDraw = registerDraw,
- draw = draw,
-
- strictAnd = strictAnd,
- strictOr = strictOr,
- save_pack = save_pack,
- save_unpack = save_unpack,
+ mouse = mouse,
+ keyboard = keyboard,
+
+ generateID = generateID,
+ setHot = setHot,
+ setActive = setActive,
+ setKeyFocus = setKeyFocus,
+ isHot = isHot,
+ isActive = isActive,
+ hasKeyFocus = hasKeyFocus,
+
+ disableKeyFocus = disableKeyFocus,
+ clearKeyFocus = clearKeyFocus,
+ makeCyclable = makeCyclable,
+
+ style = require((...):match("(.-)[^%.]+$") .. '.style-default'),
+ color = color,
+ registerDraw = registerDraw,
+ draw = draw,
+
+ strictAnd = strictAnd,
+ strictOr = strictOr,
+ save_pack = save_pack,
+ save_unpack = save_unpack,
}