From b7873a34c64f78b595e41f5c7cde74d4affba028 Mon Sep 17 00:00:00 2001 From: Maddox Werts Date: Mon, 26 Aug 2024 05:20:00 -0400 Subject: [PATCH] Created a basic UI system (UNTESTED) --- project/flippypass.c | 16 +++++++++++++++ project/ui.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ project/ui.h | 24 ++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 project/ui.c create mode 100644 project/ui.h diff --git a/project/flippypass.c b/project/flippypass.c index 8fe801d..8bb9231 100644 --- a/project/flippypass.c +++ b/project/flippypass.c @@ -1,10 +1,26 @@ // Libraries #include +#include "ui.h" // Entry Point int32_t flippypass_app(void* p) { // Not using P Parameter UNUSED(p); + + // Creating the UI struct + uiManager* ui = ui_create(); + + // Timer + int alive_timer = 0; + + // Drawwing the UI + while(ui->running) { + // Updating canvas + view_port_update(ui->canvas); + + alive_timer += 1; + if (alive_timer > 10000000) {ui->running = false; break;} + } // Exit App return 0; diff --git a/project/ui.c b/project/ui.c new file mode 100644 index 0000000..6df9825 --- /dev/null +++ b/project/ui.c @@ -0,0 +1,49 @@ +// Header +#include "ui.h" + +// Functions +uiManager* ui_create() { + // Creating the UI Manager + uiManager* result = malloc(sizeof(uiManager)); + + // Defining basic variables + result->running = true; + result->page = 0; + + // Creating a canvas + result->canvas = view_port_alloc(); + view_port_draw_callback_set(result->canvas, ui_draw, result); + + // Returning the UI Manager + return result; +} + +void ui_draw(Canvas* canvas, void* ctx) { + // Context into Result + uiManager* manager = (uiManager*)ctx; + + // Switching page + switch(manager->page){ + case 0: + ui_p_mainmenu(canvas); + break; + } +} +void ui_p_mainmenu(Canvas* canvas) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 2, 11, "FlippyPass"); + + //canvas_draw_icon(canvas, 15, 16, &I_ButtonRight_4x7); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 22, 23, "View Passwords"); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 22, 41, "Create Password"); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 22, 51, "About"); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 22, 32, "View Archive"); +} \ No newline at end of file diff --git a/project/ui.h b/project/ui.h new file mode 100644 index 0000000..0b79d00 --- /dev/null +++ b/project/ui.h @@ -0,0 +1,24 @@ +// Define once +#ifndef H_UI +#define H_UI + +// Libraries +#include +#include + +// Structures +typedef struct { + ViewPort* canvas; + int page; + + bool running; +} uiManager; + +// Constructors +uiManager* ui_create(); + +// Functions +void ui_draw(Canvas* canvas, void* ctx); +void ui_p_mainmenu(Canvas* canvas); + +#endif \ No newline at end of file