aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhryx <codroid@gmail.com>2013-03-29 19:01:59 -0700
committerhryx <codroid@gmail.com>2013-03-29 19:01:59 -0700
commit54f9222990985cec2e48ab6d41a1963d4d613141 (patch)
tree3a05e054404a88d63f856608e6459aeedb9e722b
parent5827cd2527144db1711ca807e018a405743e3e5f (diff)
downloadQuickie-54f9222990985cec2e48ab6d41a1963d4d613141.tar.gz
Quickie-54f9222990985cec2e48ab6d41a1963d4d613141.tar.bz2
Quickie-54f9222990985cec2e48ab6d41a1963d4d613141.tar.xz
Quickie-54f9222990985cec2e48ab6d41a1963d4d613141.zip
Default Input style handles long text better
Changes to default-style.lua: Prevent text from being drawn past bounding box via love.graphics.setScissor(). The cursor and surrounding text are kept in visible range by calculating a draw offset.
-rw-r--r--style-default.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/style-default.lua b/style-default.lua
index 529c4a2..b1e5d4d 100644
--- a/style-default.lua
+++ b/style-default.lua
@@ -125,14 +125,17 @@ 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 offset = 2 - math.floor((cursorPos-x) / (w-4)) * (w-4)
+ love.graphics.setScissor(x+1,y,w-2,h)
love.graphics.setLine(1, 'rough')
love.graphics.setColor(color.normal.fg)
- love.graphics.print(text, x+2,y+(h-th)/2)
+ love.graphics.print(text, x+offset,y+(h-th)/2)
if state ~= 'normal' then
love.graphics.setColor(color.active.fg)
- love.graphics.line(cursorPos, y+4, cursorPos, y+h-4)
+ love.graphics.line(cursorPos+offset, y+4, cursorPos+offset, y+h-4)
end
+ love.graphics.setScissor()
end
local function Checkbox(state, checked, label, align, x,y,w,h)