From 67642622e4903f48294b30f8e54382e77668bf5b Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 11:57:49 -0500 Subject: [PATCH 1/2] Updated README To add a note on backspace. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b900540..d638ccd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,16 @@ Here is how SUIT looks like with the default theme: More info and code is over at [readthedocs](http://suit.readthedocs.org/en/latest/). +## Note. + +The default backspace only deletes one character per input and ignores holding down the key + +To get a more classic backspace, add this line into your code: + +```lua +love.keyboard.setKeyRepeat(true) +``` + ## Hello, World! ```lua From 6044a1f901ecdad2a9553812a7a824a967a77728 Mon Sep 17 00:00:00 2001 From: Whitecl4ws Date: Sat, 28 Jan 2017 12:00:07 -0500 Subject: [PATCH 2/2] Added Label and Password options --- input.lua | 6 ++++++ theme.lua | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/input.lua b/input.lua index 5262c2b..201074e 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 @@ -26,9 +29,11 @@ return function(core, input, ...) -- position 6: hello| -- get size of text and cursor position + opt.cursor_pos = 0 if input.cursor > 1 then local s = input.text:sub(1, utf8.offset(input.text, input.cursor)-1) + if input.password then s = string.rep("*", string.len(input.text)) end opt.cursor_pos = opt.font:getWidth(s) end @@ -53,6 +58,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 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