-
-
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
Feature Request: Allow storing user data inside windows and to imgui.ini file #2564
Comments
(reposted with missing code blurb) Hello,
Yes you can do that. I am not sure to understand why you don't just add a new .ini handler in the You can maintain your own key>value store where value is MyStruct and make that persist in the .ini file this way. The boilerplate needed is quite small, there's no reason to store your value in the same .ini block as the one imgui uses for its stuff. Just copy what
You can store and write the same title, so your .ini file would look like:
(Linking to #437) |
Okay, I see now. I'm hesitant to do this though which is why I would suggest giving "dedicated support" for this type of stuff. Mostly because if the system ever changes, even just slightly, then I may have to rewrite the implementation. But if this is what you recommend, then I'll do it. |
From my point of view I need to avoid taking too much unnecessary responsability and that means not providing too many guarantees. This is what |
I wonder what is the proper way now of extending ImGuiWindow with user data? I am doing now by manually patching sources by adding at the end of ImGuiWindow definition in imgui_internal.h
I need the userData to extend some window features which are not yet available in ImGui. Thanks in advance. |
There is currently no direct way to extend What I did is I defined two structures:
Then I ended up with: static ImGuiLayoutWindowState* GetCurrentWindowLayoutState(); Basically what the function does is:
Ideally there should be a way to re-parse ini file to extenstion activated after new This is the current state afaik. |
Note that this is achieved by registering a custom .ini handler, which is based on a description by the owner of Dear ImGui (see [1]). References: - [1] ocornut/imgui#2564
Hello, |
For example which windows (debuggables, sound settings, ...) were open, which are the last used paths in file-open-dialogs, or how the OSD icons or reversebar were configured, are now remembered after closing and restarting openMSX. This uses functionality from imgui_internal.h, this API is not guaranteed to remain the same between different Dear ImGui versions. Though it is a solution recommended by the Dear ImGui developers themselves. For example see: ocornut/imgui#2564 I'm not happy about the current implementation. The main reason is that currently we duplicate the to-be-serialized information in two locations. And we have to keep those in sync. This is especially true for the more dynamic info (like the 'debuggable' windows that are open, this list depends on the specific MSX machine). One of the strong points in the "Immediate Mode GUI paradigm" is that there is no duplicated information. And thus there cannot be bugs in keeping the information in sync. The current implementation violates that principle. The reason why currently the information is duplicated is because of object lifetime issues. Just before 'Dear ImGui' is shutdown, it still writes the imgui.ini file, we want our extra information in that file. But in the current code, when we shutdown 'Dear ImGui' we've already deleted the 'ImGuiLayer' object which contains the information we want to save. My first solution was to move the information to a new object 'ImGuiManager' which does have a longer lifetime than 'Dear ImGui'. But as stated in the previous paragraph: currently this design leads to some duplicated information that needs to be kept in sync. I plan to refactor this in the following patches. But I already wanted to push the current new functionality. I already wanted to refactor 'ImGuiLayer' so that's it's split over several smaller files. E.g. separate file for the debugger stuff, the setting stuff, the media stuff, ... I'll give that higher priority, and try to do it in a way that also resolves the lifetime issues.
I could not find this already, so I'm sorry if this is duplicating another issue.
What this means:
Provide a way to store custom data structures inside the window objects themselves, which are already publicly available through the imgui context in
Windows
. In short, this will let programmers access data about windows without abstracting their own wrapping class.Why this is better than using a wrapping class:
For my current use case, I would like to initialize a window with additional data that can change at start-up and during run-time. It is possible to create a wrapper that saves a pointer or ID for the window along with the additional data, but this now means I would have to also track the windows and effectively rewrite the current implementation for saving window information to the
imgui.ini
file. Instead, it would be easier to allow developers to save (or serialize) custom data structures for the windows which is already saved by dear imgui.Why this is better than hard-coding everything into dear imgui:
It would obviously be a lot of work to do things like storing the state of every widget inside a window, simply due to the fact that saving the layout of each window alone would bloat the .ini file and create a lot of unnecessary double-checking during window drawing. Letting the developer choose what data to save for a window and where it should go is easier for everyone.
What this could look like:
First, here is how it looks in use, I explain it afterwards and show what code changes might be needed to allow this.
MyClass.h
main.cpp
Sorry if this code has bugs, I just wrote it manually inside the issue box and didn't actually test it. This is just to give you an idea of how it can be used.
How it could work:
I'm not as familiar with the code base, but from initial scanning it seems like there wouldn't be very many changes needed to support this.
The functions
Save
andLoad
would need to be added as virtual functions to theImGuiWindowClass
class/ struct. As well, a pointer likeImGuiWindowClass* WindowClass
would have to be added to theImGuiWindowSettings
struct.Inside the current
SettingsHandlerWindow_WriteAll
function that is responsible for building theimgui.ini
file, all that would need to be added is a call tosettings->WindowClass->Save(buf)
. This might need a new buffer for the call specifically, and could only be added if the buffer actually contains data. This would probably best be added last using a header similar to[Window]
maybe something like[UserData]
, of which is considered finished loading custom data when the next[Window]
line appears.Then inside the
SettingsHandlerWindow_ReadLine
function you'd add aentry_data->Load(line)
function call, which is only called when something like[UserData]
is found and a switch is flipped.From what I can see, this is all that really needs to be done. Like I wrote earlier, this is all already possible to do, but it requires us developers to reinvent the wheel so-to-speak and we'd end up having the
imgui.ini
file as well as our own.ini
-like file. This way, we can simply add our data to a derived class which dear imgui will automatically save and load for us.I would love to see this implemented! If you give me the green light I'd happily create a pull request to add this 🙂
The text was updated successfully, but these errors were encountered: