ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.2k stars 10.31k forks source link

Example application design? #5032

Closed Levi-Armstrong closed 2 years ago

Levi-Armstrong commented 2 years ago

Hello,

I am looking for an example, guidance or material on how to architect an application using ImGui. Until now I have only used libraries like Qt, and I am not sure how to approach developing an application containing multiple widgets/windows and storage of application and widget/window data with ImGui. I came across this repo, but not sure if this is a preferred approach.

Levi-Armstrong commented 2 years ago

I am currently reviewing this repo which seems to be more comprehensive.

jokteur commented 2 years ago

I don't think there is any standard architecture of developping an application using Dear ImGui. I think the Hazel engine is a good example of an application, however the public source code is not complete, so you don't see the complete picture with this repo.

My approach was to just try to developp an application, and see how it goes. My first attempt was BM-Segmenter. It is an app for importing and segmenting medical CT images with the help of machine learning.

From the lessons I learned developping the first application, I made TempoApp, a template from which I can quickly start a new app, without all the boilerplate. With this template, I developped in less than two months this, which is an app for managing and borrowing objects to patients in an hospital to avoid losing objects. And now, I am in the processing of rewriting the first app I did using and improving the template I showed above.

I am sorry if almost nothing I showed is documented, because most of the code source is for only destined for me. And I am sure that there are terrible design errors in my applications, but Dear ImGui allowed me to quickly produce apps and this was crucial for me.

PathogenDavid commented 2 years ago

I second @jokteur. I think one of the beautiful things about Dear ImGui is it is not overly opinionated over how your application is structured. Your needs might not necessarily be the same as others' needs, you're better off starting out bare-bones and basic and refine things until you have a solution which works well for your specific application.

For example, in my Dear ImGui window management code, opening a window corresponding to an object will either spawn a new window or focus an existing one. In a different application you might prefer that you can spawn multiple windows per associated object instead. I also don't provide the ability to set specific window positions, but in some apps that's important for the UX you're trying to accomplish. In my app, my modal spawning logic only supports basic question dialogs. In a more complex app you might need something more extensible.

In many apps there's no OOP window abstraction at all. Heck, in some apps they just use Dear ImGui from wherever they feel like it and use the default debug window. It all depends on your specific needs.

MichaelKv commented 2 years ago

Third. But I would also want examples of application designs for C++ (probably, someone would write an ImGUI binding for this terrible but still popular language). I am interested in full featured approaches with exceptions, multithreading and probably co-routines. It took me a time to invent a design for exceptions handling but I would like to have a look at a professional approach.

Levi-Armstrong commented 2 years ago

Everyone, Thank you for the information and examples.

ocornut commented 2 years ago

@MichaelKv : professional game developers generally don't use exceptions.

I agree with the general answer than Dear ImGui isn't too opinionated about how to structure your application and there isn't a right answer.