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

CalcWordWrapPositionA issue #240

Closed
tinhajj opened this issue Jan 31, 2024 · 5 comments · Fixed by #241
Closed

CalcWordWrapPositionA issue #240

tinhajj opened this issue Jan 31, 2024 · 5 comments · Fixed by #241

Comments

@tinhajj
Copy link

tinhajj commented Jan 31, 2024

I'm trying to call CalcWordWrapPositionA on my current font, but it seems to always error
Basically just doing something along the lines of this in my draw loop

font := imgui.CurrentFont()
place := font.CalcWordWrapPositionA(1.0, "lines of text", 300)
fmt.Println("Wrap at", place)

I get this error File: D:/a/cimgui-go/cimgui-go/cimgui/imgui/imgui_draw.cpp, Line: 3515

I'm not too familiar with C and how it interops with Go so this is a little harder for me to debug. Can I get a sanity check from someone else that something is wrong here and I'm not misusing this api?

Incase its useful I am trying to use this function to implement this:
ocornut/imgui#2313

@tinhajj
Copy link
Author

tinhajj commented Jan 31, 2024

The only thing I can add is that the go definition for CalcWordWrapPositionA doesn't match the imgui definition in that text_end is missing in the go definition. Not sure if thats relevant.

@gucio321
Copy link
Collaborator

gucio321 commented Feb 1, 2024

The reason for this is because text_end in cimgui_wrapper.cpp is always set to 0 (aka NULL) by cmd/codegen.

In my opinion this isn't ok. GO should pass len(text) or even user-specified value here. and C will set text-end to text+text_len (it calculates pointer to text end - its C)

gucio321 added a commit to gucio321/cimgui-go that referenced this issue Feb 1, 2024
currently it was always set to 0 but it coems out that 0 is not always appropiate value.

In reference to AllenDang#240 some methods needs exact value. This commit uses pointer arythmetic
to calculate text_end if it is possible/needed. Now user can specify text_len argument (or put 0)
@tinhajj
Copy link
Author

tinhajj commented Feb 1, 2024

Thanks I tried this out, and CalcWordWrapPositionA now works. But the return value isn't as valuable as I had hoped. Since it gives back a string/single character, where I really need an index to the spot where the word wrap has to happen.

This change also changed the function signature of some text functions like TextUnformatted. Basically it required me to give a text_len param which makes it a little more cumbersome to use.

So it seems like we'd need a way to say that just CalcWordWrapPositionA should have a different return type, and also it should automatically pass a 'good' text_end value to cpp code

@gucio321
Copy link
Collaborator

gucio321 commented Feb 1, 2024

Well if you think go should automatically pass the right value there i can do that. In case of return type, i think it's a pointer to the spot where text should be wrapped. You can use pointer arithmetics to find it

@gucio321 gucio321 reopened this Feb 6, 2024
@gucio321
Copy link
Collaborator

I think I re-opened it by missclick (I don't see any comment justifying this re-openal). Let me close this and ping me if I'm wrong 😄

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 a pull request may close this issue.

2 participants