Closed Delikt closed 2 years ago
entry
does not currently support observing keyboard events (like hitting ENTER). However, you can fake this behavior by using a non_wrapping_multiline_entry
and testing for the presence of \n
in the text
property value (just make sure to remove \n
from the text
after confirming its presence to avoid showing a new line to the user).
Example:
require 'glimmer-dsl-libui'
include Glimmer
window('Entry Submission with Enter', 300, 50) {
non_wrapping_multiline_entry { |nwme|
on_changed do
if nwme.text.include?("\n")
nwme.text = nwme.text.gsub("\n", '')
msg_box('Submission', "You entered:\n #{nwme.text}")
end
end
}
}.show
Thank you for your fast response, i will try around with that but i'm pretty sure this will not work cause i have a password_entry Field from where i want to submit.. i will reply here if the workaround worked for me
Yeah, no... that only works for standard text entry
because non_wrapping_multiline_entry
does not support a password mask like password_entry
.
However, a workaround is to add a submit button below the password_entry
, which the user can invoke using the keyboard alone with the following keys:
require 'glimmer-dsl-libui'
include Glimmer
window('Submit with Keyboard', 250, 40) {
vertical_box {
password_entry {
}
button {
text 'Submit'
on_clicked do
msg_box 'Submitted', 'Hitting tab and space triggers the submit button'
end
}
}
}.show
Otherwise, there is one more workaround.
You can build your own ENTER-supporting custom password control using the area
control (which supports arbitrary keyboard and mouse event listeners). If you really need it and need help building it, let me know, and I'd be happy to provide some code.
Hahaha, I just discovered one more workaround. You can attempt to mask the non_wrapping_multiline_entry
yourself. I am including an example below, but it is not complete as it does not handle backspacing, deleting, moving the keyboard caret, and other edge cases, but it's just a proof of concept.
require 'glimmer-dsl-libui'
include Glimmer
window('Entry Submission with Enter', 300, 50) {
vertical_box {
non_wrapping_multiline_entry { |nwme|
on_changed do
if nwme.text.include?("\n")
nwme.text = nwme.text.gsub("\n", '')
msg_box('Submission', "You entered:\n #{@saved}")
end
if nwme.text.match(/[^*]/)
@saved ||= ''
@saved += nwme.text.match(/([^*])/)[1]
nwme.text = nwme.text.gsub(/[^*]/, '*')
end
end
}
}
}.show
If you like this option, and need help completing it, let me know, and I'd be happy to help. Otherwise, let me know if you prefer the area
based solution suggested in my last comment, or if the initial workaround of letting users submit by hitting TAB and SPACE (instead of ENTER) is good enough.
Thank you very much for your Time and this workarounds, in my pov it make not more sense to press TAB and SPACE instead of TAB and Enter and the behavor not to handle backspacing, deleting, moving isn't that pretty... so i will let it is like it is for now...
Here a preview of my first Programm ever, what i builded with Ruby, LibUI, glimmer-dsl-libui and ocra to compile a self executable Windows exe:
Thanks to all the Programers from the above mentationed Repos, who makes this happen!
This Program is a configurable Setup what i coded for my Work in my spare Time - it save me as IT Support a lot of Time.
Sadly, i can't puplish the Source, cause there are some stuff in the Code from my Company.
Is it possible to input Userdata in a Textfield (Login Form) and submit it with pressing Enter instead of building a "Login" Button to submit Login?
a Example snippet will be welcome.
Thanks!