Skip to content

Conversation

@filippocrocchini
Copy link

@filippocrocchini filippocrocchini commented Aug 24, 2025

Ignore the CLAY_NAMED stuff, that is a duplicate implementation of #492 and will get removed once it's merged.

In my experience rolling out my own immediate mode UI libraries, I have gravitated towards having a core layout engine which you can hook into to do things at different times in the pipeline. Be it rendering, input and whatnot.

I don't expect this to be merged in as it's incomplete first of all, but I believe this kind of API could allow the debug visualization, rendering, input and more to be separated from the core. I believe you are working towards that and here are my two cents on that.

I would love feedback on this, especially regarding how it would interact with floating elements. I am almost 100% sure that, as it is, it won't work in some corner cases.

Stripped down input example:

    void process_input_on_element(void* userData, uint32_t id, Clay_ElementData data, Clay_LayoutConfig* layout, Clay_ElementState state)
    {
        auto visible_region = data.visibleBoundingBox;

        if (state == CLAY_ELEMENT_STATE_OPEN)
        {
            if (contains(visible_region, cursor_position)) {
                if (mouse_owner == id && left_button_down)
                {
                    pressed_id  = id;
                }
                if (mouse_owner == id && left_button_just_released)
                {
                    clicked_id  = id;
                    mouse_owner = 0;
                }
            }
        }

        // Here we do it on end finalize, because we want to give ownership of the input to the deepest node that is
        // currently hovered. This doesn't always work especially with floating elements. However, if we had a zIndex
        // for every element then it should work. 
        
        if (state == CLAY_ELEMENT_STATE_END_FINALIZE)
        {
            if (contains(visible_region, cursor_position))
            {
                if (left_button_just_pressed && !new_mouse_owner && is_clickable(id))
                {
                    new_mouse_owner = id;
                    mouse_owner     = id;
                }
            }
        }
    }

@filippocrocchini filippocrocchini changed the title Experimental Core API (?) [Core] Experimental Core API (?) Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants