Merge branch 'ofw-dev' into dev

This commit is contained in:
MX
2023-06-29 04:22:51 +03:00
65 changed files with 1473 additions and 130 deletions

View File

@@ -16,7 +16,8 @@ typedef struct DialogsApp DialogsApp;
/****************** FILE BROWSER ******************/
/**
* File browser dialog extra options
* File browser dialog extra options.
* This can be default-initialized using {@link dialog_file_browser_set_basic_options}.
* @param extension file extension to be offered for selection
* @param base_path root folder path for navigation with back key
* @param skip_assets true - do not show assets folders
@@ -38,8 +39,10 @@ typedef struct {
} DialogsFileBrowserOptions;
/**
* Initialize file browser dialog options
* and set default values
* Initialize file browser dialog options and set default values.
* This is guaranteed to initialize all fields
* so it is safe to pass pointer to uninitialized {@code options}
* and assume that the data behind it becomes fully initialized after the call.
* @param options pointer to options structure
* @param extension file extension to filter
* @param icon file icon pointer, NULL for default icon

View File

@@ -146,6 +146,8 @@ typedef struct {
const Icon* file_icon;
bool hide_ext;
size_t scroll_counter;
uint32_t button_held_for_ticks;
} FileBrowserModel;
static const Icon* BrowserItemIcons[] = {
@@ -659,9 +661,24 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
browser->view,
FileBrowserModel * model,
{
int32_t scroll_speed = 1;
if(model->button_held_for_ticks > 5) {
if(model->button_held_for_ticks % 2) {
scroll_speed = 0;
} else {
scroll_speed = model->button_held_for_ticks > 9 ? 5 : 3;
}
}
if(event->key == InputKeyUp) {
model->item_idx =
((model->item_idx - 1) + model->item_cnt) % model->item_cnt;
if(model->item_idx < scroll_speed) {
model->button_held_for_ticks = 0;
model->item_idx = model->item_cnt - 1;
} else {
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) %
model->item_cnt;
}
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(
@@ -672,8 +689,16 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
browser->worker, load_offset, ITEM_LIST_LEN_MAX);
}
model->scroll_counter = 0;
model->button_held_for_ticks += 1;
} else if(event->key == InputKeyDown) {
model->item_idx = (model->item_idx + 1) % model->item_cnt;
int32_t count = model->item_cnt;
if(model->item_idx + scroll_speed >= count) {
model->button_held_for_ticks = 0;
model->item_idx = 0;
} else {
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
}
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(
@@ -684,11 +709,19 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
browser->worker, load_offset, ITEM_LIST_LEN_MAX);
}
model->scroll_counter = 0;
model->button_held_for_ticks += 1;
}
},
false);
browser_update_offset(browser);
consumed = true;
} else if(event->type == InputTypeRelease) {
with_view_model(
browser->view,
FileBrowserModel * model,
{ model->button_held_for_ticks = 0; },
true);
}
} else if(event->key == InputKeyOk) {
if(event->type == InputTypeShort) {

View File

@@ -6,6 +6,8 @@
struct TextBox {
View* view;
uint16_t button_held_for_ticks;
};
typedef struct {
@@ -19,36 +21,52 @@ typedef struct {
bool formatted;
} TextBoxModel;
static void text_box_process_down(TextBox* text_box) {
static void text_box_process_down(TextBox* text_box, uint8_t lines) {
with_view_model(
text_box->view,
TextBoxModel * model,
{
if(model->scroll_pos < model->scroll_num - 1) {
model->scroll_pos++;
// Search next line start
while(*model->text_pos++ != '\n')
;
if(model->scroll_pos < model->scroll_num - lines) {
model->scroll_pos += lines;
for(uint8_t i = 0; i < lines; i++) {
// Search next line start
while(*model->text_pos++ != '\n')
;
}
} else if(lines > 1) {
lines = model->scroll_num - model->scroll_pos - 1;
model->scroll_pos = model->scroll_num - 1;
for(uint8_t i = 0; i < lines; i++) {
// Search next line start
while(*model->text_pos++ != '\n')
;
}
}
},
true);
}
static void text_box_process_up(TextBox* text_box) {
static void text_box_process_up(TextBox* text_box, uint8_t lines) {
with_view_model(
text_box->view,
TextBoxModel * model,
{
if(model->scroll_pos > 0) {
model->scroll_pos--;
// Reach last symbol of previous line
model->text_pos--;
// Search previous line start
while((model->text_pos != model->text) && (*(--model->text_pos) != '\n'))
;
if(*model->text_pos == '\n') {
model->text_pos++;
if(model->scroll_pos > lines - 1) {
model->scroll_pos -= lines;
for(uint8_t i = 0; i < lines; i++) {
// Reach last symbol of previous line
model->text_pos--;
// Search previous line start
while((model->text_pos != model->text) && (*(--model->text_pos) != '\n'))
;
if(*model->text_pos == '\n') {
model->text_pos++;
}
}
} else if(lines > 1) {
lines = model->scroll_pos;
model->scroll_pos = 0;
model->text_pos = (char*)model->text;
}
},
true);
@@ -120,14 +138,28 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
TextBox* text_box = context;
bool consumed = false;
if(event->type == InputTypeShort) {
if(event->type == InputTypeShort || event->type == InputTypeRepeat) {
int32_t scroll_speed = 1;
if(text_box->button_held_for_ticks > 5) {
if(text_box->button_held_for_ticks % 2) {
scroll_speed = 0;
} else {
scroll_speed = text_box->button_held_for_ticks > 9 ? 5 : 3;
}
}
if(event->key == InputKeyDown) {
text_box_process_down(text_box);
text_box_process_down(text_box, scroll_speed);
consumed = true;
} else if(event->key == InputKeyUp) {
text_box_process_up(text_box);
text_box_process_up(text_box, scroll_speed);
consumed = true;
}
text_box->button_held_for_ticks++;
} else if(event->type == InputTypeRelease) {
text_box->button_held_for_ticks = 0;
consumed = true;
}
return consumed;
}