FL-819 new first start screen, add multiline text (#318)

* GUI Canvas: get current font height routine
* Dolphin: new start screen. GUI: new multiline element.
* Dolphin: up state version to reset it for everyone
* Dolphin: take maximum of idle screen height
* Dolphin: frames on first start screen.
This commit is contained in:
あく
2021-02-03 12:52:54 +03:00
committed by GitHub
parent 7481cfd6eb
commit cb4fb8e4ae
27 changed files with 109 additions and 22 deletions

View File

@@ -3,14 +3,6 @@
#include <furi.h>
struct Canvas {
u8g2_t fb;
uint8_t offset_x;
uint8_t offset_y;
uint8_t width;
uint8_t height;
};
uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr);
uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr);
@@ -70,6 +62,11 @@ uint8_t canvas_height(Canvas* canvas) {
return canvas->height;
}
uint8_t canvas_current_font_height(Canvas* canvas) {
furi_assert(canvas);
return u8g2_GetMaxCharHeight(&canvas->fb);
}
void canvas_clear(Canvas* canvas) {
furi_assert(canvas);
u8g2_ClearBuffer(&canvas->fb);

View File

@@ -1,7 +1,6 @@
#pragma once
#include <stdint.h>
#include <u8g2.h>
#include <gui/icon.h>
#include <assets_icons_i.h>
@@ -30,6 +29,12 @@ uint8_t canvas_width(Canvas* canvas);
*/
uint8_t canvas_height(Canvas* canvas);
/*
* Get current font height
* @return height in pixels.
*/
uint8_t canvas_current_font_height(Canvas* canvas);
/*
* Clear canvas, clear rendering buffer
*/

View File

@@ -1,6 +1,15 @@
#pragma once
#include "canvas.h"
#include <u8g2.h>
struct Canvas {
u8g2_t fb;
uint8_t offset_x;
uint8_t offset_y;
uint8_t width;
uint8_t height;
};
/*
* Allocate memory and initialize canvas

View File

@@ -1,6 +1,14 @@
#include "elements.h"
#include "canvas_i.h"
#include <furi.h>
#include <string.h>
#include <m-string.h>
void elements_scrollbar(Canvas* canvas, uint8_t pos, uint8_t total) {
furi_assert(canvas);
uint8_t width = canvas_width(canvas);
uint8_t height = canvas_height(canvas);
// prevent overflows
@@ -19,6 +27,8 @@ void elements_scrollbar(Canvas* canvas, uint8_t pos, uint8_t total) {
}
void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
furi_assert(canvas);
canvas_draw_line(canvas, x + 2, y, x + width - 2, y);
canvas_draw_line(canvas, x + 1, y + height - 1, x + width, y + height - 1);
canvas_draw_line(canvas, x + 2, y + height, x + width - 1, y + height);
@@ -28,4 +38,27 @@ void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t
canvas_draw_line(canvas, x + width, y + 2, x + width, y + height - 2);
canvas_draw_dot(canvas, x + 1, y + 1);
}
}
void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, char* text) {
furi_assert(canvas);
furi_assert(text);
uint8_t font_height = canvas_current_font_height(canvas);
string_t str;
string_init(str);
char* start = text;
char* end;
do {
end = strchr(start, '\n');
if(end) {
string_set_strn(str, start, end - start);
} else {
string_set_str(str, start);
}
canvas_draw_str(canvas, x, y, string_get_cstr(str));
start = end + 1;
y += font_height;
} while(end);
string_clear(str);
}

View File

@@ -22,6 +22,13 @@ void elements_scrollbar(Canvas* canvas, uint8_t pos, uint8_t total);
*/
void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
/*
* Draw multiline text
* @param x, y - top left corner coordinates
* @param text - string (possible multiline)
*/
void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, char* text);
#ifdef __cplusplus
}
#endif

View File

@@ -3,6 +3,9 @@
#include <input/input.h>
#include "canvas.h"
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif