imgui
imgui copied to clipboard
Pinned Tooltip Windows
I would like windows with the following properties:
- Render on top of a window, but don't take focus and don't activate.
- When I mouse click on them and drag, they move.
- All other events (mouse hovering, right clicking, etc go to window underneath).
I'm planning on using them for "pinned tooltip" behavior like in the below picture. Hover over some event, hit a hotkey, that tooltip is now a "pinned tooltip" and you can view / compare to other events in the main tooltip. I also think these will be useful for displaying floating information about other things.
I've got this working using the code below (which pretty much abuses tooltips). I tried using popups and a few other techniques and couldn't get anything working.
The only issue I've got is the z-ordering, but I think I can get everything else working like I want without imgui changes.
My question would be: this ok? Is there a better way to accomplish this behavior?
Thanks!
void imgui_set_tooltip( const char *name, const ImVec2 pos, const char *str, rect_t *rc )
{
ImGuiIO& io = ImGui::GetIO();
const ImVec2 mousepos_orig = io.MousePos;
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_AlwaysAutoResize;
io.MousePos = pos;
ImGui::Begin( name, NULL, flags );
ImGui::Text( "%s", str );
if ( rc )
{
ImVec2 wpos = ImGui::GetWindowPos();
ImVec2 size = ImGui::GetWindowSize();
// Return window dimensions so higher level can handle click / moving window
*rc = { wpos.x, wpos.y, size.x, size.y };
}
ImGui::End();
io.MousePos = mousepos_orig;
}