2022-10-12 02:01:37 +00:00
|
|
|
#include "ui_controls.h"
|
2022-11-10 05:32:21 +00:00
|
|
|
#include <totp_icons.h>
|
2022-10-12 02:01:37 +00:00
|
|
|
#include "constants.h"
|
|
|
|
|
2023-04-13 18:20:29 +00:00
|
|
|
#define TEXT_BOX_HEIGHT (13)
|
|
|
|
#define TEXT_BOX_MARGIN (4)
|
2022-10-12 02:01:37 +00:00
|
|
|
|
2022-11-10 05:32:21 +00:00
|
|
|
void ui_control_text_box_render(
|
|
|
|
Canvas* const canvas,
|
|
|
|
int16_t y,
|
|
|
|
const char* text,
|
|
|
|
bool is_selected) {
|
2022-10-13 14:00:20 +00:00
|
|
|
if(y < -TEXT_BOX_HEIGHT) {
|
2022-10-12 02:01:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
if(is_selected) {
|
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_MARGIN + y,
|
|
|
|
SCREEN_WIDTH - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_HEIGHT,
|
|
|
|
0);
|
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
TEXT_BOX_MARGIN - 1,
|
|
|
|
TEXT_BOX_MARGIN + y - 1,
|
|
|
|
SCREEN_WIDTH - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN + 2,
|
|
|
|
TEXT_BOX_HEIGHT + 2,
|
|
|
|
1);
|
2022-10-12 02:01:37 +00:00
|
|
|
} else {
|
2022-10-13 14:00:20 +00:00
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_MARGIN + y,
|
|
|
|
SCREEN_WIDTH - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_HEIGHT,
|
|
|
|
1);
|
2022-10-12 02:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
canvas_draw_str_aligned(
|
|
|
|
canvas, TEXT_BOX_MARGIN + 2, TEXT_BOX_MARGIN + 3 + y, AlignLeft, AlignTop, text);
|
2022-10-12 02:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
void ui_control_select_render(
|
|
|
|
Canvas* const canvas,
|
|
|
|
int16_t x,
|
|
|
|
int16_t y,
|
|
|
|
uint8_t width,
|
2022-11-10 05:32:21 +00:00
|
|
|
const char* text,
|
2022-10-13 14:00:20 +00:00
|
|
|
bool is_selected) {
|
|
|
|
if(y < -TEXT_BOX_HEIGHT) {
|
2022-10-12 02:01:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
if(is_selected) {
|
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
x + TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_MARGIN + y,
|
|
|
|
width - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_HEIGHT,
|
|
|
|
0);
|
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
x + TEXT_BOX_MARGIN - 1,
|
|
|
|
TEXT_BOX_MARGIN + y - 1,
|
|
|
|
width - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN + 2,
|
|
|
|
TEXT_BOX_HEIGHT + 2,
|
|
|
|
1);
|
2022-10-12 02:01:37 +00:00
|
|
|
} else {
|
2022-10-13 14:00:20 +00:00
|
|
|
canvas_draw_rframe(
|
|
|
|
canvas,
|
|
|
|
x + TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_MARGIN + y,
|
|
|
|
width - TEXT_BOX_MARGIN - TEXT_BOX_MARGIN,
|
|
|
|
TEXT_BOX_HEIGHT,
|
|
|
|
1);
|
2022-10-12 02:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
canvas_draw_str_aligned(
|
|
|
|
canvas, x + (width >> 1), TEXT_BOX_MARGIN + 3 + y, AlignCenter, AlignTop, text);
|
2022-11-10 05:32:21 +00:00
|
|
|
canvas_draw_icon(
|
|
|
|
canvas, x + TEXT_BOX_MARGIN + 2, TEXT_BOX_MARGIN + 2 + y, &I_totp_arrow_left_8x9);
|
|
|
|
canvas_draw_icon(
|
|
|
|
canvas, x + width - TEXT_BOX_MARGIN - 10, TEXT_BOX_MARGIN + 2 + y, &I_totp_arrow_right_8x9);
|
2022-10-12 02:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
void ui_control_button_render(
|
|
|
|
Canvas* const canvas,
|
|
|
|
int16_t x,
|
|
|
|
int16_t y,
|
|
|
|
uint8_t width,
|
|
|
|
uint8_t height,
|
2022-11-10 05:32:21 +00:00
|
|
|
const char* text,
|
2022-10-13 14:00:20 +00:00
|
|
|
bool is_selected) {
|
|
|
|
if(y < -height) {
|
2022-10-12 02:01:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
if(is_selected) {
|
2022-10-12 02:01:37 +00:00
|
|
|
canvas_draw_rbox(canvas, x, y, width, height, 1);
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
} else {
|
|
|
|
canvas_draw_rframe(canvas, x, y, width, height, 1);
|
|
|
|
}
|
|
|
|
|
2022-10-13 14:00:20 +00:00
|
|
|
canvas_draw_str_aligned(
|
|
|
|
canvas, x + (width >> 1), y + (height >> 1) + 1, AlignCenter, AlignCenter, text);
|
|
|
|
if(is_selected) {
|
2022-10-12 02:01:37 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
}
|
|
|
|
}
|