[FL-867] GUI: ViewPort arrangement API, better input and draw dispatching (#333)
* Input: refactoring, platform agnostic key configuration, update usage across project. Minor queue usage fixes and tick timings. * Gui: lighter and more efficient input and draw call dispatching, ViewPort rearranging API. View: conditional model updates, API usage update. * BT: smaller update delay * GUI: ViewPort visibility check
This commit is contained in:
		@@ -91,26 +91,38 @@ void dialog_set_header_text(Dialog* dialog, const char* text) {
 | 
			
		||||
    furi_assert(dialog);
 | 
			
		||||
    furi_assert(text);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog->view, (DialogModel * model) { model->header_text = text; });
 | 
			
		||||
        dialog->view, (DialogModel * model) {
 | 
			
		||||
            model->header_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_set_text(Dialog* dialog, const char* text) {
 | 
			
		||||
    furi_assert(dialog);
 | 
			
		||||
    furi_assert(text);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog->view, (DialogModel * model) { model->text = text; });
 | 
			
		||||
        dialog->view, (DialogModel * model) {
 | 
			
		||||
            model->text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_set_left_button_text(Dialog* dialog, const char* text) {
 | 
			
		||||
    furi_assert(dialog);
 | 
			
		||||
    furi_assert(text);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog->view, (DialogModel * model) { model->left_text = text; });
 | 
			
		||||
        dialog->view, (DialogModel * model) {
 | 
			
		||||
            model->left_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_set_right_button_text(Dialog* dialog, const char* text) {
 | 
			
		||||
    furi_assert(dialog);
 | 
			
		||||
    furi_assert(text);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog->view, (DialogModel * model) { model->right_text = text; });
 | 
			
		||||
        dialog->view, (DialogModel * model) {
 | 
			
		||||
            model->right_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -94,6 +94,7 @@ static bool dialog_ex_view_input_callback(InputEvent* event, void* context) {
 | 
			
		||||
            left_text = model->left_text;
 | 
			
		||||
            center_text = model->center_text;
 | 
			
		||||
            right_text = model->right_text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    // Process key presses only
 | 
			
		||||
@@ -142,6 +143,8 @@ DialogEx* dialog_ex_alloc() {
 | 
			
		||||
            model->left_text = NULL;
 | 
			
		||||
            model->center_text = NULL;
 | 
			
		||||
            model->right_text = NULL;
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
    return dialog_ex;
 | 
			
		||||
}
 | 
			
		||||
@@ -182,6 +185,7 @@ void dialog_ex_set_header(
 | 
			
		||||
            model->header.y = y;
 | 
			
		||||
            model->header.horizontal = horizontal;
 | 
			
		||||
            model->header.vertical = vertical;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -200,6 +204,7 @@ void dialog_ex_set_text(
 | 
			
		||||
            model->text.y = y;
 | 
			
		||||
            model->text.horizontal = horizontal;
 | 
			
		||||
            model->text.vertical = vertical;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -210,23 +215,33 @@ void dialog_ex_set_icon(DialogEx* dialog_ex, int8_t x, int8_t y, IconName name)
 | 
			
		||||
            model->icon.x = x;
 | 
			
		||||
            model->icon.y = y;
 | 
			
		||||
            model->icon.name = name;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_ex_set_left_button_text(DialogEx* dialog_ex, const char* text) {
 | 
			
		||||
    furi_assert(dialog_ex);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) { model->left_text = text; });
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) {
 | 
			
		||||
            model->left_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_ex_set_center_button_text(DialogEx* dialog_ex, const char* text) {
 | 
			
		||||
    furi_assert(dialog_ex);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) { model->center_text = text; });
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) {
 | 
			
		||||
            model->center_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dialog_ex_set_right_button_text(DialogEx* dialog_ex, const char* text) {
 | 
			
		||||
    furi_assert(dialog_ex);
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) { model->right_text = text; });
 | 
			
		||||
        dialog_ex->view, (DialogExModel * model) {
 | 
			
		||||
            model->right_text = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -141,6 +141,7 @@ Popup* popup_alloc() {
 | 
			
		||||
            model->icon.x = -1;
 | 
			
		||||
            model->icon.y = -1;
 | 
			
		||||
            model->icon.name = I_ButtonCenter_7x7;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
    return popup;
 | 
			
		||||
}
 | 
			
		||||
@@ -182,6 +183,7 @@ void popup_set_header(
 | 
			
		||||
            model->header.y = y;
 | 
			
		||||
            model->header.horizontal = horizontal;
 | 
			
		||||
            model->header.vertical = vertical;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -200,6 +202,7 @@ void popup_set_text(
 | 
			
		||||
            model->text.y = y;
 | 
			
		||||
            model->text.horizontal = horizontal;
 | 
			
		||||
            model->text.vertical = vertical;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -210,6 +213,7 @@ void popup_set_icon(Popup* popup, int8_t x, int8_t y, IconName name) {
 | 
			
		||||
            model->icon.x = x;
 | 
			
		||||
            model->icon.y = y;
 | 
			
		||||
            model->icon.name = name;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -108,6 +108,7 @@ Submenu* submenu_alloc() {
 | 
			
		||||
        submenu->view, (SubmenuModel * model) {
 | 
			
		||||
            SubmenuItemArray_init(model->items);
 | 
			
		||||
            model->position = 0;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    return submenu;
 | 
			
		||||
@@ -117,7 +118,10 @@ void submenu_free(Submenu* submenu) {
 | 
			
		||||
    furi_assert(submenu);
 | 
			
		||||
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        submenu->view, (SubmenuModel * model) { SubmenuItemArray_clear(model->items); });
 | 
			
		||||
        submenu->view, (SubmenuModel * model) {
 | 
			
		||||
            SubmenuItemArray_clear(model->items);
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
    view_free(submenu->view);
 | 
			
		||||
    free(submenu);
 | 
			
		||||
}
 | 
			
		||||
@@ -142,6 +146,7 @@ SubmenuItem* submenu_add_item(
 | 
			
		||||
            item->label = label;
 | 
			
		||||
            item->callback = callback;
 | 
			
		||||
            item->callback_context = callback_context;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    return item;
 | 
			
		||||
@@ -159,6 +164,7 @@ void submenu_process_up(Submenu* submenu) {
 | 
			
		||||
                model->position = SubmenuItemArray_size(model->items) - 1;
 | 
			
		||||
                model->window_position = model->position - 3;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -175,6 +181,7 @@ void submenu_process_down(Submenu* submenu) {
 | 
			
		||||
                model->position = 0;
 | 
			
		||||
                model->window_position = 0;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -186,6 +193,7 @@ void submenu_process_ok(Submenu* submenu) {
 | 
			
		||||
            if(model->position < (SubmenuItemArray_size(model->items))) {
 | 
			
		||||
                item = SubmenuItemArray_get(model->items, model->position);
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    if(item && item->callback) {
 | 
			
		||||
 
 | 
			
		||||
@@ -223,6 +223,7 @@ static void text_input_handle_up(TextInput* text_input) {
 | 
			
		||||
            if(model->selected_row > 0) {
 | 
			
		||||
                model->selected_row--;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -235,6 +236,7 @@ static void text_input_handle_down(TextInput* text_input) {
 | 
			
		||||
                    model->selected_column = get_row_size(model->selected_row) - 1;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -246,6 +248,7 @@ static void text_input_handle_left(TextInput* text_input) {
 | 
			
		||||
            } else {
 | 
			
		||||
                model->selected_column = get_row_size(model->selected_row) - 1;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -257,6 +260,7 @@ static void text_input_handle_right(TextInput* text_input) {
 | 
			
		||||
            } else {
 | 
			
		||||
                model->selected_column = 0;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -281,6 +285,7 @@ static void text_input_handle_ok(TextInput* text_input) {
 | 
			
		||||
                model->text[text_length] = selected;
 | 
			
		||||
                model->text[text_length + 1] = 0;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -333,6 +338,7 @@ TextInput* text_input_alloc() {
 | 
			
		||||
            model->header = "";
 | 
			
		||||
            model->selected_row = 0;
 | 
			
		||||
            model->selected_column = 0;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    return text_input;
 | 
			
		||||
@@ -361,10 +367,14 @@ void text_input_set_result_callback(
 | 
			
		||||
            model->callback_context = callback_context;
 | 
			
		||||
            model->text = text;
 | 
			
		||||
            model->max_text_length = max_text_length;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void text_input_set_header_text(TextInput* text_input, const char* text) {
 | 
			
		||||
    with_view_model(
 | 
			
		||||
        text_input->view, (TextInputModel * model) { model->header = text; });
 | 
			
		||||
        text_input->view, (TextInputModel * model) {
 | 
			
		||||
            model->header = text;
 | 
			
		||||
            return true;
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user