Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions src/ui/components/confirm_gesture.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <touch/gestures.h>
#include <ui/ui_util.h>
#include <util.h>
#include <utils_assert.h>

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

typedef struct {
bool active_top; // Marker is 'active', i.e., touched
bool active_bottom; // Marker is 'active', i.e., touched
bool confirmed; // Confirm event occurred
bool gesture_active; // Marker is 'active', i.e., touched.
bool active[2]; // Slider is active
bool confirmed; // Confirm callback called
uint16_t active_count; // Start at an offset to allow movement on first touch
uint16_t bottom_arrow_slidein; // from zero to arrow height * SCALE
void (*callback)(void* user_data);
Expand All @@ -43,7 +44,7 @@ typedef struct {
bool confirm_gesture_is_active(component_t* component)
{
confirm_data_t* data = (confirm_data_t*)component->data;
return data->active_top;
return data->gesture_active;
}

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

// Update active_count
if (data->active_top && data->active_bottom) {
if (data->active[0] && data->active[1]) {
data->active_count++;
data->gesture_active = true;
} else {
data->active_count = MAX(SCALE - 1, data->active_count - SCALE);
}

// Update bottom arrow slidein
if (data->active_top) {
// Update bottom arrow slidein if top is active
if (data->active[top_slider]) {
if (data->bottom_arrow_slidein < arrow_height * SCALE) {
data->bottom_arrow_slidein++;
}
} else if (data->bottom_arrow_slidein > 0) {
data->bottom_arrow_slidein--;
} else if (data->bottom_arrow_slidein == 0) {
data->gesture_active = false;
}

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

switch (event->id) {
case EVENT_SLIDE_RELEASED:
if (event->data.source == top_slider) {
data->active_top = false;
} else {
data->active_bottom = false;
}
break;
case EVENT_CONTINUOUS_TAP:
if (event->data.position > SLIDER_POSITION_TWO_THIRD &&
event->data.position <= MAX_SLIDER_POS) {
if (event->data.source == top_slider) {
data->active_top = true;
} else {
data->active_bottom = true;
}
data->active[event->data.source] = true;
}
break;
case EVENT_SLIDE_RELEASED:
case EVENT_SHORT_TAP:
if (event->data.source == top_slider) {
data->active_top = false;
} else {
data->active_bottom = false;
}
data->active[event->data.source] = false;
break;
default:
break;
Expand Down Expand Up @@ -155,8 +146,9 @@ component_t* confirm_gesture_create(void (*callback)(void*), void* user_data)
Abort("Error: malloc confirm_gesture data");
}
memset(data, 0, sizeof(confirm_data_t));
data->active_top = false;
data->active_bottom = false;
data->gesture_active = false;
data->active[0] = false;
data->active[1] = false;
data->confirmed = false;
data->active_count = SCALE - 1;
data->bottom_arrow_slidein = 0;
Expand Down
11 changes: 6 additions & 5 deletions src/ui/components/trinary_input_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ static void _render(component_t* component)
UG_PutString(0, STRING_POS_Y, "...", false);
}

// Render sub-components
if (data->can_confirm) {
data->confirm_component->f->render(data->confirm_component);
}

// Do not process events for components which are not rendered.
data->trinary_char_component->disabled = true;
data->left_arrow_component->disabled = true;
Expand All @@ -245,6 +240,12 @@ static void _render(component_t* component)
if (data->title_on_top || show_title) {
data->title_component->f->render(data->title_component);
}

// Render confirm button or gesture (render confirm gesture last so that bottom triangle is
// above keyboard)
Comment on lines +244 to +245
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that bottom triangle is above keyboard

The keyboard is not rendered while the confirm gesture is active. Is this comment about something else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true, you can clearly see the bottom triangle "animating out" beneath the keyboard.

if (data->can_confirm) {
data->confirm_component->f->render(data->confirm_component);
}
}

static void _input_char_set_alphabet(component_t* trinary_char, keyboard_mode_t mode)
Expand Down