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.
idbrii added a commit to idbrii/cpp-imgui that referenced this issue Mar 24, 2025
Includes my merged PRs and everything in my dev branch. Haven't tested
with it yet.

Changelog:
Test case for clip rect
HACK: more recent Windows SDK and VS2017; disable graph
Set size to amount of space required
Merge pull request ocornut#349 from maksw2/master
Merge pull request ocornut#347 from mgerhardy/341
Merge pull request ocornut#348 from mgerhardy/fixed-warning
Merge pull request ocornut#346 from mgerhardy/280
Merge pull request ocornut#345 from mgerhardy/322
Merge pull request ocornut#344 from rherilier/fix-gcc-warnings
Merge pull request ocornut#336 from rherilier/add-isusingviewmanipulate
Merge pull request ocornut#335 from RedSkittleFox/alternative_window
Merge pull request ocornut#334 from ocornut/fix-beginchildframe
dear imgui update and small fixes
Merge pull request ocornut#316 from Batres3/2DSupport
Merge pull request ocornut#326 from Sayama3/use-push-pop-id
Merge pull request ocornut#328 from georgeto/master
Merge pull request ocornut#330 from maritim/master
Merge pull request ocornut#331 from GiovanyH/patch-1
Merge pull request ocornut#318 from dougbinks/imgui_math_operators
Merge pull request ocornut#312 from kimidaisuki22/master
div 0 fixed
Merge pull request ocornut#301 from ZingBallyhoo/using-any
Merge pull request ocornut#300 from Clog41200/Configurable-limits
Merge pull request ocornut#298 from xDUDSSx/fix/rotation_circles
Merge pull request ocornut#297 from xDUDSSx/fix/vertical-aspect-scaling
Merge pull request ocornut#289 from ComputationalBiomechanicsLab/fix_isusing-ignores-setid
Merge pull request ocornut#291 from ocornut/fix_math_operators_include
Merge pull request ocornut#282 from MohitSethi99/master
Merge pull request ocornut#276 from pthom/virtual_destructors
Merge pull request ocornut#271 from idbrii/clip-parent
Merge pull request ocornut#270 from idbrii/btn-behaviour
Merge pull request ocornut#265 from mgerhardy/pr/fix-minor-formatting
Merge pull request ocornut#264 from mgerhardy/pr/div0
Merge pull request ocornut#269 from peter1745/hatched-line-thickness-enhancement
Merge pull request ocornut#259 from miyanyan/master
Merge branch 'master' of https://github.com/CedricGuillemet/ImGuizmo
update dear imgui
Merge pull request ocornut#256 from Aidiakapi/patch-1
Merge pull request ocornut#252 from aaronkirkham/master
Merge pull request ocornut#249 from rokups/rk/mouse-capture
Merge pull request ocornut#246 from mgerhardy/pr/viewmanipulate
removed commented code
fix click view cube
Merge pull request ocornut#231 from mgerhardy/master
Merge pull request ocornut#230 from mgerhardy/master
Merge pull request ocornut#228 from longod/master
Merge pull request ocornut#227 from madeso/master
AddBezierCubic
Merge pull request ocornut#226 from sherief/master
revert culling test commit
Merge pull request ocornut#203 from rokups/rk/misc-fixes
Merge pull request ocornut#212 from zhaijialong/fix-behind-camera-cull
Merge pull request ocornut#209 from VictorFouquet/fix_normalize
scale is always local
Merge pull request ocornut#202 from pezy/master
imguizmo namespace
Merge pull request ocornut#194 from JonathanHiggs/vcpkg-example
1.84 WIP
Merge pull request ocornut#197 from idbrii/seq-btn-color
Merge pull request ocornut#196 from idbrii/seq-big-handles
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