From c936efaecb16b3ee0873f322ff7d3471da673f9e Mon Sep 17 00:00:00 2001 From: Matthew Jennings Date: Sun, 11 May 2025 16:44:13 +0300 Subject: [PATCH] added an image to the example --- .../playdate-project-example/Source/star.png | Bin 0 -> 4511 bytes .../clay-video-demo-playdate.c | 36 ++++++++++++++---- examples/playdate-project-example/main.c | 4 +- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 examples/playdate-project-example/Source/star.png diff --git a/examples/playdate-project-example/Source/star.png b/examples/playdate-project-example/Source/star.png new file mode 100644 index 0000000000000000000000000000000000000000..1b33759871311d55e40725662082b2497b37ad35 GIT binary patch literal 4511 zcmeHKeNYtV8DB*N`7lOP6?N>oG$ESY-R|D)akt_4y5l~^EL`y#L`v)K-X3hZyFGUo z?w}JvjWr1~CXwKvp^YDyNz#xunXxg5A50;bF|CryBx*on;+Ry8n$g6DYWwcqfiS_g z%ryUTGkd%HywCG{pXc{{%)ZaK3mvIRi;^G+N_9DH#o!KuYiZ(4@J}TzSq^SJb)MC7 zF&&0OqTu8G94yy{IGBs@J_w4O3ApoS$1O|j9DX)?nyoyt_3VCE{mF}AkH6+@;dxU- z+J=+AIN>-@Z7W=Mfog2d&wbnbR{q1(sjkQQYq>Y(o?n?A+Iw@OD|9?%|E=NXi_dj+ zuJB~1eL0XkynpTcw{IRlR<>>Mryp%uykoJeHNIvO*}I47_^spPk7gv3MPIyl)$PpA00$fNOVy6q2jq|N_YC`$e`6}eh!+xtxr_&n_? z-fDHbtk#i$Kp3r0zF=|wId@6VFUuPDXlB>UsXlg+JY7(*r0Pe{x|f|wYA0KM{#`t^ zXxjq|99{c|hI*O)uAb78gp#~D|Af{pXnml(t@~dOZk~@VUGnW`1BZGC9y@yO4ZQ!d z3wqs`w!>3=>_W-r!IBwR1IjFHZh7s*Gt8pjeRgSS_Tj;v+U?)Io8wr$yd~w@tnOK_ zES`UT=JgL=*(VKVZ2jZgZF63pSF}*hJMVb&xc108t@-lB9rvfdv?F8doaBAl?FU<$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zQFm^Iwkp3Pu6{$;U(3o8uIb%GQ~6pw^!M+|7qrLE#e9uHT=CjfP-uHIf9=M910B{% Avj6}9 literal 0 HcmV?d00001 diff --git a/examples/playdate-project-example/clay-video-demo-playdate.c b/examples/playdate-project-example/clay-video-demo-playdate.c index 824edef..2d062ca 100644 --- a/examples/playdate-project-example/clay-video-demo-playdate.c +++ b/examples/playdate-project-example/clay-video-demo-playdate.c @@ -6,7 +6,8 @@ // // Note: The playdate console also does not support dynamic font sizes - fonts must be // created at a specific size with the pdc tool - so any font size set in the clay layout -// will have noe ffect. +// will have no effect. +#include "pd_api.h" #include "../../clay.h" #include @@ -32,6 +33,7 @@ void RenderHeaderButton(Clay_String text) { typedef struct { Clay_String title; Clay_String contents; + LCDBitmap* image; } Document; typedef struct { @@ -44,9 +46,10 @@ Document documentsRaw[MAX_DOCUMENTS]; DocumentArray documents = { .length = MAX_DOCUMENTS, .documents = documentsRaw }; -void ClayVideoDemo_Initialize(void) { +void ClayVideoDemoPlaydate_Initialize(PlaydateAPI* pd) { documents.documents[0] = (Document){ .title = CLAY_STRING("Squirrels"), + .image = pd->graphics->loadBitmap("star.png", NULL), .contents = CLAY_STRING( "The Secret Life of Squirrels: Nature's Clever Acrobats\n" "Squirrels are often overlooked creatures, dismissed as mere park " @@ -128,6 +131,7 @@ void ClayVideoDemo_Initialize(void) { }; documents.documents[1] = (Document){ .title = CLAY_STRING("Lorem Ipsum"), + .image = pd->graphics->loadBitmap("star.png", NULL), .contents = CLAY_STRING( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim " @@ -140,6 +144,7 @@ void ClayVideoDemo_Initialize(void) { }; documents.documents[2] = (Document){ .title = CLAY_STRING("Vacuum Instructions"), + .image = pd->graphics->loadBitmap("star.png", NULL), .contents = CLAY_STRING( "Chapter 3: Getting Started - Unpacking and Setup\n" "\n" @@ -192,7 +197,7 @@ void ClayVideoDemo_Initialize(void) { }; } -Clay_RenderCommandArray ClayVideoDemo_CreateLayout(int selectedDocumentIndex) { +Clay_RenderCommandArray ClayVideoDemoPlaydate_CreateLayout(int selectedDocumentIndex) { Clay_BeginLayout(); @@ -324,10 +329,27 @@ Clay_RenderCommandArray ClayVideoDemo_CreateLayout(int selectedDocumentIndex) { } }) { Document selectedDocument = documents.documents[selectedDocumentIndex]; - CLAY_TEXT( - selectedDocument.title, - CLAY_TEXT_CONFIG({ .fontId = FONT_ID_BODY, .textColor = COLOR_BLACK }) - ); + CLAY({ + .layout = { + .layoutDirection = CLAY_LEFT_TO_RIGHT, + .childGap = 4, + .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_BOTTOM } + } + }) { + CLAY_TEXT( + selectedDocument.title, + CLAY_TEXT_CONFIG({ .fontId = FONT_ID_BODY, .textColor = COLOR_BLACK }) + ); + CLAY({ + .layout = { + .sizing = { + .width = CLAY_SIZING_FIXED(32), + .height = CLAY_SIZING_FIXED(30) + } + }, + .image = { .imageData = selectedDocument.image, .sourceDimensions = { 32, 30 } } + }) {} + } CLAY_TEXT( selectedDocument.contents, CLAY_TEXT_CONFIG({ .fontId = FONT_ID_BODY, .textColor = COLOR_BLACK }) diff --git a/examples/playdate-project-example/main.c b/examples/playdate-project-example/main.c index 02164a8..1aaaaa3 100644 --- a/examples/playdate-project-example/main.c +++ b/examples/playdate-project-example/main.c @@ -69,7 +69,7 @@ int eventHandler(PlaydateAPI* pd, PDSystemEvent event, uint32_t eventArg) { (Clay_ErrorHandler){HandleClayErrors} ); Clay_SetMeasureTextFunction(PlayDate_MeasureText, &textUserData); - ClayVideoDemo_Initialize(); + ClayVideoDemoPlaydate_Initialize(pd); } return 0; @@ -108,7 +108,7 @@ static int update(void *userdata) { pd->system->getElapsedTime() ); - Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(selectedDocumentIndex); + Clay_RenderCommandArray renderCommands = ClayVideoDemoPlaydate_CreateLayout(selectedDocumentIndex); Clay_Playdate_Render(pd, renderCommands, textUserData.font); return 1;