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

wxWidgets ImGui Wrapper #1029

Closed
aiekick opened this issue Feb 19, 2017 · 9 comments
Closed

wxWidgets ImGui Wrapper #1029

aiekick opened this issue Feb 19, 2017 · 9 comments
Labels

Comments

@aiekick
Copy link
Contributor

aiekick commented Feb 19, 2017

Hello,

this is not an issue i think.

i tried to create a wrapper of imgui in wxWidgets.

it work more or less, but i have problem with clipboard. he is not catched. i have the good modifiers but with custom func or not i not arrive to resolve the problem.

can you check my code and say if you see somethings, can explain the problem please ?

thanks, i work on from many day...

wxImGuiCanvas.h.txt
wxImGuiCanvas.cpp.txt

@aiekick
Copy link
Contributor Author

aiekick commented Feb 20, 2017

I dont know how work the keyboard system with imgui.

In wxiwdget, i have events keydown and char. the event EVT_CHAR get the final key with modifiers, so if i touch the key 'c' with no shift, i get 'c' and not 'C'. maybe imgui want the original char 'C' for detect the good key for launch the clipboard func ?

because i see the line in the init :
io.KeyMap[ImGuiKey_C] = WXK_CONTROL_C;

i have checked the clipboard with the test window. it work so my problem come from the ctrl+c who is not catch by imgui in think.

i have tried the same process event like the directx sample but i have the same result, the clipboard is not catched.

for imgui detect the "ctrl+c", we need to put the char c in the func "io.AddInputCharacter" and imgui use modifier state ? or its another way ?

@ratchetfreak
Copy link

ImGui looks for the keydown state of C in io.KeysDown[io.KeyMap[ImGuiKey_C]]. This combined with the io.KeyCtrl boolean this will signal that ctrl+C is pressed.

@aiekick
Copy link
Contributor Author

aiekick commented Feb 20, 2017

ok i have resolved my issue.wx widgets have some problems about key cathing comparing to tohers systems

@Don-Dominic
Copy link

wrapper of imgui in wxWidgets.

i been trying to do something similar to this for some time, could you by any chance share this work for reference? Thank you.

@aiekick
Copy link
Contributor Author

aiekick commented Aug 1, 2023

you have the files attached to the post...

@Don-Dominic
Copy link

ahh silly me. thanks.

@Seneral
Copy link

Seneral commented Oct 29, 2023

I've made a platform backend for wxWidgets, which is quite usable with the existing OpenGL3 rendering backend.
Makes it a bit more maintainable.
I don't claim it to be perfect in regards to focus handling if you mix wxWidgets UI with Dear ImGui, I had to pass on all input events to wxWidgets to get a good experience, but it does work now.
No multiple viewport implementation, though it should be possible if you look into the API.
Input all seems to work properly, though no guarantees.
Cursor changes are implemented.

I also implemented my UI with on-demand rendering, so the Init takes a refresh callback, at which point you should re-render 2-3 times. I did this like this:

if (!ImGui_ImplWX_Init([]()
	{ // Two frames of updates necessary, even for mouse move
		DearImGuiPanel *panel = wxGetApp().imGuiPanel;
		panel->updateUI = std::max(panel->updateUI, 2);
		panel->Refresh();
	}))
	return false;

and

void DearImGuiPanel::OnIdle(wxIdleEvent &event)
{
	if (updateUI > 0)
		Refresh();
}

with this in setup:

Bind(wxEVT_IDLE, &DearImGuiPanel::OnIdle, this);

Bind(wxEVT_KEY_DOWN, ImGui_ImplWX_OnKeyDown);
Bind(wxEVT_KEY_UP, ImGui_ImplWX_OnKeyUp);
Bind(wxEVT_CHAR_HOOK, ImGui_ImplWX_OnChar);

Bind(wxEVT_MOTION, ImGui_ImplWX_OnMouseMoveEvent);
Bind(wxEVT_MOUSEWHEEL, ImGui_ImplWX_OnMouseWheelEvent);
Bind(wxEVT_LEFT_DOWN, ImGui_ImplWX_OnMouseLeftEvent);
Bind(wxEVT_LEFT_UP, ImGui_ImplWX_OnMouseLeftEvent);
Bind(wxEVT_RIGHT_DOWN, ImGui_ImplWX_OnMouseRightEvent);
Bind(wxEVT_RIGHT_UP, ImGui_ImplWX_OnMouseRightEvent);
Bind(wxEVT_MIDDLE_DOWN, ImGui_ImplWX_OnMouseMiddleEvent);
Bind(wxEVT_MIDDLE_UP, ImGui_ImplWX_OnMouseMiddleEvent);

and of course the Render method decreasing the counter. Also allows for fast OpenGL updates with a slower event-based UI update rate. Requires proper handling of external events (e.g. resizing) and updates from your code, ofc.

Most everything is like the Dear ImGui examples suggest, e.g. for rendering:

ImGui_ImplWX_NewFrame(this);
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();

Here's the implementation:
imgui_impl_wx.zip
or as txts:
imgui_impl_wx.cpp.txt
imgui_impl_wx.h.txt

Example (at this point, I only had the console left as the only native control, but it integrated well with Menus and other UI controls overlapping with the GLCanvas)
image

@aiekick
Copy link
Contributor Author

aiekick commented Oct 29, 2023

what is the interest to use wxWidgets but dont use wxWidgets Gui ?
cause, it seems, you have used the docking system of imgui, but not the one of wxWidgets .

@Seneral
Copy link

Seneral commented Oct 29, 2023

For me it was a transition period where I wasn't sure to what extent I was going to use ImGui (e.g. just for overlay over the 2D and 3D GLCanvases, or to replace all). Especially since I still had plans to use some cross-platform desktop integration features of wxWidgets so I had to keep it around anyway until I found replacements.
Which I partly did today, in the form of e.g.
https://github.com/dmikushin/tray
https://github.com/mackron/miniaudio
Though I'm still missing cross-platform theming support (getting system colors, even just dark/light mode, would be nice - glfw isn't quite there yet sadly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants