epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

Persist legend location and flags #430

Open Jochen0x90h opened 1 year ago

Jochen0x90h commented 1 year ago

Hi!

Thanks for this great library. I have a question: How do I persist the location and inside/outside flag of the legend so that if the app is closed and opened again the legend is still at the same position. Is there a method to query the state of the legend? Or something like SetupLegend(ImPlotLocation location, ImPlotLegendFlags flags) with references which modifies the current location and flags when the user configures the legend. Then location and flags could be saved on exit and loaded on start of the app.

ta275 commented 1 year ago

I'm not an expert but I'd imagine you could persist the state by dumping a json/txt/yml or some other file in the filesystem right before the app is closed. And then you can read from this file when the app is launched again and update the state of the legend as per the contents of the file.

This file could be stored in the installation/build directory.

BenBE commented 1 year ago

Isn't there an mechanism in ImGUI to use the imgui.ini that it writes anyway?

ta275 commented 1 year ago

Not quite familiar with imgui.ini myself. However, dumping a simple file for your own custom use-case could be beneficial in terms of avoiding any dependency on imgui.ini's behavior.

BenBE commented 1 year ago

Not quite familiar with imgui.ini myself. However, dumping a simple file for your own custom use-case could be beneficial in terms of avoiding any dependency on imgui.ini's behavior.

Wouldn't this just result in thousands of files for the user to manage if each and every plugin went that way? Also this sounds quite a bit like NIH when there's already a facility to save state for ImGUI.

Jochen0x90h commented 1 year ago

So far I haven't found out how to get the current values of the location and the inside/outise flag, so I'm not able to store it to some custom file. I think it is also not stored automatically. That's why we would need a SetupLegend() with user provided state or some other mechanism to extract the current state.