Added a text input that only accepts full numbers (int)
What's new
- I've added a new Keyboard input. It is similar to text_input and byte_input. The purpose of this one is to only allow users to input a number, nothing else. This can be very handy in app designs, as the user input is limited to expected characters.
Verification
- #include <gui/modules/int_input.h> in a fap application the same way you would include text_input.h
Checklist (For Reviewer)
- [ ] PR has description of feature/bug or link to Confluence/Jira task
- [ ] Description contains actions to verify feature/bugfix
- [ ] I've built this code, uploaded it to the device and verified feature/bugfix
@hedger Thank you for the feedback. Added the requested sdk_headers and CSV entries
@hedger are these fail messages normal or am I expected to do something to fix this?
Sorry for delay with your PR.
Can you also provide example app and rename IntInput to NumberInput, int_input to number_input?
@skotopes Ok, tried my best to keep it as expected. Let me know if something isn't right.
- The keyboard is renamed
- There is an example app in applications/examples/example_number_input
https://github.com/flipperdevices/flipperzero-firmware/assets/5908330/7530c74e-8b17-4775-b99e-4c433c50c6b0
0x0801147c in __furi_crash_implementation () at furi/core/check.c:163
163 RESTORE_REGISTERS_AND_HALT_MCU(debug);
(gdb) bt
#0 0x0801147c in __furi_crash_implementation () at furi/core/check.c:163
#1 0x0807a5cc in view_dispatcher_free (view_dispatcher=0x20014de8) at applications/services/gui/view_dispatcher.c:26
#2 0x200154a6 in example_number_input_free (app=app@entry=0x20015a00) at applications/examples/example_number_input/example_number_input.c:45
#3 0x2001551e in example_number_input (p=<optimized out>) at applications/examples/example_number_input/example_number_input.c:69
#4 0x080548a2 in flipper_application_thread (context=0x20014b20) at lib/flipper_application/flipper_application.c:224
#5 0x08013d6e in furi_thread_body (context=0x20014d78) at furi/core/thread.c:91
#6 0x08013d1a in furi_thread_catch () at furi/core/thread.c:62
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
crashing on exit because some view was not released from view dispatcher
Un-draft when ready
also please fix build issues (API mismatch)
@leedave need help?
@skotopes
Can you give me some more hints on the
view modules should own their own buffer issue.
Tbh I learn how code for Flipper should look by studying the fw you provide, as there is no official developer documentation. I got the basic setup from the other two keyboards (text & hex). If you say you're not proud of what you guys did back then and ask for an update, I'm not sure where I can find something built in the way you want to see it.
@leedave change model->text_buffer type to FuriString and allocate it on your module allocation
@skotopes How did you do the check, to see if some views were not removed from view_dispatcher. I added a code update, but lack a way of testing the result
So after a long wait, I finally managed to add your requests
model->text_bufferchanged to FuriString- removed number digits length option
- replaced with settings for min/max value allowed
- added possibility to input negative numbers, added button if set to true when loading module
Sorry for keeping you in limbo for such a long time.
This PR was bugging me a lot when I was trying to review it previous time, It's quite bad in terms of the code and clearly requires more work before we will be able to merge it.
I've highlighted some major issues, un-draft this PR when you fix it. Also feel free to ask if you need any help.
@skotopes Thank you for taking the time to review my code. Looks like I still have a lot to learn, but I'll stay at it.
As chance has it, just like last time your review collided with the first day of my vacation. Meaning I can't update it before I get back. I did some of the small changes already, the rest will need to wait.
@leedave no problem, I'll wait ;-)
@skotopes I've done some refactoring to solve the issues you mentioned and some more.
Main additions
- Abilitity to adjust min and max values in the demo app for easier testing of edge-cases
- Invalid number inputs are ignored
- In some cases you need to be able to write an invalid number to be able to finish off with a valid number later (min: 50, type in 9 then 0 for 90). A Lock button replaces the save button in this case to symbolize invalid input and prevent saving.
- Back button no longer saves entry, but loads back the original value
- Removed sign & useSign, as no longer needed with min/max settings
- replaced all const char* strings in module with furiString. Only used in module and destroyed on exit.
- Callback returns number, no longer uses string
I hope this fits better. Let me know if something is still not good.
tehe
See comments. Un-draft when ready.
@skotopes Your requested updates are made, ready for review.
@leedave you are close to the finishing line, just a little bit more ;-)
Thanks again for making me a better programmer
Un-draft when fixed
That was quite a journey, couple things for you to take away:
- Read documentation
- Plan object ownership and allocate/release cycle
- Keep things simple
- Test
Yes that was a journey, but I do appreciate the help as at the time I started developing things for Flipper there was no documentation I could read, only other code from the FW I could learn from.
I've just noticed that in the mean time documentation has started appearing ... and I'm surprised to see that there's actually a page related to [this Pull Request] (https://developer.flipper.net/flipperzero/doxygen/md__2github_2workspace_2applications_2examples_2example__number__input_2_read_me.html)
As long as you document your code in doxygen format it will appear in developer documentation