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
|
// Creating the UI struct
|
||||||
uiManager* ui = ui_create();
|
uiManager* ui = ui_create();
|
||||||
|
|
||||||
// Timer
|
|
||||||
int alive_timer = 0;
|
|
||||||
|
|
||||||
// Drawwing the UI
|
// Drawwing the UI
|
||||||
|
InputEvent event;
|
||||||
while(ui->running) {
|
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
|
// Updating canvas
|
||||||
view_port_update(ui->canvas);
|
view_port_update(ui->canvas);
|
||||||
|
furi_mutex_release(ui->mutex);
|
||||||
alive_timer += 1;
|
|
||||||
if (alive_timer > 10000000) {ui->running = false; break;}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ui_delete(ui);
|
||||||
|
|
||||||
// Exit App
|
// Exit App
|
||||||
return 0;
|
return 0;
|
||||||
|
|
28
project/ui.c
28
project/ui.c
|
@ -10,15 +10,33 @@ uiManager* ui_create() {
|
||||||
result->running = true;
|
result->running = true;
|
||||||
result->page = 0;
|
result->page = 0;
|
||||||
|
|
||||||
|
// Creating a GUI
|
||||||
|
result->gui = furi_record_open(RECORD_GUI);
|
||||||
|
|
||||||
// Creating a canvas
|
// Creating a canvas
|
||||||
result->canvas = view_port_alloc();
|
result->canvas = view_port_alloc();
|
||||||
view_port_draw_callback_set(result->canvas, ui_draw, result);
|
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
|
// Returning the UI Manager
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_draw(Canvas* canvas, void* ctx) {
|
void ui_draw(Canvas* canvas, void* ctx) {
|
||||||
|
// Showing the Main Menu
|
||||||
|
ui_p_mainmenu(canvas);
|
||||||
|
|
||||||
// Context into Result
|
// Context into Result
|
||||||
uiManager* manager = (uiManager*)ctx;
|
uiManager* manager = (uiManager*)ctx;
|
||||||
|
|
||||||
|
@ -46,4 +64,14 @@ void ui_p_mainmenu(Canvas* canvas) {
|
||||||
|
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str(canvas, 22, 32, "View Archive");
|
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
|
// Libraries
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
FuriMessageQueue* event_queue;
|
||||||
|
FuriMutex* mutex;
|
||||||
ViewPort* canvas;
|
ViewPort* canvas;
|
||||||
|
Gui* gui;
|
||||||
int page;
|
int page;
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
|
@ -18,7 +22,11 @@ typedef struct {
|
||||||
uiManager* ui_create();
|
uiManager* ui_create();
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
void ui_timer(void* event_queue);
|
||||||
|
|
||||||
void ui_draw(Canvas* canvas, void* ctx);
|
void ui_draw(Canvas* canvas, void* ctx);
|
||||||
void ui_p_mainmenu(Canvas* canvas);
|
void ui_p_mainmenu(Canvas* canvas);
|
||||||
|
|
||||||
|
void ui_delete(uiManager* manager);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue