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.
This commit is contained in:
parent
5827cd2527
commit
54f9222990
1 changed files with 5 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue