Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Access bounding boxes of scrolling containers #101

Closed
wants to merge 5 commits into from

Conversation

hexmaster111
Copy link

Moved a few internal types into public for other .c files that don't have clay_impl defined.

I was unable to get at the internal data from another c file, so I moved these defs up past the clay impl define.

Im using it to impl a slider control like this

            Clay_ScrollContainerData track = Clay_GetScrollContainerData(sliderId);
            Clay_ScrollContainerData thumb = Clay_GetScrollContainerData(thumbId);
            Clay__ScrollContainerDataInternal *track_internal_data = FindScrollContainerDataInternal(sliderId);
            Clay__ScrollContainerDataInternal *thumb_internal_data = FindScrollContainerDataInternal(thumbId);

            if (track.found && thumb.found && track_internal_data && thumb_internal_data)
            {
                // put the track where the users currsor is clicking on the track

                Vector2 mousePos = GetMousePosition();
                Vector2 trackPos = (Vector2){track_internal_data->boundingBox.x, track_internal_data->boundingBox.y};

                Vector2 mouseRelitiveToTrack = Vector2Subtract(mousePos, trackPos);
                Vector2 trackSize = (Vector2){track_internal_data->boundingBox.width, track_internal_data->boundingBox.height};

                Vector2 click_percent = (Vector2){
                    .x = ScailFloat(mouseRelitiveToTrack.x - thumb_internal_data->boundingBox.width * 0.5f, 0, trackSize.x - thumb_internal_data->boundingBox.width * 0.5f, 0, 1),
                    .y = ScailFloat(mouseRelitiveToTrack.y - thumb_internal_data->boundingBox.height * 0.5f, 0, trackSize.y - thumb_internal_data->boundingBox.height * 0.5f, 0, 1)};

                *value = Clamp(ScailFloat(click_percent.x, 0, 1, min, max), min, max);
            }

And the helper func to make searching for things a little nicer todo

Clay__ScrollContainerDataInternal *FindScrollContainerDataInternal(Clay_ElementId id)
{
    Clay__ScrollContainerDataInternal *find = NULL;
    for (int sidx = 0; sidx < Clay__scrollContainerDatas.length; sidx++)
    {
        find = Clay__ScrollContainerDataInternalArray_Get(
            &Clay__scrollContainerDatas,
            sidx);

        if (find->elementId == id.id)
        {
            break;
        }

        find = NULL;
    }

    return find;
}

@nicbarker
Copy link
Owner

Hello! Just to make sure I understand correctly, you want to access the bounding box of the scroll element?
If that's the case, I'll expand the public facing Clay_ScrollContainerData to include the bounding box so you can get it in one call, with the current api 🙂

@nicbarker nicbarker added the enhancement New feature or request label Dec 25, 2024
@nicbarker nicbarker changed the title Making the Bounding Boxes Public [Core] Access bounding boxes of scrolling containers Dec 25, 2024
@nicbarker
Copy link
Owner

That being said, there should probably be a public API for just querying the bounds of any element by id 🤔

@hexmaster111
Copy link
Author

Ah, yeah, I'm pretty sure me making them scroll boxes was a part of some earlier hacking around with clay. An API for getting the bounding box of any element would make a lot of sense!

@hexmaster111 hexmaster111 closed this by deleting the head repository Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants