-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
How to check ImGui if has no persistant data present? #4988
Comments
I guess you could test for the presence of an ini file. But to be honest your question sounds like a XY Problem and you should always clarify what you are actually trying to do.
I'm asking this because I have a block of code that should only run if the program has no persistant data.
What would that block of code want to do ?
|
I understand, I'll try to explain as best as I can. The block in question sets up the docking layout with the help of dock builder API. It sets upa "default" layout which users can then change for their liking. I only want to set up this default layout if there is no saved .ini file because otherwise I'd be overwriting the users' preferences. That's why I want to check if ImGui has persistant data present. My question has many parallels with #4829 so you may want to close this right away, but I also think (if there already isn't) having a function to query whether or not ImGui has persisted any amount of data would be a fine addition. |
As suspected this is a XY Problem. You should not “check if imgui has no persistant data”.
Since you are building for a given dock node id, you can simply check if a node with this ID exist.
|
I'm already checking to see if my docknode exists but it's never "not existing", ImGui::DockBuilderGetNode() always retuns a non-null pointer. Here is my code:
What am I doing wrong here? If I convert the expression to instead check for the existence of imgui.ini, the if executes only once when the program is launched for the first time. |
You are calling DockSpace() which CREATES the node right before checking if the node exists..
|
I found the cause of my problem, I changed these lines:
to these:
Now that I've fixed my initial problem, should we close this issue without adressing the question on the title and change the title or keep it open consider the possible use cases of such a function? |
I'll close this and let searches do the rest :)
You can also simply read |
Seems that for DockSpaceOverViewport, this is currently problematic. |
Is there a built-in way to check if imgui has persistant data present?
I'm asking this because I have a block of code that should only run if the program has no persistant data. (opening for the first time etc.)
I thought about writing my user data in the form of a bool and then try reading it before the aforementioned block of code, but I couldn't wrap my head around how the ImGuiSettingsHandler worked (when it fired those callbacks etc.)
Thank you in advance.
The text was updated successfully, but these errors were encountered: