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

Supporting TextHovered and TextActive colors #511

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ ImGuiStyle::ImGuiStyle()

Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
Colors[ImGuiCol_TextHovered] = ImVec4(0.90f, 0.90f, 0.40f, 1.00f);
Colors[ImGuiCol_TextActive] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f);
Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f);
Expand Down Expand Up @@ -4468,6 +4470,8 @@ const char* ImGui::GetStyleColName(ImGuiCol idx)
{
case ImGuiCol_Text: return "Text";
case ImGuiCol_TextDisabled: return "TextDisabled";
case ImGuiCol_TextHovered: return "TextHovered";
case ImGuiCol_TextActive: return "TextActive";
case ImGuiCol_WindowBg: return "WindowBg";
case ImGuiCol_ChildWindowBg: return "ChildWindowBg";
case ImGuiCol_Border: return "Border";
Expand Down Expand Up @@ -5007,6 +5011,36 @@ void ImGui::TextDisabled(const char* fmt, ...)
va_end(args);
}

void ImGui::TextHoveredV(const char* fmt, va_list args)
{
ImGui::PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextHovered]);
TextV(fmt, args);
ImGui::PopStyleColor();
}

void ImGui::TextHovered(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
TextDisabledV(fmt, args);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong call here. What are those functions really useful for anyway? (did you feel you needed them as user?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not need them at all.
It was a replication of the other ones.
I totally agree they are not useful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want me to remove them and make another pull-request ?
(I'm not very familiar with github...)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pitfall with GIT that everyone falls into at least once, if that your pull-request is linked to your branch. So anything you push into this branch will be added to the PR.
This also mean you need to be mindful of your local branching. In theory you need to commit to the PR branch and then merge the PR branch in your working branch. Git is a little work..

va_end(args);
}

void ImGui::TextActiveV(const char* fmt, va_list args)
{
ImGui::PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextActive]);
TextV(fmt, args);
ImGui::PopStyleColor();
}

void ImGui::TextActive(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
TextDisabledV(fmt, args);
va_end(args);
}

void ImGui::TextWrappedV(const char* fmt, va_list args)
{
ImGui::PushTextWrapPos(0.0f);
Expand Down Expand Up @@ -5281,7 +5315,10 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
// Render
const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);

ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[(hovered && held) ? ImGuiCol_TextActive : hovered ? ImGuiCol_TextHovered : ImGuiCol_Text]);
RenderTextClipped(bb.Min, bb.Max, label, NULL, &label_size, ImGuiAlign_Center | ImGuiAlign_VCenter);
ImGui::PopStyleColor();

// Automatically close popups
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
Expand Down Expand Up @@ -5627,6 +5664,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
// Render
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
const ImVec2 text_pos = bb.Min + padding + ImVec2(collapser_width, text_base_offset_y);
ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[(held && hovered) ? ImGuiCol_TextActive : hovered ? ImGuiCol_TextHovered : ImGuiCol_Text]);
if (display_frame)
{
// Framed type
Expand Down Expand Up @@ -5657,6 +5695,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
LogRenderedText(text_pos, ">");
RenderText(text_pos, label, NULL, label_hide_text_after_double_hash);
}
ImGui::PopStyleColor();

return opened;
}
Expand Down Expand Up @@ -6496,7 +6535,10 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
char value_buf[64];
const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);

ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[g.ActiveId == id ? ImGuiCol_TextActive : g.HoveredId == id ? ImGuiCol_TextHovered : ImGuiCol_Text]);
RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImGuiAlign_Center|ImGuiAlign_VCenter);
ImGui::PopStyleColor();

if (label_size.x > 0.0f)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
Expand Down Expand Up @@ -8138,9 +8180,13 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
bb_with_spacing.Max.x -= (ImGui::GetContentRegionMax().x - max_x);
}

if (flags & ImGuiSelectableFlags_Disabled) ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
if (flags & ImGuiSelectableFlags_Disabled)
ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
else
ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[(held && hovered) ? ImGuiCol_TextActive : hovered ? ImGuiCol_TextHovered : ImGuiCol_Text]);

RenderTextClipped(bb.Min, bb_with_spacing.Max, label, NULL, &label_size);
if (flags & ImGuiSelectableFlags_Disabled) ImGui::PopStyleColor();
ImGui::PopStyleColor();

// Automatically close popups
if (pressed && !(flags & ImGuiSelectableFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
Expand Down
6 changes: 6 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ namespace ImGui
IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
IMGUI_API void TextDisabled(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextDisabledV(const char* fmt, va_list args);
IMGUI_API void TextHovered(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextHovered]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextHoveredV(const char* fmt, va_list args);
IMGUI_API void TextActive(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextActive]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextActiveV(const char* fmt, va_list args);
IMGUI_API void TextWrapped(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
IMGUI_API void TextWrappedV(const char* fmt, va_list args);
IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text
Expand Down Expand Up @@ -537,6 +541,8 @@ enum ImGuiCol_
{
ImGuiCol_Text,
ImGuiCol_TextDisabled,
ImGuiCol_TextHovered,
ImGuiCol_TextActive,
ImGuiCol_WindowBg,
ImGuiCol_ChildWindowBg,
ImGuiCol_Border,
Expand Down