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

[Bindings/Odin] Added missing public and private API function bindings #175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cstrachan88
Copy link

Added the missing bindings to the Odin source. All of the added procedures work as expected. With this, I was able to build an interactive example following the youtube tutorial. There is one issue getting this to work. Using Hovered as a condition to set the rectangle color unfortunately tests against the parent element, so all of the document title rectangles are highlighted. This can be seen at the start of the video. Everything else matches the youtube example, include the file menu.

demo.mp4
for d, i in documents {
  if u32(i) == selected_document_idx {
    if clay.UI(
      clay.Layout({padding = {16, 16}, sizing = clay.Sizing{width = clay.SizingGrow({})}}),
      clay.Rectangle({color = {120, 120, 120, 255}, cornerRadius = {8, 8, 8, 8}}),
    ) {
      clay.Text(d.title, clay.TextConfig({fontId = DEFAULT_FONT_ID, fontSize = 16, textColor = COLOR_WHITE}))
    }
  }
    else {
    if clay.UI(
      clay.Layout({padding = {16, 16}, sizing = clay.Sizing{width = clay.SizingGrow({})}}),
      // BUG: Hovered is triggering when the parent container is hovered
      clay.Rectangle({color = clay.Hovered() ? {120, 120, 120, 120} : {}, cornerRadius = {8, 8, 8, 8}}),
    ) {
      // NOTE: OnHover must be handled inside element - doesn't return a TypedConfig
      clay.OnHover(handle_hover, nil)
      clay.Text(d.title, clay.TextConfig({fontId = DEFAULT_FONT_ID, fontSize = 16, textColor = COLOR_WHITE}))
    }
  }
}

and

handle_hover :: proc "c" (elementId: clay.ElementId, pointerInfo: clay.PointerData, userData: rawptr) {
  context = state.ctx
  // NOTE: Using offset here since it is sequential from 0 and matches the document index
  if pointerInfo.state == .PRESSED_THIS_FRAME {
    selected_document_idx = elementId.offset
  }
}

@cstrachan88 cstrachan88 changed the title Added missing public and private API function bindings [Bindings/Odin] Added missing public and private API function bindings Jan 8, 2025
@nicbarker
Copy link
Owner

Hi @cstrachan88, thanks so much for opening this! I will take a closer look today or tomorrow 🙂

@cstrachan88
Copy link
Author

👍

I think my auto-formatting triggered on a couple of the procedures, but I only added the PointerData structs and matched the "Function Forward Declarations" section in clay.h

@cstrachan88
Copy link
Author

I've updated my bindings to match some of the latest API changes but haven't finished yet. I'm travelling over the next two days and will ping with another PR when it's all synced up if that helps.

@nicbarker nicbarker force-pushed the main branch 2 times, most recently from 4fd677e to 338852b Compare January 14, 2025 08:46
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.

2 participants