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

Icons and Popups on headers. #316

Open
lcodes opened this issue Sep 3, 2015 · 17 comments
Open

Icons and Popups on headers. #316

lcodes opened this issue Sep 3, 2015 · 17 comments
Labels

Comments

@lcodes
Copy link

lcodes commented Sep 3, 2015

Hello, I'd like to add more icons to the right of a header line but don't seem to find how.

Also I'd like to show a popup menu using ImGui::BeginPopupContextItem when the header line is right-clicked but it doesn't work.

Thanks! Loving the library so far :)

@ocornut
Copy link
Owner

ocornut commented Sep 3, 2015

Jeremie, what do you mean by header line?

@lcodes
Copy link
Author

lcodes commented Sep 3, 2015

Ah sorry I didn't specify, I meant the title bar of windows from calling ImGui::Begin as well as the one from ImGui::CollapsingHeader.

ocornut added a commit that referenced this issue Sep 3, 2015
@ocornut
Copy link
Owner

ocornut commented Sep 3, 2015

You can already use BeginPopupContextItem() or any *Item* call on a Collapsing Header.

You can't directly do that for the title bar but it's easy to replicate the content of BeginPopupContentItem() and adjust it for a custom rectangle.

#include <imgui_internal.h> // for GetCurrentWindow()->TitleBarRect9)

if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1))
{
    ImRect rect = ImGui::GetCurrentWindow()->TitleBarRect();
    if (ImGui::IsMouseHoveringRect(rect.Min, rect.Max, false))
        ImGui::OpenPopup("FOO");
}

You'll need to update as I added a third parameter to IsMouseHoveredRect() to ignore the current clipping setting. Otherwise you can do

@ocornut
Copy link
Owner

ocornut commented Sep 3, 2015

For icons you can't really trivially, but you can use various approaches.

a) Include icons in your font and use them in your title, see #232
b) Draw them manually after the fact. Maybe add spacing in the title then use GetWindowDrawList()->AddImage(). For the title bar because the clipping region doesn't include the title bar you'd need to, e.g. PushClipRectFullScreen(), PopClipRect() and draw the icons in-between.
c) Copy and recreate custom functions based on existing CollapsingHeader()

If you need the icons to be interactive then maybe it is a little more work.

@lcodes
Copy link
Author

lcodes commented Sep 5, 2015

Thanks for the info!

The context menu does indeed work on collapsing headers, turns out I only tested on a window and assumed headers worked the same way;)

I do indeed want icons to act like buttons; basically I'll be using this for flags I still want to toggle when the window or section is collapsed.

I'll get back to you over the weekend for the rest, I'm actually using your library from D. I'll need to fork and update both CIMGUI and derelict-imgui before I can try this code ;)

Just as a quick idea, how about splitting both windows and sections into separate begin/end calls for both their header and content, something like this:

ImGui::BeginHeader(...);
// either draw complete header or append to arrow/label depending on args to previous call.
if (ImGui::Begin(...)) {
    // draw window contents
}
ImGui::End();

Curious to know what you think!

@ocornut
Copy link
Owner

ocornut commented Sep 5, 2015

We can't break the existing API but manipulating the header is basically as simple as changing the clipping rectangle, moving the cursor, doing what you need then restoring the cursor. So that possibly could be turned into a high-level helper but before that we'd need to try low level.

This app has been doing their own title bar https://github.com/ApoorvaJ/Papaya

@lcodes
Copy link
Author

lcodes commented Sep 5, 2015

I can't seem to get the new version of IMGUI to work. The shared library loads fine but nothing appears on the screen. If I downgrade to v1.44 everything works again.

@ocornut
Copy link
Owner

ocornut commented Sep 5, 2015

Please open a new thread. I don't know what "shared library" you are talking about, if it is a concept of cimgui or dimgui wrappers.

You can git bisect to try to find a bug, but frankly I don't think any of the changes since 1.44 would have broken something of this nature, so I'd guess maybe some of those wrappers weren't rebuild.

@lcodes
Copy link
Author

lcodes commented Sep 5, 2015

Just found it, turns out e58f991 added the DisplayFramebufferScale field and the equivalent declaration in D wasn't updated.

I'm almost to the point where I can try these samples in D, I'll let you know how it goes.

@ocornut
Copy link
Owner

ocornut commented Sep 6, 2015

Oh I didn't realize the D library had to replicate every data structure.

@lcodes
Copy link
Author

lcodes commented Sep 6, 2015

Yeah, it is ABI compatible with C but not source compatible. Its most likely that way so there's zero runtime overhead yet the language isn't burdened with legacy C syntax.

@lcodes
Copy link
Author

lcodes commented Sep 6, 2015

Alright I've got the code for window context menus to work, except no popup is showing. I traced the execution and OpenPopup is properly called when I right-click the title bar, BeginPopup returns true but no menu on screen. I tried BeginPopupContextItem with the same results.

Is there something I'm missing?

@ocornut
Copy link
Owner

ocornut commented Sep 6, 2015

Hard to say without detailed information. What's your code like?

@lcodes
Copy link
Author

lcodes commented Sep 6, 2015

Damn I feel stupid hehe; I found my problem while pasting the code here and stripping it of application logic. Turns out I was calling BeginPopup only on the frame the right-click happened. It works great now!

I'll try the icons now and see if I can make them clickable with tooltips.

@ocornut
Copy link
Owner

ocornut commented Dec 25, 2015

Hi Jeremie,

I have recently added missing high-level version of ImGui::PushClipRect / ImGui::PopClipRect in imgui_internal.h which may be helpful here.
40ddf8e

The difference with draw_list->PushClipRect() is that the later would only affect rendering while the earlier also affect how hit tests and widget culling are performed.

Have you moved forward with this idea? Let me know if this issue can be closed or if there are other desirable changes.

@ocornut
Copy link
Owner

ocornut commented Apr 24, 2016

Adding this back to my mental list today as I'm looking at tree and collapsing headers. Will see how we may be able to make it easier to add custom icons to a collapsing headers. (See #600)

@ocornut ocornut added the popups label Aug 16, 2017
@azonenberg
Copy link
Contributor

You can already use BeginPopupContextItem() or any *Item* call on a Collapsing Header.

You can't directly do that for the title bar but it's easy to replicate the content of BeginPopupContentItem() and adjust it for a custom rectangle.

#include <imgui_internal.h> // for GetCurrentWindow()->TitleBarRect9)

if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(1))
{
    ImRect rect = ImGui::GetCurrentWindow()->TitleBarRect();
    if (ImGui::IsMouseHoveringRect(rect.Min, rect.Max, false))
        ImGui::OpenPopup("FOO");
}

You'll need to update as I added a third parameter to IsMouseHoveredRect() to ignore the current clipping setting. Otherwise you can do

This example code works fine if the window is not docked, but fails if the window is docked. Is there a way to handle a right click event on a docked window's tab?

azonenberg added a commit to ngscopeclient/scopehal-apps that referenced this issue Nov 29, 2023
… if group is renamed. Fixes #640. Group renaming only works if group is UNDOCKED (see ocornut/imgui#316) for now.
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

3 participants