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 all commits
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
22 changes: 13 additions & 9 deletions imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@
//#define IMGUI_STB_NAMESPACE ImGuiStb

//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }

#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
#ifdef EASE_CORE_DEFINED
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const EaseCore::Vec2 & f) { x = f.x; y = f.y; } \
operator EaseCore::Vec2() const { return EaseCore::Vec2(x,y); }

#define IM_VEC4_CLASS_EXTRA \
ImVec4(const EaseCore::Vec4 & f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
EaseCore::Vec4 ToVec4() const { return EaseCore::Vec4(x,y,z,w); } \
operator EaseCore::Vec4() const { return EaseCore::Vec4(x,y,z,w); }
#endif

// Indices
#define ImDrawIdx unsigned int

//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
//---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
Expand Down
56 changes: 51 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,9 @@ 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_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.70f);
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_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f);
Expand Down Expand Up @@ -3137,9 +3139,9 @@ static ImRect GetVisibleRect()
return ImRect(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y);
}

void ImGui::BeginTooltip()
void ImGui::BeginTooltip(ImGuiWindowFlags options)
{
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|options;
ImGui::Begin("##Tooltip", NULL, flags);
}

Expand Down Expand Up @@ -4513,6 +4515,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_PopupBg: return "PopupBg";
Expand Down Expand Up @@ -5055,6 +5059,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 @@ -5335,7 +5369,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 @@ -5681,6 +5718,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 @@ -5711,6 +5749,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 @@ -6556,7 +6595,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 @@ -8232,9 +8274,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
8 changes: 7 additions & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,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 @@ -337,7 +341,7 @@ namespace ImGui
// Tooltips
IMGUI_API void SetTooltip(const char* fmt, ...) IM_PRINTFARGS(1); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
IMGUI_API void SetTooltipV(const char* fmt, va_list args);
IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text
IMGUI_API void BeginTooltip(ImGuiWindowFlags options=0); // use to create full-featured tooltip windows that aren't just text
IMGUI_API void EndTooltip();

// Menus
Expand Down Expand Up @@ -549,6 +553,8 @@ enum ImGuiCol_
ImGuiCol_WindowBg, // Background of normal windows
ImGuiCol_ChildWindowBg, // Background of child windows
ImGuiCol_PopupBg, // Background of popups, menus, tooltips windows
ImGuiCol_TextHovered,
ImGuiCol_TextActive,
ImGuiCol_Border,
ImGuiCol_BorderShadow,
ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input
Expand Down