Skip to content

wxWidgets ImGui Wrapper #1029

Description

@aiekick

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

Activity

  1. aiekick commented on Feb 20, 2017

    @aiekick
    ContributorAuthor

    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 ?

  2. ratchetfreak commented on Feb 20, 2017

    @ratchetfreak

    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.

  3. aiekick commented on Feb 20, 2017

    @aiekick
    ContributorAuthor

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

  4. Don-Dominic commented on Aug 1, 2023

    @Don-Dominic

    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.

  5. aiekick commented on Aug 1, 2023

    @aiekick
    ContributorAuthor

    you have the files attached to the post...

  6. Don-Dominic commented on Aug 1, 2023

    @Don-Dominic

    ahh silly me. thanks.

  7. Seneral commented on Oct 29, 2023

    @Seneral

    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

  8. aiekick commented on Oct 29, 2023

    @aiekick
    ContributorAuthor

    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 .

  9. Seneral commented on Oct 29, 2023

    @Seneral

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions