Incomplete list drawing code. More to come.

This commit is contained in:
That-One-Nerd 2025-06-25 13:36:12 -04:00
parent 72cbed8182
commit c754be2c9d
5 changed files with 111 additions and 19 deletions

22
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "CEdev",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/kyley/Desktop/Coding/Lib/CEdev/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.26100.0",
"compilerPath": "C:\\Users\\kyley\\Desktop\\Coding\\Lib\\CEdev\\bin\\ez80-clang.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"files.associations": {
"screen.h": "c",
"getcsc.h": "c"
}
}

View File

@ -1,19 +0,0 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <stdlib.h>
/* Main function, called first */
int main(void)
{
/* Clear the homescreen */
os_ClrHome();
/* Print a string */
os_PutStrFull("Hello, World.");
/* Waits for a key */
while (!os_GetCSC());
/* Return 0 for success */
return 0;
}

63
src/main.cpp Normal file
View File

@ -0,0 +1,63 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <stdlib.h>
#include "main.h"
void demo_func()
{
os_PutStrLine("and this is the demo func!\n");
}
list_item modes[] = {
{ "Option 1", demo_func },
{ "Option 2", nullptr },
{ "Option 3", nullptr },
{ "Option 4", nullptr },
{ "Option 5", nullptr },
{ "Option 6", nullptr },
{ "Option 7", nullptr },
{ "Option 8", nullptr },
{ "Option 9", nullptr },
{ "Option 10", demo_func },
{ nullptr, nullptr }
};
/* Main function, called first */
int main(void)
{
/* Clear the homescreen */
os_ClrHome();
list_config config;
config.start_row = 1;
config.end_row = 5;
display_list(modes, config);
/* Waits for a key */
while (!os_GetCSC());
/* Return 0 for success */
return 0;
}
int display_list(const list_item* list, const list_config& config)
{
size_t item_count = 0;
for (size_t i = 0; true; i++)
{
const list_item& item = list[i];
if (item.display_name == nullptr) break;
item_count++;
}
if (item_count == 0) return -1; // No list to display.
uint8_t max_on_screen = MIN(config.end_row - config.start_row, 10 - config.start_row) + 1;
uint24_t offset = 0;
for (size_t i = 0, j = offset; i < max_on_screen && j < item_count; i++, j++)
{
os_SetCursorPos(config.start_row + i, 0);
os_PutStrLine(list[j].display_name);
}
return -1;
}

20
src/main.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <inttypes.h>
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
typedef struct
{
const char* display_name;
void (*select_func)();
} list_item;
typedef struct
{
uint8_t start_row;
uint8_t end_row;
} list_config;
int display_list(const list_item* list, const list_config& config);