Updated GUI system
This commit is contained in:
parent
b7873a34c6
commit
7563a8c587
4 changed files with 62 additions and 6 deletions
8
project/app.h
Normal file
8
project/app.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Define once
|
||||
#ifndef H_APP
|
||||
#define H_APP
|
||||
|
||||
// Constants
|
||||
#define TAG "FlippyPass"
|
||||
|
||||
#endif
|
|
@ -10,17 +10,29 @@ int32_t flippypass_app(void* p) {
|
|||
// Creating the UI struct
|
||||
uiManager* ui = ui_create();
|
||||
|
||||
// Timer
|
||||
int alive_timer = 0;
|
||||
|
||||
// Drawwing the UI
|
||||
InputEvent event;
|
||||
while(ui->running) {
|
||||
// Getting the input event
|
||||
FuriStatus status = furi_message_queue_get(ui->event_queue, &event, 100);
|
||||
furi_mutex_acquire(ui->mutex, FuriWaitForever);
|
||||
|
||||
if (status == FuriStatusOk) {
|
||||
if (event.key == InputKeyBack) {
|
||||
ui->running = false;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_D(TAG, "Event Timeout");
|
||||
}
|
||||
|
||||
// Updating canvas
|
||||
view_port_update(ui->canvas);
|
||||
|
||||
alive_timer += 1;
|
||||
if (alive_timer > 10000000) {ui->running = false; break;}
|
||||
furi_mutex_release(ui->mutex);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
ui_delete(ui);
|
||||
|
||||
// Exit App
|
||||
return 0;
|
||||
|
|
28
project/ui.c
28
project/ui.c
|
@ -10,15 +10,33 @@ uiManager* ui_create() {
|
|||
result->running = true;
|
||||
result->page = 0;
|
||||
|
||||
// Creating a GUI
|
||||
result->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// Creating a canvas
|
||||
result->canvas = view_port_alloc();
|
||||
view_port_draw_callback_set(result->canvas, ui_draw, result);
|
||||
gui_add_view_port(result->gui, result->canvas, GuiLayerFullscreen);
|
||||
|
||||
// Creating mutex
|
||||
result->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
if (!result->mutex) {
|
||||
FURI_LOG_E(TAG, "Failed to create Mutex\r\n");
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Creating event queue
|
||||
result->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
|
||||
// Returning the UI Manager
|
||||
return result;
|
||||
}
|
||||
|
||||
void ui_draw(Canvas* canvas, void* ctx) {
|
||||
// Showing the Main Menu
|
||||
ui_p_mainmenu(canvas);
|
||||
|
||||
// Context into Result
|
||||
uiManager* manager = (uiManager*)ctx;
|
||||
|
||||
|
@ -46,4 +64,14 @@ void ui_p_mainmenu(Canvas* canvas) {
|
|||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 22, 32, "View Archive");
|
||||
}
|
||||
|
||||
void ui_delete(uiManager* manager) {
|
||||
furi_message_queue_free(manager->event_queue);
|
||||
view_port_enabled_set(manager->canvas, false);
|
||||
gui_remove_view_port(manager->gui, manager->canvas);
|
||||
view_port_free(manager->canvas);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_mutex_free(manager->mutex);
|
||||
free(manager);
|
||||
}
|
|
@ -5,10 +5,14 @@
|
|||
// Libraries
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include "app.h"
|
||||
|
||||
// Structures
|
||||
typedef struct {
|
||||
FuriMessageQueue* event_queue;
|
||||
FuriMutex* mutex;
|
||||
ViewPort* canvas;
|
||||
Gui* gui;
|
||||
int page;
|
||||
|
||||
bool running;
|
||||
|
@ -18,7 +22,11 @@ typedef struct {
|
|||
uiManager* ui_create();
|
||||
|
||||
// Functions
|
||||
void ui_timer(void* event_queue);
|
||||
|
||||
void ui_draw(Canvas* canvas, void* ctx);
|
||||
void ui_p_mainmenu(Canvas* canvas);
|
||||
|
||||
void ui_delete(uiManager* manager);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue