Skip to content

Instantly share code, notes, and snippets.

@pakeke-constructor
Last active December 15, 2021 08:51
Show Gist options
  • Save pakeke-constructor/331f84cc1cfad7c74dcc3364c44979d6 to your computer and use it in GitHub Desktop.
Save pakeke-constructor/331f84cc1cfad7c74dcc3364c44979d6 to your computer and use it in GitHub Desktop.
local useInput = require("libs.nm_helium.shell.input")
return helium(function(param, view)
local textinput
textinput = useInput(function(fintxt)
if param.parse then
textinput.text = param.parse(textinput.text)
end
if param.text_update then
param.text_update(textinput.text)
end
end, nil, "")
assert(param.prompt_text)
local prompt_text = param.prompt_text
return function()
local prompt_w = love.graphics.getFont():getWidth(prompt_text) + 4
local prompt_h = love.graphics.getFont():getHeight(prompt_text)
local view_w = view.w - prompt_w
local view_h = view.h
local fintext = textinput.text
love.graphics.setLineWidth(2)
love.graphics.setColor(0.45,0.45,0.45, 0.5)
love.graphics.rectangle("fill", 3, 3, prompt_w - 6, view.h - 4)
if textinput.focused then
love.graphics.setColor(0,1,0, 1)
else
love.graphics.setColor(0.768, 0.768, 0.768, 1)
end
love.graphics.rectangle("line", 2, 2, prompt_w - 4, view.h - 4)
local px, py = 8, view.h / 2 - prompt_h / 2
love.graphics.setColor(0.1,0.1,0.1)
love.graphics.print(prompt_text, px, py)
love.graphics.setColor(1,1,1)
if textinput.focused then
love.graphics.setColor(0, 1, 0)
else
love.graphics.setColor(0.8,0.8,0.8)
end
love.graphics.print(prompt_text, px+2, py+2)
if textinput.focused then
love.graphics.setColor(0.4,0.5,0.4)
love.graphics.rectangle('fill', prompt_w + 3, 3, view_w -6, view_h -6)
love.graphics.setColor(0, 1, 0)
love.graphics.rectangle('line', prompt_w + 2, 2, view_w-4, view_h-4)
fintext = fintext..'@'
else
love.graphics.setColor(0.5,0.5,0.5)
love.graphics.rectangle('fill', prompt_w + 3, 3, view_w-6, view_h-6, 3, 3)
love.graphics.setColor(0.768, 0.768, 0.768)
love.graphics.rectangle('line', prompt_w + 2, 2, view_w-4, view_h-4)
end
love.graphics.setColor(0.1,0.1,0.1)
local tw = love.graphics.getFont():getWidth(fintext)
local th = love.graphics.getFont():getHeight(fintext)
local tx, ty = prompt_w + view_w / 2 - tw / 2, view_h / 2 - th / 2
love.graphics.print(fintext, tx, ty)
if textinput.focused then
love.graphics.setColor(0, 1, 0)
else
love.graphics.setColor(1,1,1)
end
love.graphics.print(fintext, tx + 2, ty + 2)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment