-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
ImStrv: Use a string span for consuming strings in API #3038
base: master
Are you sure you want to change the base?
Conversation
This looks awesome, we also use IMGUI in Rust where we have string slices instead of null-terminated string pointers. And we also use IMGUI inside a WASM sandbox where we explicitly have to transfer the exact right memory between WASM and the host and where string slices with explicit length are a lot easier, faster, and safer than loose null-terminated string pointers where one have to dynamically determine the length of them for the marshalling. So would love to see this integrated in to core IMGUI! |
Good to hear! Would you care to try this branch with your application? This PR may have issues or things missing. Real world experience would be invaluable for finishing this PR and merging it. |
Unfortunately it would be a bit tricky for us to try it I think because we use IMGUI through But @Jasper-Bekkers and @MaikKlein in our team here at Embark have more experience with how that works and may be able to give feedback about this PR |
No need to immediately act upon that in PR, but as C++20 is aiming at inconveniently making UTF-8 literal Another one is that it would facilitate a path where wchar_t could be supported as the default compile-time target, to support e.g. Unreal Engine without utf-8 > wchar_t conversions. |
@ocornut Is this PR something you'd consider merge in in the near future? |
Hello, Not super “near” future as I don’t have resources to review/tweak it thoroughly the way I’d like (considering concerns such as cognitive and debug overhead for c++ users) but I imagine we should be able to tackle it in 2020, which is the reason I asked Rokas to revive the old PR. Real world feedback would also be helpful. If there’s traction, one possibility is to first merge the changed function signatures which constitute the bulk of the diff, so the remaining diff gets easier to update for as long as this is not fulled solved. |
Getting the updated function signatures in would already help us quite a bit. Having strings the way they are now has had quite an impact on imgui-s for us so investigating changes there would also take some time. |
Since the PR only mentions Rust, I just wanted to mention that this would also really benefit my usecase of using imgui from D. |
28b7728
to
4a5858d
Compare
"Real world feedback would also be helpful." |
b9f8bfe
to
9e584ee
Compare
8722c48
to
49c69e3
Compare
… taking being/end string pointers to use new class.
This would also be helpful for the Java binding I maintained. |
(moved message from #494, sane to resume talking in the newer issue) I have a pushed an updated That gives the extra benefit that with the single-param constructor: literals which are frequent with raw C/C++ usage can now using compile-times strlen. That's over the general benefit that pulling data from another language or string type which has constant time access to length can now avoid the strlen() alltogether - that's another benefit of this branch. Some quick measurement done with our testing framework gives it a nice edge in Release build, and Debug build (with all VS security checks) gave it a minor 2-3% slow-down. This is before I made some other tweaks which perhaps made it better. Will do more thorough measurement later. Things I would like to be able to move forward:
Point (3) will need involved Rust users. Point (4) is interesting to discuss: @bitshifter old cimgui fork replaced all cimgui api with ImStr: Otherwise cimgui could provide two api with a different prefix. One e.g. Either way this needs a solution. As a general feeling I believe that only direct C users would want to use It's too late for 1.80 but tentatively if the right things are in place we could aim for it by 1.81 or 1.82. |
It has been a long time since I looked at this. It looks like |
In LuaJIT-ImGui I would prefer ig.Text("some_text") over ig.Text(ImStr("some_text")) |
Yes of course. From pretty much any language you would do Text("hello") and the bindings would convert that to the ImStr function implicitly/automatically or explicitly (preferable as it can leverage knowing string length without a strlen call). |
FYI there are two things to do here:
|
b3b85d8
to
0755767
Compare
c817acb
to
8d39063
Compare
Reminder that this VS issue is IHMO the biggest remaining hurdle before merging this. As-is, the change seriously hinder debugger experience for C++ users. |
Hey, I wanted to check the current status of this pull request. Is the VS issue the only thing that prevents merging and how is the status on that? |
The VS issue is the main friction point remaining (please ask friends to upvote https://developercommunity.visualstudio.com/t/allow-natstepfilter-and-natjmc-to-be-included-as-p/561718 ;).
Yes, this is the branch expected to be merged into master. We would actually appreciate if you used this branch and reported issues, if any. |
I would love to use the branch, but unfortunately, I need the docking one more... I know it may be potentially a lot of work for you, as the two branches may not always merge cleanly (I know they don't at the moment), but is there any chance of a docking+string_view branch? I can offer my help for this if it's a direction you'd want to go. |
I've pushed some work now (on all three branches) to make it possible to merge docking+string_view. |
… all Visual Studio projects. (#3038)
is there a way to use this with the docking branch? If no, do you have an estimated time when this is going to be merged (I know eta's are annoying, but would love to use this from rust) |
|
Are there plans to merge this in the foreseeable future? I'm writing a wrapper using dear_bindings and just wondering whether maybe I should focus on just the ImStr path instead of the "old and busted" zero-terminated approach. |
EDIT Moved to features/string_view branch
WE EXPECT TO MERGE THIS IN 2021 BUT ARE WAITING FOR (1) NEW BINDING GENERATOR (2) INVESTIGATING SWITCHING TO STB_PRINTF IN ORDER TO SUPPORT NON-ZERO TERMINATED FORMATS
This PR implements a custom
ImStr
string span class and uses it in the API instead ofconst char* text
andconst char* text, const char* text_end
. PR is a spiritual successor of #683.Rationale: this change facilitates use of Dear ImGui from languages that do not zero-terminate their strings. So basically rust. Even though rust does have zero-terminated c strings - they are not default and therefore transparent interop between rust strings and this library would require string copying.
Things to note:
Text()
vsTestUnformatted()
.imgui_internal.h
that are not expected to be used by vast majority of users are not covered.imgui_internal.h
that takeconst char* format
are not covered for performance reasons.const char*
or callbacks are not covered.Input*()
,Sider*()
andScalar*()
functions are covered, but that limits size of format parameter to 63 bytes. Format is copied to a buffer on stack because internal functions expect it to be zero-terminated.const char* text, const char* text_end
were obsoleted, becauseImStr
version does exactly same.ImStr
is implicitly constructible fromconst char*
.ImStr
is implicitly convertible to bool, yieldsfalse
whenImStr
has no string attached. Yieldstrue
if any string is attached, even if string length is 0. This is essentially same as checking if string pointer is null.