Requesting an example of custom element provided by an application
I'm trying to follow the instructions for adding a CLAY_CUSTOM_ELEMENT. Currently using the Raylib renderer from this repository.
I can see that the renderer includes a sample for a 3D model. That's kind of "baked in" to the renderer. If I'm trying to define my own custom layout element, is the right approach to fork clay_renderer_raylib.c? Or is there some other way to extend the render instructions?
(Maybe I'm totally on the wrong track... my ultimate goal is to have a drawing surface that I can render to directly with Raylib. For that I think I need to get the bounding box provided by the layout engine. Is a custom element the best way for me to get the post-layout bounding box of my element?)
Custom elements are what you want here and you would need to fork the renderer, you can see from the code that it tries to show how you would make something extensible with CustomElementType being a tagged union.
(the implementation is a little weird though storing a pointer to the union in customData instead of inlining it with CLAY_EXTEND_CONFIG_CUSTOM)
For another example you can see our codebase, see also, where we call a user-defined callback with the element bounds, so you can write stuff like
local function DrawCross( x, y, w, h )
local thickness = w / 5
local padding = w / 10
cd.box( x + padding, y + h/2 - thickness/2, w - padding * 2, thickness, "#f00" )
cd.box( x + w/2 - thickness/2, y + padding, thickness, h - padding * 2, "#f00" )
end
cd.node( { width = 100, height = 100 }, DrawCross )
Thank you, that is exactly the guidance I was looking for.