make the ptext_prompt func can define which keyboard to enter (#2608)

* _

* format

* use define
This commit is contained in:
sommermorgentraum
2025-04-04 21:41:12 +08:00
committed by GitHub
parent 4162820409
commit 1377516dce
25 changed files with 50 additions and 19 deletions

View File

@@ -32,7 +32,8 @@ namespace ui {
AlphanumView::AlphanumView(
NavigationView& nav,
std::string& str,
size_t max_length)
size_t max_length,
uint8_t enter_mode)
: TextEntryView(nav, str, max_length) {
size_t n;
@@ -76,7 +77,7 @@ AlphanumView::AlphanumView(
n++;
}
set_mode(mode);
set_mode(enter_mode);
button_mode.on_select = [this](Button&) {
set_mode(mode + 1);

View File

@@ -37,7 +37,7 @@ namespace ui {
class AlphanumView : public TextEntryView {
public:
AlphanumView(NavigationView& nav, std::string& str, size_t max_length);
AlphanumView(NavigationView& nav, std::string& str, size_t max_length, uint8_t enter_mode);
AlphanumView(const AlphanumView&) = delete;
AlphanumView(AlphanumView&&) = delete;

View File

@@ -31,8 +31,9 @@ void text_prompt(
NavigationView& nav,
std::string& str,
size_t max_length,
uint8_t mode,
std::function<void(std::string&)> on_done) {
text_prompt(nav, str, str.length(), max_length, on_done);
text_prompt(nav, str, str.length(), max_length, mode, on_done);
}
void text_prompt(
@@ -40,8 +41,9 @@ void text_prompt(
std::string& str,
uint32_t cursor_pos,
size_t max_length,
uint8_t mode,
std::function<void(std::string&)> on_done) {
auto te_view = nav.push<AlphanumView>(str, max_length);
auto te_view = nav.push<AlphanumView>(str, max_length, mode);
te_view->set_cursor(cursor_pos);
te_view->on_changed = [on_done](std::string& value) {
if (on_done)

View File

@@ -26,6 +26,11 @@
#include "ui.hpp"
#include "ui_navigation.hpp"
#define ENTER_KEYBOARD_MODE_ALPHA 0
#define ENTER_KEYBOARD_MODE_DIGITS 1
#define ENTER_KEYBOARD_MODE_SYMBOLS 2
#define ENTER_KEYBOARD_MODE_HEX 3
namespace ui {
class TextEntryView : public View {
@@ -62,6 +67,7 @@ void text_prompt(
NavigationView& nav,
std::string& str,
size_t max_length,
uint8_t mode,
std::function<void(std::string&)> on_done = nullptr);
void text_prompt(
@@ -69,6 +75,7 @@ void text_prompt(
std::string& str,
uint32_t cursor_pos,
size_t max_length,
uint8_t mode, // enter mode: 123 abc etc
std::function<void(std::string&)> on_done = nullptr);
} /* namespace ui */