Skip to content

Commit 2fa485b

Browse files
committed
confirm_gesture: fix unintentional keyboard press
Previously the confirm gesture component would get "out of active" as soon as the top slider was released. If one released the top slider before the top slider it would often trigger a keyboard press. This commit creates an additional boolean that keeps the "active" state in "active" until the drawing is reset to it's original state thus removing the risk of unintentional keyboard presses. The confirm gesture is also given a "higher priority" by being rendered last.
1 parent 69f124b commit 2fa485b

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

src/ui/components/confirm_gesture.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <touch/gestures.h>
2424
#include <ui/ui_util.h>
2525
#include <util.h>
26+
#include <utils_assert.h>
2627

2728
#include <stdbool.h>
2829
#include <stdint.h>
@@ -31,9 +32,9 @@
3132
#define SCALE 6 // Divide active_count by scale to slow down motion
3233

3334
typedef struct {
34-
bool active_top; // Marker is 'active', i.e., touched
35-
bool active_bottom; // Marker is 'active', i.e., touched
36-
bool confirmed; // Confirm event occurred
35+
bool gesture_active; // Marker is 'active', i.e., touched.
36+
bool active[2]; // Slider is active
37+
bool confirmed; // Confirm callback called
3738
uint16_t active_count; // Start at an offset to allow movement on first touch
3839
uint16_t bottom_arrow_slidein; // from zero to arrow height * SCALE
3940
void (*callback)(void* user_data);
@@ -43,7 +44,7 @@ typedef struct {
4344
bool confirm_gesture_is_active(component_t* component)
4445
{
4546
confirm_data_t* data = (confirm_data_t*)component->data;
46-
return data->active_top;
47+
return data->gesture_active;
4748
}
4849

4950
/**
@@ -57,19 +58,22 @@ static void _render(component_t* component)
5758
confirm_data_t* data = (confirm_data_t*)component->data;
5859

5960
// Update active_count
60-
if (data->active_top && data->active_bottom) {
61+
if (data->active[0] && data->active[1]) {
6162
data->active_count++;
63+
data->gesture_active = true;
6264
} else {
6365
data->active_count = MAX(SCALE - 1, data->active_count - SCALE);
6466
}
6567

66-
// Update bottom arrow slidein
67-
if (data->active_top) {
68+
// Update bottom arrow slidein if top is active
69+
if (data->active[top_slider]) {
6870
if (data->bottom_arrow_slidein < arrow_height * SCALE) {
6971
data->bottom_arrow_slidein++;
7072
}
7173
} else if (data->bottom_arrow_slidein > 0) {
7274
data->bottom_arrow_slidein--;
75+
} else if (data->bottom_arrow_slidein == 0) {
76+
data->gesture_active = false;
7377
}
7478

7579
// Draw the top arrow
@@ -101,31 +105,18 @@ static void _render(component_t* component)
101105
static void _on_event(const event_t* event, component_t* component)
102106
{
103107
confirm_data_t* data = (confirm_data_t*)component->data;
108+
ASSERT(event->data.source < sizeof(data->active));
104109

105110
switch (event->id) {
106-
case EVENT_SLIDE_RELEASED:
107-
if (event->data.source == top_slider) {
108-
data->active_top = false;
109-
} else {
110-
data->active_bottom = false;
111-
}
112-
break;
113111
case EVENT_CONTINUOUS_TAP:
114112
if (event->data.position > SLIDER_POSITION_TWO_THIRD &&
115113
event->data.position <= MAX_SLIDER_POS) {
116-
if (event->data.source == top_slider) {
117-
data->active_top = true;
118-
} else {
119-
data->active_bottom = true;
120-
}
114+
data->active[event->data.source] = true;
121115
}
122116
break;
117+
case EVENT_SLIDE_RELEASED:
123118
case EVENT_SHORT_TAP:
124-
if (event->data.source == top_slider) {
125-
data->active_top = false;
126-
} else {
127-
data->active_bottom = false;
128-
}
119+
data->active[event->data.source] = false;
129120
break;
130121
default:
131122
break;
@@ -155,8 +146,9 @@ component_t* confirm_gesture_create(void (*callback)(void*), void* user_data)
155146
Abort("Error: malloc confirm_gesture data");
156147
}
157148
memset(data, 0, sizeof(confirm_data_t));
158-
data->active_top = false;
159-
data->active_bottom = false;
149+
data->gesture_active = false;
150+
data->active[0] = false;
151+
data->active[1] = false;
160152
data->confirmed = false;
161153
data->active_count = SCALE - 1;
162154
data->bottom_arrow_slidein = 0;

src/ui/components/trinary_input_string.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,6 @@ static void _render(component_t* component)
216216
UG_PutString(0, STRING_POS_Y, "...", false);
217217
}
218218

219-
// Render sub-components
220-
if (data->can_confirm) {
221-
data->confirm_component->f->render(data->confirm_component);
222-
}
223-
224219
// Do not process events for components which are not rendered.
225220
data->trinary_char_component->disabled = true;
226221
data->left_arrow_component->disabled = true;
@@ -245,6 +240,12 @@ static void _render(component_t* component)
245240
if (data->title_on_top || show_title) {
246241
data->title_component->f->render(data->title_component);
247242
}
243+
244+
// Render confirm button or gesture (render confirm gesture last so that bottom triangle is
245+
// above keyboard)
246+
if (data->can_confirm) {
247+
data->confirm_component->f->render(data->confirm_component);
248+
}
248249
}
249250

250251
static void _input_char_set_alphabet(component_t* trinary_char, keyboard_mode_t mode)

0 commit comments

Comments
 (0)