Skip to content
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

Add support for ImGui #550

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Add support for ImGui #550

wants to merge 16 commits into from

Conversation

TheGondos
Copy link
Contributor

This PR adds support for Dear ImGui, which provides an OS agnostic GUI toolkit.

  • The first commit hooks the library to the orbiter core and the D3D9Client library. I've used cmake fetch+patch mecanism to add the external dependency. I'm not an expert in cmake so don't hesitate to comment if you're not satisfied with the way the library has been added.
    The ImGui code is instanciated inside the Orbitersdk.lib file so that modules can eventually use it in the future.

  • The second commit changes the handling of input boxes/context menus to use the new library.
    Some feedback would be nice from users with high DPI monitors so that we can know if the font size is acceptable.

The library has backends for DX9/DX12, OpenGL, vulkan, WinAPI, SDL, glfw... so it should be future proof.

I've got ImGui equivalents for almost all dialogs in my linux branch so if we decide to expand on this, it should not be too difficult to replace the core Orbiter dialogs currently using the Windows API.

@TheGondos
Copy link
Contributor Author

TheGondos commented Jan 24, 2025

I've added a temporary port for the D3D9 gfx dialog to help in refining the API. I'll either remove it later or port the other dialogs.
So far I'm not satisfied with the name DialogImGui, I'll probably switch to ImGuiDialog.
I also consider moving the window creation (ImGui::Begin) inside the base class to have a cleaner handling of the active flag which is used to track if the window is opened or closed.
Doing so will break the context menu and inputboxes because they are not using a window.
Lua bindings should be coming next

@jarmonik
Copy link
Contributor

Thanks, I tested this and it worked fine, no problems with building and the code looks very simple and efficient. So, I'll have to start looking into the documentation and learning how to use the widgets. There seems to be pretty good collection of them. Is there a "Load file", "Save file" dialogs ? Is there still much to do before merge ?

@TheGondos
Copy link
Contributor Author

TheGondos commented Jan 24, 2025

Thanks, I tested this and it worked fine, no problems with building and the code looks very simple and efficient. So, I'll have to start looking into the documentation and learning how to use the widgets. There seems to be pretty good collection of them. Is there a "Load file", "Save file" dialogs ? Is there still much to do before merge ?

There is no "native" file dialog but there are a few projects that provide one, I'll try a couple and see if one is easier to use than the others.
You can place an "ImGui::ShowDemoWindow()" in the Draw() method to see a complete list of available controls. Most are easy to use, it becomes more complicated when you want an advanced layout but it usually can be done. For debug menus it's a no brainer to use.

Before merging I'd like some feedback from someone with a HiDPI display to know if the dialogs aren't too small there.
For now only the context menu / input box is using this. Did you try it (by using the TGT button in OrbitMFD for example)?

@jarmonik
Copy link
Contributor

Yes, I tried the "TGT" button and it works perfectly. Nice work there. On 1920x1080 the scaling looks good al-tough in some cases I might prefer little smaller, like in a property tree. Is the scaling adjustable ?

@TheGondos
Copy link
Contributor Author

TheGondos commented Jan 25, 2025

The font used to be 14 in size, I upped it to 18 but that's something that'll need tweaking I guess.
You can modify this line in DlgMgr.cpp if you want to play with different values :
io.Fonts->AddFontFromFileTTF("Roboto-Medium.ttf", 18.0f, &config, GetGlyphRangesOrbiter());
I see there is a dlgFont_Scale configuration option, I'll see if I can make use of it.

Edit: I did some work on Lua bindings but the "usual" tool is unmaintained. I could get it to a work with the current ImGui version but there is some work involved. I'll do that in another PR not to pollute this one.

@TheGondos
Copy link
Contributor Author

TheGondos commented Jan 26, 2025

This is ready for review but not for merge.
If you're OK with this, just tell me and I'll remove the D3D9 Graphics Controls prototype and squash/rebase the whole thing so it won't pollute the main branch.
Future work that'll require other PRs :

  • port core dialogs to this
  • add notification API (mostly interesting for Lua error reporting)
  • Lua bindings

@TheGondos TheGondos marked this pull request as ready for review January 26, 2025 17:21
@TheGondos
Copy link
Contributor Author

Well, since I was at it I added notifications and used them for Lua errors :
notif

@TheGondos TheGondos changed the title WIP: Add support for ImGui Add support for ImGui Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants