From 1162c0f864ac16db72c76695d48c2578d799e780 Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:26:48 -0500 Subject: [PATCH 1/5] Update README.md Added key repeat option for classic GUI backspace --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b900540..d015ee7 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ local suit = require 'suit' -- storage for text input local input = {text = ""} +-- By default, backspace only registers once, if you want classic GUI backspace that keeps going when pushed down +-- Add this line: love.keyboard.setKeyRepeat(true) + -- all the UI is defined in love.update or functions that are called from here function love.update(dt) -- put the layout origin at position (100,100) From 2fa2d4ca7316c8db13cbe62f54d79665c5f782ac Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:27:25 -0500 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d015ee7..61af2c5 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ local suit = require 'suit' -- storage for text input local input = {text = ""} --- By default, backspace only registers once, if you want classic GUI backspace that keeps going when pushed down --- Add this line: love.keyboard.setKeyRepeat(true) +-- By default, backspace only registers once, if you want classic GUI backspace that +-- Keeps going when pushed down, add this line: love.keyboard.setKeyRepeat(true) -- all the UI is defined in love.update or functions that are called from here function love.update(dt) From 5e097ae6a7b2662c71d4a9064b06e40f4c0f957e Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:28:01 -0500 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61af2c5..fb901ed 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ local suit = require 'suit' local input = {text = ""} -- By default, backspace only registers once, if you want classic GUI backspace that --- Keeps going when pushed down, add this line: love.keyboard.setKeyRepeat(true) +-- Keeps removing chars when pushed down, add this line: love.keyboard.setKeyRepeat(true) -- all the UI is defined in love.update or functions that are called from here function love.update(dt) From 8404c2ff79a7669c115b36ab5aa7aad34d850b5f Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:33:10 -0500 Subject: [PATCH 4/5] Added both password and label support Label is set only once when the focus is not on the box, it can also be reset by setting the label again (the label is set to "" when the focus is on the input) Password can also be toggled on and off depending on your needs --- input.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/input.lua b/input.lua index 5262c2b..7a848f3 100644 --- a/input.lua +++ b/input.lua @@ -17,7 +17,10 @@ return function(core, input, ...) w = w or text_width + 6 h = h or opt.font:getHeight() + 4 + input.label = input.label or "" + input.password = input.password or false input.text = input.text or "" + if input.label ~= "" then input.text = input.label end input.cursor = math.max(1, math.min(utf8.len(input.text)+1, input.cursor or utf8.len(input.text)+1)) -- cursor is position *before* the character (including EOS) i.e. in "hello": -- position 1: |hello @@ -29,7 +32,8 @@ return function(core, input, ...) opt.cursor_pos = 0 if input.cursor > 1 then local s = input.text:sub(1, utf8.offset(input.text, input.cursor)-1) - opt.cursor_pos = opt.font:getWidth(s) + if password then opt.cursor_pos = opt.font:getWidth(string.rep("*", string.len(input.text))) + else opt.cursor_pos = opt.font:getWidth(s) end end -- compute drawing offset @@ -53,6 +57,7 @@ return function(core, input, ...) opt.hasKeyboardFocus = core:grabKeyboardFocus(opt.id) if opt.hasKeyboardFocus then + if input.label ~= "" then input.text = "" input.label = "" input.cursor = 1 end local keycode,char = core:getPressedKey() -- text input if char and char ~= "" then From 155eb193b53791aee95853475ae3c793c03b712d Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:34:02 -0500 Subject: [PATCH 5/5] Update theme.lua --- theme.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/theme.lua b/theme.lua index fe8b416..4c423df 100644 --- a/theme.lua +++ b/theme.lua @@ -121,7 +121,12 @@ function theme.Input(input, opt, x,y,w,h) -- text love.graphics.setColor((opt.color and opt.color.normal and opt.color.normal.fg) or theme.color.normal.fg) love.graphics.setFont(opt.font) - love.graphics.print(input.text, x, y+(h-th)/2) + if not input.password then love.graphics.print(input.text, x, y+(h-th)/2) end + if input.password and input.text ~= input.label then + love.graphics.print(string.rep("*", string.len(input.text)), x, y+(h-th)/2) + else + love.graphics.print(input.text, x, y+(h-th)/2) + end -- cursor if opt.hasKeyboardFocus and (love.timer.getTime() % 1) > .5 then