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

Have a way to handle a event from window title bar? #7369

Closed
RicardoDazzling opened this issue Mar 5, 2024 · 2 comments
Closed

Have a way to handle a event from window title bar? #7369

RicardoDazzling opened this issue Mar 5, 2024 · 2 comments

Comments

@RicardoDazzling
Copy link

Version/Branch of Dear ImGui:

Version 1.90.4, Branch: master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 10

Full config/build information:

Dear ImGui 1.90.5 WIP (19043)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00000006
 HasMouseCursors
 HasSetMousePos
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

I'm new in C++ and ImGui, so I'm not finded a exemple to it:

I need to handle a double click event in the window titlebar. My idea was create a way to the user change the title with double click, so the window title would to be a input. But I know that it can be hard to implement, so if I show a modal asking the user a new window name, solve my problem. But I don't know how to add this event for the window title...

Thank you everyone!

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Mar 5, 2024

After Begin() you can query title bar (or docking tab) item data, so this would work:

ImGui::Begin("Hello, world!", nullptr, ImGuiWindowFlags_NoCollapse); 
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0))
    printf("hi\n");

You need to disable collapsing otherwise this would conflict with the double-clicking.

I pushed 65dc67f which allows overriding this via the key-ownership mechanism, so if you pull you could use:

ImGui::Begin("Hello, world!");
if (ImGui::IsItemHovered())
{
    ImGuiID my_id = ImGui::GetID("left-click-interceptor");
    ImGui::SetKeyOwner(ImGuiKey_MouseLeft, my_id);
    if (ImGui::IsMouseDoubleClicked(0, my_id))
        printf("hi\n");
}

However, while that answers your question I think both solutions are incorrect as they would likely interact wrongly with docked window.

I think you would better use a context-menu for that:

ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.
if (ImGui::BeginPopupContextItem(nullptr, ImGuiPopupFlags_MouseButtonRight))
{
    if (ImGui::MenuItem("Rename..."))
        printf("hi\n");
    ImGui::EndPopup();
}

This will work with docked window.

Note that if you rename windows you need to use the ### operator to preserve their unique identifier, so their imgui-side names should be "User Visible Name###Internal Name". Otherwise after you rename dear imgui will think it is a different window. See "Demo->Examples->Manipulating Window Titles" for an example.

@RicardoDazzling
Copy link
Author

Thank you! It solved my doubt

@ocornut ocornut closed this as completed Mar 8, 2024
hackermdch pushed a commit to hackermdch/imgui that referenced this issue Jun 9, 2024
ocornut added a commit that referenced this issue Sep 17, 2024
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

No branches or pull requests

3 participants
@ocornut @RicardoDazzling and others