From 54f9222990985cec2e48ab6d41a1963d4d613141 Mon Sep 17 00:00:00 2001 From: hryx Date: Fri, 29 Mar 2013 19:01:59 -0700 Subject: 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. --- style-default.lua | 7 +++++-- 1 file 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) -- cgit v1.2.3-54-g00ecf