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] Provide information about source string to Clay_MeasureText #180

Open
Riquelme02 opened this issue Jan 10, 2025 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@Riquelme02
Copy link

Hello Nic,
I've been playing with Clay for a few weeks
now after a friend recommended it to me.

Unfortunately I've hit a brick wall when it comes to string handling when
I tried integrating it into an existing project. We handle text by shaping
our paragraphs with HarfBuzz and caching the result, which is an array of
glyph information - all further text operations work by specifying start
and end indices into that array. Meanwhile Clay can only give us raw strings
and no realistic method to extract the necessary indices from them.

To summarize: Clay provides a string slice, and what we
need is actually the start and end indices of that slice.
(we also need the entire original string, although this part I could easily
solve by passing around a handle to our cache through the element config).

Can you think of a feasible solution on Clay's side? I would love to
use this library without maintaing a local copy that does what I need.

@nicbarker
Copy link
Owner

Hello 👋
That sounds like the kind of thing we are likely to run into in future. We actually need to introduce a breaking change into the API for the text measurement callback anyway, so I'll get this one in too at the same time 🙂
Would it work to provide a pointer to the original entire string, so you can do pointer arithmetic on the string to measure to figure out the index?

@nicbarker
Copy link
Owner

nicbarker commented Jan 10, 2025

I'm imagining something like

Clay_Dimensions Clay_MeasureText(Clay_String toMeasure, Clay_String originalString, Clay_TextElementConfig *config) {
    int32_t startIndex = toMeasure.chars - originalString.chars;
    int32_t endIndex = startIndex + toMeasure.length;
}

@nicbarker nicbarker changed the title Problem with internal format of strings [Core] Provide information about source string to Clay_MeasureText Jan 10, 2025
@nicbarker nicbarker added the enhancement New feature or request label Jan 10, 2025
@Riquelme02
Copy link
Author

Thank you, I think pointer arithmetic should work.
What about the text render command? Is there already
an easy way to access this information during that step
or will you propagate these changes there as well?

@nicbarker
Copy link
Owner

@Riquelme02 I will investigate providing that information in the render command as well 👍

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

No branches or pull requests

2 participants