cdk_objs(3)

πŸ’– cdk_objs β€” Cdk object-support functions πŸ’–

okay bestie, welcome to cdk_objs(3), a little Library calls page from the Cdk universe. pull up a chair, grab a strawberry πŸ“, and let's talk about how Cdk fakes objects in a language that has, like, zero object support. it's giving "we ball" but make it C. ✨


🌸 SYNOPSIS 🌸

cc [ flag ... ] file ...  -lcdk [ library ... ]

void cleanCdkTitle (
               CDKOBJS *obj);

void drawCdkTitle (
               WINDOW *window,
               CDKOBJS *object);

char * getCdkTitle (
               CDKOBJS *obj);

void positionCDKObject (
               CDKOBJS *object,
               WINDOW *win);

void setCDKObjectBackgroundColor (
               CDKOBJS *object,
               const 3char *color);

void setCDKObjectPostProcess (
               CDKOBJS *object,
               PROCESSFN func,
               void *data);

void setCDKObjectPreProcess (
               CDKOBJS *object,
               PROCESSFN func,
               void *data);

void setCdkExitType(
               CDKOBJS *obj,
               EExitType *type,
               chtyp ch);

int setCdkTitle (
               CDKOBJS *obj,
               const char *title,
               int boxWidth);

bool validCDKObject (
               CDKOBJS *obj);

πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea β˜•: Cdk is written in ANSI C, and ANSI C has "no" object support. (scare quotes fully intended, we're being shady.) so most of the object support in Cdk is done using macros plus a tiny handful of types that hold all the object info. and those types are:

  • CDKFUNCS β€” this one holds the function pointers for the common methods of the widgets. it's kept separate from CDKOBJS because it gets compiled into each widget's own C code (peep the DeclareCDKObjects() and DeclareSetXXchar() macros, iykyk). the widget instances just point at a single copy of CDKFUNCS per widget. frugal queen. πŸ‘‘
  • CDKOBJS β€” this holds the data that's common to all objects (aka widget instances). it shows up first in each widget's struct, which is the whole trick that lets Cdk use generic functions over in binding.c, cdkscreen.c, position.c, etc. main character energy, honestly. πŸ’…

✨ AVAILABLE FUNCTIONS ✨

the functions declared in <cdk_objs.h> exist for the situations where the expressions are just, like, way too complex for a macro. macro girlies, this one's for you when the macro stops macroing. 😭

  • cleanCdkTitle β€” nukes the storage for the widget's title. goodbye title storage, it was real 🫢
  • drawCdkTitle β€” draws the widget's title. that's it, that's the job, and it does it gorgeously.
  • getCdkTitle β€” hands you back the widget's title as a string. colors are encoded exactly the way cdk_display(3) describes. aaand if your title is multi-line, the lines of text are separated by "<#10>" markers (which is an encoded newline, sneaky right?). 🌈
  • positionCDKObject β€” this is the one that lets the user grab the cursor keys and physically adjust where the widget is sitting. drag-and-drop but make it keyboard ⌨️
  • setCDKObjectBackgroundColor β€” sets the background color of the widget. aesthetic customization, we love to see it. 🎨
  • setCDKObjectPostProcess β€” sets the data for postprocessing.
  • setCDKObjectPreProcess β€” sets the data for preprocessing. (pre vs post, the eternal sibling rivalry πŸ™ˆ)
  • setCdkExitType β€” sets the object's exit-type based on the input. and okay, quick lore drop: the .exitType field should have been part of the CDKOBJS struct, but it's used way too pervasively in Cdk4 applications to move it now. so here we are, it lives elsewhere, we deal. πŸ’€
  • setCdkTitle β€” sets the widget's title. yes, the counterpart to the getter, we're balanced like that. ⭐
  • validCDKObject β€” returns true if a "new" was done on the object but no "destroy". like, is this thing alive? vibe check passed? πŸ‘€
not me lovingly documenting a struct layout at 2am. anyway. 🧚

πŸ‘‘ SEE ALSO πŸ‘‘

cdk_binding(3), cdk_display(3), cdk_process(3).


that's the whole page bestie, you ate it up fr fr. this was the cdk_objs(3) manual page, dated 2024-03-28, and it ships with the Cdk library (that's the same source/version fam). now go write some widgets, periodt. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from