implot icon indicating copy to clipboard operation
implot copied to clipboard

Persist legend location and flags

Open Jochen0x90h opened this issue 2 years ago • 5 comments

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.

Jochen0x90h avatar Dec 12 '22 11:12 Jochen0x90h

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.

ta275 avatar Dec 16 '22 07:12 ta275

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

BenBE avatar Dec 16 '22 08:12 BenBE

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.

ta275 avatar Dec 26 '22 10:12 ta275

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.

BenBE avatar Dec 26 '22 19:12 BenBE

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.

Jochen0x90h avatar Jan 04 '23 19:01 Jochen0x90h