GUI: NumberInput allow empty default and show pressing 0

This commit is contained in:
Willy-JL
2024-08-14 03:27:15 +02:00
parent 90728784e5
commit dfbba6a593
2 changed files with 10 additions and 4 deletions

View File

@@ -36,7 +36,7 @@ void momentum_app_scene_protocols_freqs_add_on_enter(void* context) {
momentum_app_scene_protocols_freqs_add_number_input_callback,
app,
0,
0, // TODO: support leaving default value empty, change min to 100000
100000,
999999);
view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewNumberInput);

View File

@@ -206,7 +206,7 @@ static void number_input_add_digit(NumberInputModel* model, char* newChar) {
}
model->current_number = strtol(furi_string_get_cstr(model->text_buffer), NULL, 10);
if(model->current_number == 0) {
furi_string_reset(model->text_buffer);
furi_string_set(model->text_buffer, "0");
}
}
@@ -417,7 +417,9 @@ void number_input_set_result_callback(
int32_t max_value) {
furi_check(number_input);
current_number = CLAMP(current_number, max_value, min_value);
if(current_number != 0) {
current_number = CLAMP(current_number, max_value, min_value);
}
with_view_model(
number_input->view,
@@ -426,7 +428,11 @@ void number_input_set_result_callback(
model->callback = callback;
model->callback_context = callback_context;
model->current_number = current_number;
furi_string_printf(model->text_buffer, "%ld", current_number);
if(current_number != 0) {
furi_string_printf(model->text_buffer, "%ld", current_number);
} else {
furi_string_set(model->text_buffer, "");
}
model->min_value = min_value;
model->max_value = max_value;
},