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

text hovered #5280

Closed
0Z0SK0 opened this issue May 3, 2022 · 2 comments
Closed

text hovered #5280

0Z0SK0 opened this issue May 3, 2022 · 2 comments

Comments

@0Z0SK0
Copy link

0Z0SK0 commented May 3, 2022

Version/Branch of Dear ImGui:

Version: 1.86
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler: VS C++ 17
Operating System: Win 8.1 x64

My Issue/Question:

Is it possible to hope for the developing of text hover style?

@ocornut
Copy link
Owner

ocornut commented May 3, 2022

You can create your own widget easily for that.

@ocornut
Copy link
Owner

ocornut commented May 4, 2022

Here's a potential solution that handles formatting:

header

namespace ImGui
{
    void TextWithHoverColor(ImVec4 col, const char* fmt, ...);
};

implementation

#include "imgui_internal.h"

void ImGui::TextWithHoverColor(ImVec4 col, const char* fmt, ...)
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return;

    // Format text
    va_list args;
    va_start(args, fmt);
    const char* text_begin = g.TempBuffer;
    const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
    va_end(args);

    // Layout
    const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
    const ImVec2 text_size = CalcTextSize(text_begin, text_end);
    ImRect bb(text_pos.x, text_pos.y, text_pos.x + text_size.x, text_pos.y + text_size.y);
    ItemSize(text_size, 0.0f);
    if (!ItemAdd(bb, 0))
        return;

    // Render
    bool hovered = IsItemHovered();
    if (hovered)
        PushStyleColor(ImGuiCol_Text, col);
    RenderText(bb.Min, text_begin, text_end, false);
    if (hovered)
        PopStyleColor();
}

Also linking to #511 #2941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants