77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "display/renderbase.h"
|
|
#include "ui/font.h"
|
|
|
|
#define UI_TEXTBOX_LINES_PER_PAGE 4
|
|
#define UI_TEXTBOX_WIDTH RENDER_WIDTH
|
|
#define UI_TEXTBOX_HEIGHT_INNER ( \
|
|
FONT_TILE_HEIGHT * UI_TEXTBOX_LINES_PER_PAGE \
|
|
)
|
|
|
|
#define UI_TEXTBOX_BORDER_WIDTH 4
|
|
#define UI_TEXTBOX_BORDER_HEIGHT UI_TEXTBOX_BORDER_WIDTH
|
|
#define UI_TEXTBOX_PADDING_X 2
|
|
#define UI_TEXTBOX_PADDING_Y UI_TEXTBOX_PADDING_X
|
|
#define UI_TEXTBOX_WIDTH_INNER ( \
|
|
UI_TEXTBOX_WIDTH - (UI_TEXTBOX_BORDER_WIDTH * 2) - \
|
|
(UI_TEXTBOX_PADDING_X * 2) \
|
|
)
|
|
#define UI_TEXTBOX_HEIGHT ( \
|
|
UI_TEXTBOX_HEIGHT_INNER + (UI_TEXTBOX_BORDER_HEIGHT * 2) + \
|
|
(UI_TEXTBOX_PADDING_Y * 2) \
|
|
)
|
|
|
|
#define UI_TEXTBOX_CHARS_PER_LINE (UI_TEXTBOX_WIDTH_INNER / FONT_TILE_WIDTH)
|
|
#define UI_TEXTBOX_CHARS_PER_PAGE ( \
|
|
UI_TEXTBOX_CHARS_PER_LINE * UI_TEXTBOX_LINES_PER_PAGE \
|
|
)
|
|
#define UI_TEXTBOX_PAGE_COUNT_MAX 6
|
|
#define UI_TEXTBOX_LINE_COUNT ( \
|
|
UI_TEXTBOX_LINES_PER_PAGE * UI_TEXTBOX_PAGE_COUNT_MAX \
|
|
)
|
|
#define UI_TEXTBOX_CHARS_MAX ( \
|
|
UI_TEXTBOX_CHARS_PER_PAGE * UI_TEXTBOX_PAGE_COUNT_MAX \
|
|
)
|
|
|
|
#define UI_TEXTBOX_REVEAL_RATE 2
|
|
|
|
typedef struct {
|
|
char_t text[UI_TEXTBOX_CHARS_MAX];
|
|
uint8_t lineLengths[UI_TEXTBOX_LINE_COUNT];
|
|
uint8_t pageCount;
|
|
uint8_t pageChars[UI_TEXTBOX_PAGE_COUNT_MAX];
|
|
uint16_t totalChars;
|
|
|
|
uint8_t page;
|
|
uint8_t charsRevealed;
|
|
|
|
bool_t visible;
|
|
} uitextbox_t;
|
|
|
|
extern uitextbox_t UI_TEXTBOX;
|
|
|
|
/**
|
|
* Initializes the UI textbox.
|
|
*/
|
|
void uiTextboxInit(void);
|
|
|
|
/**
|
|
* Updates the UI textbox, handling text input and scrolling.
|
|
*/
|
|
void uiTextboxUpdate(void);
|
|
|
|
/**
|
|
* Sets the text for the UI textbox.
|
|
*
|
|
* @param text The text to display in the textbox.
|
|
*/
|
|
void uiTextboxSetText(
|
|
const char_t *text
|
|
); |