refactor added elements stuff into own file

master
Felix Pankratz 2 years ago
parent 98e42712cf
commit a59879bf1b

@ -0,0 +1,55 @@
#include <gui/canvas.h>
#include <gui/icon_i.h>
//lib can only do bottom left/right
void elements_button_top_left(Canvas* canvas, const char* str) {
const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const Icon* icon = &I_ButtonUp_7x4;
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t x = 0;
const uint8_t y = 0 + button_height;
canvas_draw_box(canvas, x, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x + button_width + 0, y - button_height, x + button_width + 0, y - 1);
canvas_draw_line(canvas, x + button_width + 1, y - button_height, x + button_width + 1, y - 2);
canvas_draw_line(canvas, x + button_width + 2, y - button_height, x + button_width + 2, y - 3);
canvas_invert_color(canvas);
canvas_draw_icon(canvas, x + horizontal_offset, y - icon_v_offset, &I_ButtonUp_7x4);
canvas_draw_str(
canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
canvas_invert_color(canvas);
}
void elements_button_top_right(Canvas* canvas, const char* str) {
const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const Icon* icon = &I_ButtonUp_7x4;
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t x = canvas_width(canvas);
const uint8_t y = 0 + button_height;
canvas_draw_box(canvas, x - button_width, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x - button_width - 1, y - button_height, x - button_width - 1, y - 1);
canvas_draw_line(canvas, x - button_width - 2, y - button_height, x - button_width - 2, y - 2);
canvas_draw_line(canvas, x - button_width - 3, y - button_height, x - button_width - 3, y - 3);
canvas_invert_color(canvas);
canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
canvas_draw_icon(
canvas, x - horizontal_offset - icon->width, y - icon_v_offset, &I_ButtonUp_7x4);
canvas_invert_color(canvas);
}

@ -0,0 +1,2 @@
void elements_button_top_right(Canvas* canvas, const char* str);
void elements_button_top_left(Canvas* canvas, const char* str);

@ -7,11 +7,12 @@
#include <gui/gui.h>
#include <gui/elements.h>
#include <gui/canvas.h>
#include <gui/icon_i.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include "gui_extensions.h"
#define BPM_STEP_SIZE_FINE 0.5d
#define BPM_STEP_SIZE_COARSE 10.0d
#define BPM_BOUNDARY_LOW 10.0d
@ -38,69 +39,18 @@ typedef struct {
NotificationApp* notifications;
} MetronomeState;
//lib can only do bottom left/right
static void elements_button_top_left(Canvas* canvas, const char* str) {
const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const Icon* icon = &I_ButtonUp_7x4;
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t x = 0;
const uint8_t y = 0 + button_height;
canvas_draw_box(canvas, x, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x + button_width + 0, y - button_height, x + button_width + 0, y - 1);
canvas_draw_line(canvas, x + button_width + 1, y - button_height, x + button_width + 1, y - 2);
canvas_draw_line(canvas, x + button_width + 2, y - button_height, x + button_width + 2, y - 3);
canvas_invert_color(canvas);
canvas_draw_icon(canvas, x + horizontal_offset, y - icon_v_offset, &I_ButtonUp_7x4);
canvas_draw_str(
canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
canvas_invert_color(canvas);
}
void elements_button_top_right(Canvas* canvas, const char* str) {
const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const Icon* icon = &I_ButtonUp_7x4;
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t x = canvas_width(canvas);
const uint8_t y = 0 + button_height;
canvas_draw_box(canvas, x - button_width, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x - button_width - 1, y - button_height, x - button_width - 1, y - 1);
canvas_draw_line(canvas, x - button_width - 2, y - button_height, x - button_width - 2, y - 2);
canvas_draw_line(canvas, x - button_width - 3, y - button_height, x - button_width - 3, y - 3);
canvas_invert_color(canvas);
canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
canvas_draw_icon(
canvas, x - horizontal_offset - icon->width, y - icon_v_offset, &I_ButtonUp_7x4);
canvas_invert_color(canvas);
}
static void render_callback(Canvas* const canvas, void* ctx) {
const MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25);
if(metronome_state == NULL) {
return;
}
string_t tempStr;
string_init(tempStr);
// border around the edge of the screen
canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_set_font(canvas, FontPrimary);
// draw bars/beat
@ -159,7 +109,6 @@ static void timer_callback(void* ctx) {
release_mutex((ValueMutex*)ctx, metronome_state);
}
static uint32_t state_to_sleep_ticks(MetronomeState* metronome_state) {
// calculate time between beeps
uint32_t tps = furi_kernel_get_tick_frequency();
@ -316,7 +265,7 @@ int32_t metronome_app() {
}
}
} else {
FURI_LOG_D("Hello_world", "FuriMessageQueue: event timeout");
FURI_LOG_D("Metronome", "FuriMessageQueue: event timeout");
// event timeout
}

Loading…
Cancel
Save