[FL-2284] IR: Show universal remote loading (#1004)

* [FL-2131] IR: Show universal remote loading
* Remove unused hal rtc. Gui: cleanup loading module.

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Albert Kharisov
2022-02-24 15:59:36 +04:00
committed by GitHub
parent 92734f1bb3
commit 24987b95cd
32 changed files with 409 additions and 243 deletions

View File

@@ -40,8 +40,6 @@ ARRAY_DEF(ButtonMatrix, ButtonArray_t);
struct ButtonPanel {
View* view;
ButtonPanelInputCallback input_callback;
void* input_context;
};
typedef struct {
@@ -51,8 +49,6 @@ typedef struct {
uint16_t reserve_y;
uint16_t selected_item_x;
uint16_t selected_item_y;
ButtonPanelDrawCallback draw_callback;
void* draw_context;
} ButtonPanelModel;
static ButtonItem** button_panel_get_item(ButtonPanelModel* model, size_t x, size_t y);
@@ -72,7 +68,6 @@ ButtonPanel* button_panel_alloc() {
view_allocate_model(button_panel->view, ViewModelTypeLocking, sizeof(ButtonPanelModel));
view_set_draw_callback(button_panel->view, button_panel_view_draw_callback);
view_set_input_callback(button_panel->view, button_panel_view_input_callback);
button_panel->input_callback = NULL;
with_view_model(
button_panel->view, (ButtonPanelModel * model) {
@@ -80,7 +75,6 @@ ButtonPanel* button_panel_alloc() {
model->reserve_y = 0;
model->selected_item_x = 0;
model->selected_item_y = 0;
model->draw_callback = NULL;
ButtonMatrix_init(model->button_matrix);
LabelList_init(model->labels);
return true;
@@ -216,8 +210,6 @@ static void button_panel_view_draw_callback(Canvas* canvas, void* _model) {
canvas_set_font(canvas, label->font);
canvas_draw_str(canvas, label->x, label->y, label->str);
}
if(model->draw_callback) model->draw_callback(canvas, model->draw_context);
}
static void button_panel_process_down(ButtonPanel* button_panel) {
@@ -341,9 +333,7 @@ static bool button_panel_view_input_callback(InputEvent* event, void* context) {
furi_assert(button_panel);
bool consumed = false;
if(button_panel->input_callback) {
consumed = button_panel->input_callback(event, button_panel->input_context);
} else if(event->type == InputTypeShort) {
if(event->type == InputTypeShort) {
switch(event->key) {
case InputKeyUp:
consumed = true;
@@ -391,23 +381,3 @@ void button_panel_add_label(
return true;
});
}
void button_panel_set_popup_draw_callback(
ButtonPanel* button_panel,
ButtonPanelDrawCallback callback,
void* context) {
with_view_model(
button_panel->view, (ButtonPanelModel * model) {
model->draw_callback = callback;
model->draw_context = context;
return true;
});
}
void button_panel_set_popup_input_callback(
ButtonPanel* button_panel,
ButtonPanelInputCallback callback,
void* context) {
button_panel->input_context = context;
button_panel->input_callback = callback;
}

View File

@@ -17,12 +17,6 @@ typedef struct ButtonPanel ButtonPanel;
/** Callback type to call for handling selecting button_panel items */
typedef void (*ButtonItemCallback)(void* context, uint32_t index);
/** Callback type for additional drawings above main button_panel screen */
typedef void (*ButtonPanelDrawCallback)(Canvas* canvas, void* _model);
/** Callback type to intercept input events of button_panel */
typedef bool (*ButtonPanelInputCallback)(InputEvent* event, void* context);
/** Allocate new button_panel module.
*
* @return ButtonPanel instance
@@ -106,34 +100,6 @@ void button_panel_add_label(
Font font,
const char* label_str);
// TODO: [FL-1445] Have to replace callbacks above with additional popup-layer
/** Set popup draw callback for button_panel module.
*
* Used to add popup drawings after main draw callback is done.
*
* @param button_panel ButtonPanel instance
* @param callback callback function to set for draw event
* @param context context to pass to callback
*/
void button_panel_set_popup_draw_callback(
ButtonPanel* button_panel,
ButtonPanelDrawCallback callback,
void* context);
/** Set popup input callback for button_panel module.
*
* Used to add popup input callback. It will intercept all input events for
* current view.
*
* @param button_panel ButtonPanel instance
* @param callback function to overwrite main input callbacks
* @param context context to pass to callback
*/
void button_panel_set_popup_input_callback(
ButtonPanel* button_panel,
ButtonPanelInputCallback callback,
void* context);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,94 @@
#include <stdint.h>
#include <furi.h>
#include <assets_icons.h>
#include <gui/icon_animation.h>
#include <gui/elements.h>
#include <gui/canvas.h>
#include <gui/view.h>
#include <input/input.h>
#include "loading.h"
struct Loading {
View* view;
};
typedef struct {
IconAnimation* icon;
} LoadingModel;
static void loading_draw_callback(Canvas* canvas, void* _model) {
LoadingModel* model = (LoadingModel*)_model;
uint8_t x = 7;
uint8_t y = 40;
uint8_t width = 49;
uint8_t height = 47;
elements_bold_rounded_frame(canvas, x, y, width, height);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, x + 7, y + 13, "Loading...");
canvas_draw_icon_animation(canvas, x + 13, y + 19, model->icon);
}
static bool loading_input_callback(InputEvent* event, void* context) {
furi_assert(context);
return true;
}
static void loading_enter_callback(void* context) {
furi_assert(context);
Loading* instance = context;
LoadingModel* model = view_get_model(instance->view);
/* using Loading View in conjunction with several
* Stack View obligates to reassign
* Update callback, as it can be rewritten
*/
view_tie_icon_animation(instance->view, model->icon);
icon_animation_start(model->icon);
view_commit_model(instance->view, false);
}
static void loading_exit_callback(void* context) {
furi_assert(context);
Loading* instance = context;
LoadingModel* model = view_get_model(instance->view);
icon_animation_stop(model->icon);
view_commit_model(instance->view, false);
}
Loading* loading_alloc(void) {
Loading* instance = malloc(sizeof(Loading));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(LoadingModel));
LoadingModel* model = view_get_model(instance->view);
model->icon = icon_animation_alloc(&A_Loading_24);
view_tie_icon_animation(instance->view, model->icon);
view_commit_model(instance->view, false);
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, loading_draw_callback);
view_set_input_callback(instance->view, loading_input_callback);
view_set_enter_callback(instance->view, loading_enter_callback);
view_set_exit_callback(instance->view, loading_exit_callback);
return instance;
}
void loading_free(Loading* instance) {
LoadingModel* model = view_get_model(instance->view);
icon_animation_free(model->icon);
view_commit_model(instance->view, false);
furi_assert(instance);
view_free(instance->view);
free(instance);
}
View* loading_get_view(Loading* instance) {
furi_assert(instance);
furi_assert(instance->view);
return instance->view;
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include <gui/view.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Loading anonymous structure */
typedef struct Loading Loading;
/** Allocate and initialize
*
* This View used to show system is doing some processing
*
* @return Loading View instance
*/
Loading* loading_alloc();
/** Deinitialize and free Loading View
*
* @param instance Loading instance
*/
void loading_free(Loading* instance);
/** Get Loading view
*
* @param instance Loading instance
*
* @return View instance that can be used for embedding
*/
View* loading_get_view(Loading* instance);
#ifdef __cplusplus
}
#endif