From ae27eddcabbfc132720d5a7c24364993a28bca76 Mon Sep 17 00:00:00 2001 From: Matthew Jennings Date: Mon, 5 May 2025 19:39:23 +0300 Subject: [PATCH] setup some interactivity with the dpad --- CMakeLists.txt | 4 +- examples/playdate-project-example/.gitignore | 1 + examples/playdate-project-example/README.md | 37 ++++ .../clay-video-demo-playdate.c | 195 ++++++++++++++++++ examples/playdate-project-example/main.c | 91 ++++---- renderers/playdate/clay_renderer_playdate.c | 99 ++++----- 6 files changed, 334 insertions(+), 93 deletions(-) create mode 100644 examples/playdate-project-example/README.md create mode 100644 examples/playdate-project-example/clay-video-demo-playdate.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bb05c5..5b166fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,9 @@ if(CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_SOKOL_EXAMPLES) add_subdirectory("examples/sokol-video-demo") add_subdirectory("examples/sokol-corner-radius") endif() -if(CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_PLAYDATE_EXAMPLES) + +# Playdate example not included in ALL because users need to install the playdate SDK first which requires a license agreement +if(CLAY_INCLUDE_PLAYDATE_EXAMPLES) add_subdirectory("examples/playdate-project-example") endif() diff --git a/examples/playdate-project-example/.gitignore b/examples/playdate-project-example/.gitignore index fd2fd96..736b2f4 100644 --- a/examples/playdate-project-example/.gitignore +++ b/examples/playdate-project-example/.gitignore @@ -1,2 +1,3 @@ clay_playdate_example.pdx Source/pdex.dylib +Source/pdex.elf diff --git a/examples/playdate-project-example/README.md b/examples/playdate-project-example/README.md new file mode 100644 index 0000000..a9f9a13 --- /dev/null +++ b/examples/playdate-project-example/README.md @@ -0,0 +1,37 @@ +# Playdate console example + +This example uses a modified version of the document viewer application from the Clay video demo. The Playdate console has a very small black and white screen, so some of the fixed sizes and styles needed to be modified to make the application usable on the console. The selected document can be changed using up/down on the D-pad, and the selected document can be scrolled with the crank. + +## Building + +You need to have the (Playdate SDK)[https://play.date/dev/] installed to be able to build this example. Once it's installed you can build it by adding -DCLAY_INCLUDE_PLAYDATE_EXAMPLES=ON when initialising a directory with cmake. + +e.g. + +``` +cmake -DCLAY_INCLUDE_PLAYDATE_EXAMPLES=ON cmake-build-debug +``` + +And then build it: + +``` +cmake --build cmake-build-debug +``` + +The pdx file will be located at examples/playdate-project-example/clay_playdate_example.pdx. You can then open it with the Playdate simulator. + +## Building for the playdate device + +By default the building this example will produce a pdx which can only run on the Playdate simulator application. To build a pdx that can run on the Playdate hardware you need to set the toolchain to use armgcc, toolchain file to the arm.cmake provided in the playdate SDK and make sure to disable the other examples. The Playdate hardware requires threads to be disabled which is not compatible with some of the other examples. + +e.g. To setup the cmake-build-release directory for device builds: + +``` +cmake -DTOOLCHAIN=armgcc -DCMAKE_TOOLCHAIN_FILE=/Users/mattahj/Developer/PlaydateSDK/C_API/buildsupport/arm.cmake -DCLAY_INCLUDE_ALL_EXAMPLES=OFF -DCLAY_INCLUDE_PLAYDATE_EXAMPLES=ON -B cmake-build-release +``` + +And then build it: + +``` +cmake --build cmake-build-release +``` diff --git a/examples/playdate-project-example/clay-video-demo-playdate.c b/examples/playdate-project-example/clay-video-demo-playdate.c new file mode 100644 index 0000000..795e6c6 --- /dev/null +++ b/examples/playdate-project-example/clay-video-demo-playdate.c @@ -0,0 +1,195 @@ +// This is the video demo with some adjustments so it works on the playdate console +// The playdate screen is only 400x240 pixels and it can only display black and white, so some +// fixed sizes and colours needed tweaking! +#include "../../clay.h" +#include + +const int FONT_ID_BODY_16 = 0; +Clay_Color COLOR_WHITE = { 255, 255, 255, 255}; +Clay_Color COLOR_BLACK = { 0, 0, 0, 255}; + +void RenderHeaderButton(Clay_String text) { + CLAY({ + .layout = { .padding = { 8, 8, 4, 4 }}, + .backgroundColor = COLOR_BLACK, + .cornerRadius = CLAY_CORNER_RADIUS(4) + }) { + CLAY_TEXT(text, CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 8, + .textColor = COLOR_WHITE + })); + } +} + +typedef struct { + Clay_String title; + Clay_String contents; +} Document; + +typedef struct { + Document *documents; + uint32_t length; +} DocumentArray; + +#define MAX_DOCUMENTS 3 +Document documentsRaw[MAX_DOCUMENTS]; + +DocumentArray documents = { + .length = MAX_DOCUMENTS, + .documents = documentsRaw +}; + +typedef struct { + intptr_t offset; + intptr_t memory; +} ClayVideoDemo_Arena; + +void ClayVideoDemo_Initialize(void) { + documents.documents[0] = (Document){ .title = CLAY_STRING("Squirrels"), .contents = CLAY_STRING("The Secret Life of Squirrels: Nature's Clever Acrobats\n""Squirrels are often overlooked creatures, dismissed as mere park inhabitants or backyard nuisances. Yet, beneath their fluffy tails and twitching noses lies an intricate world of cunning, agility, and survival tactics that are nothing short of fascinating. As one of the most common mammals in North America, squirrels have adapted to a wide range of environments from bustling urban centers to tranquil forests and have developed a variety of unique behaviors that continue to intrigue scientists and nature enthusiasts alike.\n""\n""Master Tree Climbers\n""At the heart of a squirrel's skill set is its impressive ability to navigate trees with ease. Whether they're darting from branch to branch or leaping across wide gaps, squirrels possess an innate talent for acrobatics. Their powerful hind legs, which are longer than their front legs, give them remarkable jumping power. With a tail that acts as a counterbalance, squirrels can leap distances of up to ten times the length of their body, making them some of the best aerial acrobats in the animal kingdom.\n""But it's not just their agility that makes them exceptional climbers. Squirrels' sharp, curved claws allow them to grip tree bark with precision, while the soft pads on their feet provide traction on slippery surfaces. Their ability to run at high speeds and scale vertical trunks with ease is a testament to the evolutionary adaptations that have made them so successful in their arboreal habitats.\n""\n""Food Hoarders Extraordinaire\n""Squirrels are often seen frantically gathering nuts, seeds, and even fungi in preparation for winter. While this behavior may seem like instinctual hoarding, it is actually a survival strategy that has been honed over millions of years. Known as \"scatter hoarding,\" squirrels store their food in a variety of hidden locations, often burying it deep in the soil or stashing it in hollowed-out tree trunks.\n""Interestingly, squirrels have an incredible memory for the locations of their caches. Research has shown that they can remember thousands of hiding spots, often returning to them months later when food is scarce. However, they don't always recover every stash some forgotten caches eventually sprout into new trees, contributing to forest regeneration. This unintentional role as forest gardeners highlights the ecological importance of squirrels in their ecosystems.\n""\n""The Great Squirrel Debate: Urban vs. Wild\n""While squirrels are most commonly associated with rural or wooded areas, their adaptability has allowed them to thrive in urban environments as well. In cities, squirrels have become adept at finding food sources in places like parks, streets, and even garbage cans. However, their urban counterparts face unique challenges, including traffic, predators, and the lack of natural shelters. Despite these obstacles, squirrels in urban areas are often observed using human infrastructure such as buildings, bridges, and power lines as highways for their acrobatic escapades.\n""There is, however, a growing concern regarding the impact of urban life on squirrel populations. Pollution, deforestation, and the loss of natural habitats are making it more difficult for squirrels to find adequate food and shelter. As a result, conservationists are focusing on creating squirrel-friendly spaces within cities, with the goal of ensuring these resourceful creatures continue to thrive in both rural and urban landscapes.\n""\n""A Symbol of Resilience\n""In many cultures, squirrels are symbols of resourcefulness, adaptability, and preparation. Their ability to thrive in a variety of environments while navigating challenges with agility and grace serves as a reminder of the resilience inherent in nature. Whether you encounter them in a quiet forest, a city park, or your own backyard, squirrels are creatures that never fail to amaze with their endless energy and ingenuity.\n""In the end, squirrels may be small, but they are mighty in their ability to survive and thrive in a world that is constantly changing. So next time you spot one hopping across a branch or darting across your lawn, take a moment to appreciate the remarkable acrobat at work a true marvel of the natural world.\n") }; + documents.documents[1] = (Document){ .title = CLAY_STRING("Lorem Ipsum"), .contents = CLAY_STRING("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") }; + documents.documents[2] = (Document){ .title = CLAY_STRING("Vacuum Instructions"), .contents = CLAY_STRING("Chapter 3: Getting Started - Unpacking and Setup\n""\n""Congratulations on your new SuperClean Pro 5000 vacuum cleaner! In this section, we will guide you through the simple steps to get your vacuum up and running. Before you begin, please ensure that you have all the components listed in the \"Package Contents\" section on page 2.\n""\n""1. Unboxing Your Vacuum\n""Carefully remove the vacuum cleaner from the box. Avoid using sharp objects that could damage the product. Once removed, place the unit on a flat, stable surface to proceed with the setup. Inside the box, you should find:\n""\n"" The main vacuum unit\n"" A telescoping extension wand\n"" A set of specialized cleaning tools (crevice tool, upholstery brush, etc.)\n"" A reusable dust bag (if applicable)\n"" A power cord with a 3-prong plug\n"" A set of quick-start instructions\n""\n""2. Assembling Your Vacuum\n""Begin by attaching the extension wand to the main body of the vacuum cleaner. Line up the connectors and twist the wand into place until you hear a click. Next, select the desired cleaning tool and firmly attach it to the wand's end, ensuring it is securely locked in.\n""\n""For models that require a dust bag, slide the bag into the compartment at the back of the vacuum, making sure it is properly aligned with the internal mechanism. If your vacuum uses a bagless system, ensure the dust container is correctly seated and locked in place before use.\n""\n""3. Powering On\n""To start the vacuum, plug the power cord into a grounded electrical outlet. Once plugged in, locate the power switch, usually positioned on the side of the handle or body of the unit, depending on your model. Press the switch to the \"On\" position, and you should hear the motor begin to hum. If the vacuum does not power on, check that the power cord is securely plugged in, and ensure there are no blockages in the power switch.\n""\n""Note: Before first use, ensure that the vacuum filter (if your model has one) is properly installed. If unsure, refer to \"Section 5: Maintenance\" for filter installation instructions.") }; +} + +Clay_RenderCommandArray ClayVideoDemo_CreateLayout(int selectedDocumentIndex) { + + Clay_BeginLayout(); + + Clay_Sizing layoutExpand = { + .width = CLAY_SIZING_GROW(0), + .height = CLAY_SIZING_GROW(0) + }; + + Clay_BorderElementConfig contentBorders = { + .color = COLOR_BLACK, + .width = { .top = 1, .left = 1, .right = 1, .bottom = 1 } + }; + + // Build UI here + CLAY({ .id = CLAY_ID("OuterContainer"), + .backgroundColor = COLOR_WHITE, + .layout = { + .layoutDirection = CLAY_TOP_TO_BOTTOM, + .sizing = layoutExpand, + .padding = CLAY_PADDING_ALL(8), + .childGap = 4 + } + }) { + // Child elements go inside braces + CLAY({ .id = CLAY_ID("HeaderBar"), + .layout = { + .sizing = { + .height = CLAY_SIZING_FIXED(30), + .width = CLAY_SIZING_GROW(0) + }, + .childGap = 8, + .childAlignment = { + .y = CLAY_ALIGN_Y_CENTER + } + }, + }) { + // Header buttons go here + CLAY({ .id = CLAY_ID("FileButton"), + .layout = { .padding = { 8, 8, 4, 4 }}, + .backgroundColor = COLOR_BLACK, + .cornerRadius = CLAY_CORNER_RADIUS(4) + }) { + CLAY_TEXT(CLAY_STRING("File"), CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 8, + .textColor = COLOR_WHITE + })); + } + RenderHeaderButton(CLAY_STRING("Edit")); + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0) }}}) {} + RenderHeaderButton(CLAY_STRING("Upload")); + RenderHeaderButton(CLAY_STRING("Media")); + RenderHeaderButton(CLAY_STRING("Support")); + } + + CLAY({ + .id = CLAY_ID("LowerContent"), + .layout = { .sizing = layoutExpand, .childGap = 8 }, + }) { + CLAY({ + .id = CLAY_ID("Sidebar"), + .border = contentBorders, + .cornerRadius = 4, + .layout = { + .layoutDirection = CLAY_TOP_TO_BOTTOM, + .padding = CLAY_PADDING_ALL(8), + .childGap = 4, + .sizing = { + .width = CLAY_SIZING_FIXED(125), + .height = CLAY_SIZING_GROW(0) + } + } + }) { + for (int i = 0; i < documents.length; i++) { + Document document = documents.documents[i]; + Clay_LayoutConfig sidebarButtonLayout = { + .sizing = { .width = CLAY_SIZING_GROW(0) }, + .padding = CLAY_PADDING_ALL(8) + }; + + if (i == selectedDocumentIndex) { + CLAY({ + .layout = sidebarButtonLayout, + .backgroundColor = COLOR_BLACK, + .cornerRadius = CLAY_CORNER_RADIUS(4) + }) { + CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 10, + .textColor = COLOR_WHITE + })); + } + } else { + CLAY({ + .layout = sidebarButtonLayout, + .backgroundColor = (Clay_Color) { 0, 0, 0, Clay_Hovered() ? 120 : 0 }, + .cornerRadius = CLAY_CORNER_RADIUS(4), + .border = contentBorders + }) { + CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 10, + .textColor = COLOR_BLACK, + })); + } + } + } + } + + CLAY({ .id = CLAY_ID("MainContent"), + .border = contentBorders, + .cornerRadius = 4, + .clip = { .vertical = true, .childOffset = Clay_GetScrollOffset() }, + .layout = { + .layoutDirection = CLAY_TOP_TO_BOTTOM, + .childGap = 8, + .padding = CLAY_PADDING_ALL(8), + .sizing = layoutExpand + } + }) { + Document selectedDocument = documents.documents[selectedDocumentIndex]; + CLAY_TEXT(selectedDocument.title, CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 12, + .textColor = COLOR_BLACK + })); + CLAY_TEXT(selectedDocument.contents, CLAY_TEXT_CONFIG({ + .fontId = FONT_ID_BODY_16, + .fontSize = 12, + .textColor = COLOR_BLACK + })); + } + } + } + + Clay_RenderCommandArray renderCommands = Clay_EndLayout(); + for (int32_t i = 0; i < renderCommands.length; i++) { + Clay_RenderCommandArray_Get(&renderCommands, i); + } + return renderCommands; +} diff --git a/examples/playdate-project-example/main.c b/examples/playdate-project-example/main.c index 45305d8..4c3f3d2 100644 --- a/examples/playdate-project-example/main.c +++ b/examples/playdate-project-example/main.c @@ -4,7 +4,7 @@ #include "../../clay.h" #include "../../renderers/playdate/clay_renderer_playdate.c" -#include "../shared-layouts/clay-video-demo.c" +#include "clay-video-demo-playdate.c" static int update(void *userdata); const char *fontpath = "/System/Fonts/Asheville-Sans-14-Bold.pft"; @@ -17,18 +17,18 @@ struct TextUserData { PlaydateAPI *pd; }; -static struct TextUserData gTextUserData = {.font = NULL, .pd = NULL}; -static ClayVideoDemo_Data demoData; +static struct TextUserData testUserData = {.font = NULL, .pd = NULL}; -static Clay_Dimensions PlayDate_MeasureText(Clay_StringSlice text, - Clay_TextElementConfig *config, - void *userData) { - // TODO: playdate needs to load fonts at the given size, so need to do that - // before we can use different font sizes! +static Clay_Dimensions PlayDate_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) { + // TODO: playdate needs to load fonts at the given size, so need to do that before we can use different font sizes! struct TextUserData *textUserData = userData; int width = textUserData->pd->graphics->getTextWidth( - textUserData->font, text.chars, - utf8_count_codepoints(text.chars, text.length), kUTF8Encoding, 0); + textUserData->font, + text.chars, + utf8_count_codepoints(text.chars, text.length), + kUTF8Encoding, + 0 + ); int height = textUserData->pd->graphics->getFontHeight(textUserData->font); return (Clay_Dimensions){ .width = (float)width, @@ -39,65 +39,66 @@ static Clay_Dimensions PlayDate_MeasureText(Clay_StringSlice text, #ifdef _WINDLL __declspec(dllexport) #endif -int eventHandler(PlaydateAPI* pd, PDSystemEvent event, uint32_t arg) +int eventHandler(PlaydateAPI* pd, PDSystemEvent event, uint32_t eventArg) { - (void)arg; // arg is currently only used for event = kEventKeyPressed - if (event == kEventInit) { const char *err; font = pd->graphics->loadFont(fontpath, &err); - if (font == NULL) - pd->system->error("%s:%i Couldn't load font %s: %s", __FILE__, __LINE__, - fontpath, err); + if (font == NULL) { + pd->system->error("%s:%i Couldn't load font %s: %s", __FILE__, __LINE__, fontpath, err); + } - gTextUserData.pd = pd; - gTextUserData.font = font; - - // Note: If you set an update callback in the kEventInit handler, the system - // assumes the game is pure C and doesn't run any Lua code in the game + testUserData.pd = pd; + testUserData.font = font; pd->system->setUpdateCallback(update, pd); uint64_t totalMemorySize = Clay_MinMemorySize(); - Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory( - totalMemorySize, pd->system->realloc(NULL, totalMemorySize)); - Clay_Initialize(clayMemory, - (Clay_Dimensions){(float)pd->display->getWidth(), - (float)pd->display->getHeight()}, - (Clay_ErrorHandler){HandleClayErrors}); - Clay_SetMeasureTextFunction(PlayDate_MeasureText, &gTextUserData); - demoData = ClayVideoDemo_Initialize(pd); + Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, pd->system->realloc(NULL, totalMemorySize)); + Clay_Initialize( + clayMemory, + (Clay_Dimensions){(float)pd->display->getWidth(), (float)pd->display->getHeight()}, + (Clay_ErrorHandler){HandleClayErrors} + ); + Clay_SetMeasureTextFunction(PlayDate_MeasureText, &testUserData); + ClayVideoDemo_Initialize(); } return 0; } -#define TEXT_WIDTH 86 -#define TEXT_HEIGHT 16 - -int x = (400 - TEXT_WIDTH) / 2; -int y = (240 - TEXT_HEIGHT) / 2; -int dx = 1; -int dy = 2; +int selectedDocumentIndex = 0; +#define WRAP_RANGE(x, N) ((((x) % (N)) + (N)) % (N)) static int update(void *userdata) { PlaydateAPI *pd = userdata; + PDButtons pushedButtons; + pd->system->getButtonState(NULL, &pushedButtons, NULL); + + if (pushedButtons & kButtonDown) { + selectedDocumentIndex = WRAP_RANGE(selectedDocumentIndex + 1, MAX_DOCUMENTS); + } else if (pushedButtons & kButtonUp) { + selectedDocumentIndex = WRAP_RANGE(selectedDocumentIndex - 1, MAX_DOCUMENTS); + } pd->graphics->clear(kColorWhite); pd->graphics->setFont(font); - Clay_SetPointerState((Clay_Vector2){.x = pd->display->getWidth() / 2.0f, - .y = pd->display->getHeight() / 2.0f}, - false); + // A bit hacky, setting the cursor on to the document view so it can be + // scrolled.. + Clay_SetPointerState((Clay_Vector2){ + .x = pd->display->getWidth() / 2.0f, + .y = pd->display->getHeight() / 2.0f + }, false); float crankDelta = pd->system->getCrankChange(); - Clay_UpdateScrollContainers(true, (Clay_Vector2){0, crankDelta * 0.25f}, - pd->system->getElapsedTime()); - Clay_RenderCommandArray renderCommands = - ClayVideoDemo_CreateLayout(&demoData); + Clay_UpdateScrollContainers( + false, + (Clay_Vector2){0, -crankDelta * 0.25f}, + pd->system->getElapsedTime() + ); + Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(selectedDocumentIndex); Clay_Playdate_Render(pd, renderCommands, font); - pd->system->drawFPS(0, 0); - return 1; } diff --git a/renderers/playdate/clay_renderer_playdate.c b/renderers/playdate/clay_renderer_playdate.c index 6bb7c10..7e17b62 100644 --- a/renderers/playdate/clay_renderer_playdate.c +++ b/renderers/playdate/clay_renderer_playdate.c @@ -28,7 +28,10 @@ static size_t utf8_count_codepoints(const char *str, size_t byte_len) { } static LCDColor clayColorToLCDColor(Clay_Color color) { - if (color.r == 255 && color.g == 255 && color.b == 255) { + // Convert the RGB to grayscale using the standard luminance formula + unsigned char grayscale_value = (unsigned char)(0.299 * color.r + 0.587 * color.g + 0.114 * color.b); + + if (grayscale_value > 128) { return kColorWhite; } return kColorBlack; @@ -42,27 +45,26 @@ static LCDBitmapDrawMode clayColorToDrawMode(Clay_Color color) { return kDrawModeCopy; } -static void Clay_Playdate_Render(PlaydateAPI *pd, - Clay_RenderCommandArray renderCommands, - LCDFont *fonts) { +static void Clay_Playdate_Render(PlaydateAPI *pd, Clay_RenderCommandArray renderCommands, LCDFont *fonts) { for (uint32_t i = 0; i < renderCommands.length; i++) { - Clay_RenderCommand *renderCommand = - Clay_RenderCommandArray_Get(&renderCommands, i); + Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, i); Clay_BoundingBox boundingBox = renderCommand->boundingBox; switch (renderCommand->commandType) { case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: { Clay_RectangleRenderData *config = &renderCommand->renderData.rectangle; struct Rect rect = (struct Rect){ - .x = boundingBox.x, - .y = boundingBox.y, - .w = boundingBox.width, - .h = boundingBox.height, + .x = boundingBox.x, + .y = boundingBox.y, + .w = boundingBox.width, + .h = boundingBox.height, }; if (config->cornerRadius.topLeft > 0) { pd->graphics->fillRoundRect( - rect.x, rect.y, rect.w, rect.h, config->cornerRadius.topLeft, - clayColorToLCDColor(config->backgroundColor)); + rect.x, rect.y, rect.w, rect.h, + config->cornerRadius.topLeft, + clayColorToLCDColor(config->backgroundColor) + ); } else { pd->graphics->fillRect(rect.x, rect.y, rect.w, rect.h, clayColorToLCDColor(config->backgroundColor)); @@ -76,32 +78,36 @@ static void Clay_Playdate_Render(PlaydateAPI *pd, // layout has.. LCDFont *font = fonts; struct Rect destination = (struct Rect){ - .x = boundingBox.x, - .y = boundingBox.y, - .w = boundingBox.width, - .h = boundingBox.height, + .x = boundingBox.x, + .y = boundingBox.y, + .w = boundingBox.width, + .h = boundingBox.height, }; pd->graphics->setDrawMode(clayColorToDrawMode(config->textColor)); pd->graphics->drawText( + renderCommand->renderData.text.stringContents.chars, + utf8_count_codepoints( renderCommand->renderData.text.stringContents.chars, - utf8_count_codepoints( - renderCommand->renderData.text.stringContents.chars, - renderCommand->renderData.text.stringContents.length), - kUTF8Encoding, destination.x, destination.y); + renderCommand->renderData.text.stringContents.length + ), + kUTF8Encoding, + destination.x, + destination.y + ); pd->graphics->setDrawMode(kDrawModeCopy); - break; } case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: { struct Rect currentClippingRectangle = (struct Rect){ - .x = boundingBox.x, - .y = boundingBox.y, - .w = boundingBox.width, - .h = boundingBox.height, + .x = boundingBox.x, + .y = boundingBox.y, + .w = boundingBox.width, + .h = boundingBox.height, }; pd->graphics->setClipRect( - currentClippingRectangle.x, currentClippingRectangle.y, - currentClippingRectangle.w, currentClippingRectangle.h); + currentClippingRectangle.x, currentClippingRectangle.y, + currentClippingRectangle.w, currentClippingRectangle.h + ); break; } case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: { @@ -111,44 +117,43 @@ static void Clay_Playdate_Render(PlaydateAPI *pd, case CLAY_RENDER_COMMAND_TYPE_IMAGE: { Clay_ImageRenderData *config = &renderCommand->renderData.image; LCDBitmap *texture = config->imageData; - struct Rect destination = (struct Rect){ - .x = boundingBox.x, - .y = boundingBox.y, - .w = boundingBox.width, - .h = boundingBox.height, + .x = boundingBox.x, + .y = boundingBox.y, + .w = boundingBox.width, + .h = boundingBox.height, }; - - pd->graphics->drawBitmap(texture, destination.x, destination.y, - kBitmapUnflipped); - + pd->graphics->drawBitmap(texture, destination.x, destination.y, kBitmapUnflipped); break; } case CLAY_RENDER_COMMAND_TYPE_BORDER: { Clay_BorderRenderData *config = &renderCommand->renderData.border; - struct Rect rect = (struct Rect){ - .x = boundingBox.x, - .y = boundingBox.y, - .w = boundingBox.width, - .h = boundingBox.height, + .x = boundingBox.x, + .y = boundingBox.y, + .w = boundingBox.width, + .h = boundingBox.height, }; // TODO: properly support the different border thickness and radius // instead of just using topLeft corner /top thickness as a global setting if (config->cornerRadius.topLeft > 0) { pd->graphics->drawRoundRect( - rect.x, rect.y, rect.w, rect.h, config->cornerRadius.topLeft, - config->width.top, clayColorToLCDColor(config->color)); + rect.x, rect.y, rect.w, rect.h, + config->cornerRadius.topLeft, + config->width.top, + clayColorToLCDColor(config->color) + ); } else { - pd->graphics->drawRect(rect.x, rect.y, rect.w, rect.h, - clayColorToLCDColor(config->color)); + pd->graphics->drawRect( + rect.x, rect.y, rect.w, rect.h, + clayColorToLCDColor(config->color) + ); } break; } default: { - pd->system->logToConsole("Error: unhandled render command: %d\n", - renderCommand->commandType); + pd->system->logToConsole("Error: unhandled render command: %d\n", renderCommand->commandType); return; } }