aboutsummaryrefslogtreecommitdiffstats
path: root/style-default.lua
diff options
context:
space:
mode:
authorMatthias Richter <matthias.richter@iosb.fraunhofer.de>2013-12-11 15:19:04 +0100
committerMatthias Richter <matthias.richter@iosb.fraunhofer.de>2013-12-11 15:25:06 +0100
commit66a089a07f4d24557cb8e06f78eefb07a344ea32 (patch)
tree9e9fbaa80393cb50d5fa05b94098a1a99717d5ec /style-default.lua
parentffd187dc177f4a15fa2e87579b9cbabee38b8245 (diff)
downloadQuickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.gz
Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.bz2
Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.xz
Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.zip
Fix bug in input.lua, make 0.9-ready, add utf8 editing
1) [input.lua] Pressing backspace while the cursor was at the beggining of the text removed the first character. Fixed thanks to riidom. 2) [LÖVE 0.9] Use setLine(Width|Style) instead of setLine. Split keyboard.pressed() into keyboard.pressed() and keyboard.textinput(). (see readme) 3) [utf8.lua] Add support for UTF-8 text editing. May still fail spectacurlarly with invalid UTF-8 strings.
Diffstat (limited to 'style-default.lua')
-rw-r--r--style-default.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/style-default.lua b/style-default.lua
index e970d7a..71f412a 100644
--- a/style-default.lua
+++ b/style-default.lua
@@ -24,6 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]--
+local BASE = (...):match("(.-)[^%.]+$")
+local utf8 = require(BASE .. 'utf8')
+
-- default style
local color = {
normal = {bg = {78,78,78}, fg = {200,200,200}, border={20,20,20}},
@@ -43,7 +46,8 @@ end
gradient:set(200,255)
local function box(x,y,w,h, bg, border, flip)
- love.graphics.setLine(1, 'rough')
+ love.graphics.setLineWidth(1)
+ love.graphics.setLineStyle('rough')
love.graphics.setColor(bg)
local sy = flip and -h/2 or h/2
@@ -82,7 +86,8 @@ end
local function Slider(state, fraction, vertical, x,y,w,h)
local c = color[state]
- love.graphics.setLine(1, 'rough')
+ love.graphics.setLineWidth(1)
+ love.graphics.setLineStyle('rough')
love.graphics.setColor(c.bg)
if vertical then
love.graphics.rectangle('fill', x+w/2-2,y,4,h)
@@ -105,7 +110,8 @@ local function Slider2D(state, fraction, x,y,w,h)
box(x,y,w,h, c.bg, c.border)
-- draw quadrants
- love.graphics.setLine(1, 'rough')
+ love.graphics.setLineWidth(1)
+ love.graphics.setLineStyle('rough')
love.graphics.setColor(c.fg[1], c.fg[2], c.fg[3], math.min(127,c.fg[4] or 255))
love.graphics.line(x+w/2,y, x+w/2,y+h)
love.graphics.line(x,y+h/2, x+w,y+h/2)
@@ -124,7 +130,7 @@ local function Input(state, text, cursor, x,y,w,h)
local f = love.graphics.getFont()
local th = f:getHeight(text)
- local cursorPos = x + 2 + f:getWidth(text:sub(1,cursor))
+ local cursorPos = x + 2 + f:getWidth(utf8.sub(text, 1,cursor))
local offset = 2 - math.floor((cursorPos-x) / (w-4)) * (w-4)
local tsx,tsy,tsw,tsh = x+1, y, w-2, h
@@ -139,7 +145,8 @@ local function Input(state, text, cursor, x,y,w,h)
end
love.graphics.setScissor(tsx, tsy, tsw, tsh)
- love.graphics.setLine(1, 'rough')
+ love.graphics.setLineWidth(1)
+ love.graphics.setLineStyle('rough')
love.graphics.setColor(color.normal.fg)
love.graphics.print(text, x+offset,y+(h-th)/2)
if state ~= 'normal' then