Hi,
I’m creating a user input form that has a long list of text boxes.
The problem I have created is if I showKeyboard() to edit text in a box, the keyboard can cover over the text boxes I’m trying to edit.
I notice the code editor solves this by moving up the code being edited. Is this a public function I can also use?
What are possible solutions for a keyboard covering over the text field under edit?
Unfortunately that may then introduce a problem for input fields at top of the screen.
If the user is entering data in box at bottom then pushing text up is fine, if they are entering text at top, then the text box shouldn’t move up.
I’ll need to deal with both cases.
Problems like these really bloat my code
Example solution
self.focus is set to true in touched if self was hit
-- move stuff around so keyboard doesn't cover it
posx = self.pos.x
posy = self.pos.y
if isKeyboardShowing() == true and self.focus == true then
--Highlight and center box under edit
fill(69, 206, 14, 255)
posx=200
posy=HEIGHT/2
end
if isKeyboardShowing() == true and self.focus == false then
--grey out and move away box not under edit
fill(145, 156, 141, 255)
if posy-50<HEIGHT/2 then
posy=0
end
end
@JakAttak I said, when checking a boolean. isKeyboardShowing() will never return nil (and it would make sense to be false if it was), and I don’t see how self.focus could be nil either (again, it would make sense to be false if it was).
@SkyTheCodee, I understand. I just wanted to make sure that @Famous knows all of this if he didn’t already know he could do it (in case later he uses it with a variable that could be nil and needs to recognize that specifically)
@JakAttak I disagree with your response “those also become true when the variable is nil/not nil”. In Lua, a variable is false only if it’s nil or false, otherwise it’s true for all other values.
@dave1707, right that’s what I’m saying. So if I have a variable that could be 15 or could be true (not sure why, but it’s possible) and I want to check that it is true, if a then won’t work.
if not a then will work if a is nil or false, which you could also potential want to distinguish between.
@Saturn031000 I used to write in C and I always used 0 for false and non 0 for true. @JakAttak It’s good to know exactly how things work to avoid coding problems, especially when you’re coming from a different language.