Skip to content

Commit

Permalink
Merge branch 'WidgetTextColors' into microstrain
Browse files Browse the repository at this point in the history
  • Loading branch information
dacuster committed Jan 23, 2024
2 parents 7bbe1ce + befdb72 commit e21d366
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
6 changes: 5 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3313,9 +3313,11 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
case ImGuiCol_Button: return "Button";
case ImGuiCol_ButtonHovered: return "ButtonHovered";
case ImGuiCol_ButtonActive: return "ButtonActive";
case ImGuiCol_ButtonText: return "ButtonText"; // MicroStrain Custom
case ImGuiCol_Header: return "Header";
case ImGuiCol_HeaderHovered: return "HeaderHovered";
case ImGuiCol_HeaderActive: return "HeaderActive";
case ImGuiCol_HeaderText: return "HeaderText"; // MicroStrain Custom
case ImGuiCol_Separator: return "Separator";
case ImGuiCol_SeparatorHovered: return "SeparatorHovered";
case ImGuiCol_SeparatorActive: return "SeparatorActive";
Expand All @@ -3327,13 +3329,15 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
case ImGuiCol_TabActive: return "TabActive";
case ImGuiCol_TabUnfocused: return "TabUnfocused";
case ImGuiCol_TabUnfocusedActive: return "TabUnfocusedActive";
case ImGuiCol_TabText: return "TabText"; // MicroStrain Custom
case ImGuiCol_DockingPreview: return "DockingPreview";
case ImGuiCol_DockingEmptyBg: return "DockingEmptyBg";
case ImGuiCol_PlotLines: return "PlotLines";
case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
case ImGuiCol_PlotHistogram: return "PlotHistogram";
case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
case ImGuiCol_TableHeaderBg: return "TableHeaderBg";
case ImGuiCol_TableHeaderText: return "TableHeaderText"; // MicroStrain Custom
case ImGuiCol_TableBorderStrong: return "TableBorderStrong";
case ImGuiCol_TableBorderLight: return "TableBorderLight";
case ImGuiCol_TableRowBg: return "TableRowBg";
Expand Down Expand Up @@ -15031,7 +15035,7 @@ void ImGui::UpdatePlatformWindows()
if (is_new_platform_window)
{
IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Create Platform Window %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a");

//Microstrain Custom Edit
if(viewport->Window->Flags & ImGuiWindowFlags_Native_Child_Window)
viewport->Flags |= ImGuiViewportFlags_NativeChild;
Expand Down
4 changes: 4 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1721,9 +1721,11 @@ enum ImGuiCol_
ImGuiCol_Button,
ImGuiCol_ButtonHovered,
ImGuiCol_ButtonActive,
ImGuiCol_ButtonText, // MicroStrain
ImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem
ImGuiCol_HeaderHovered,
ImGuiCol_HeaderActive,
ImGuiCol_HeaderText, // MicroStrain
ImGuiCol_Separator,
ImGuiCol_SeparatorHovered,
ImGuiCol_SeparatorActive,
Expand All @@ -1735,13 +1737,15 @@ enum ImGuiCol_
ImGuiCol_TabActive,
ImGuiCol_TabUnfocused,
ImGuiCol_TabUnfocusedActive,
ImGuiCol_TabText, // MicroStrain
ImGuiCol_DockingPreview, // Preview overlay color when about to docking something
ImGuiCol_DockingEmptyBg, // Background color for empty node (e.g. CentralNode with no window docked into it)
ImGuiCol_PlotLines,
ImGuiCol_PlotLinesHovered,
ImGuiCol_PlotHistogram,
ImGuiCol_PlotHistogramHovered,
ImGuiCol_TableHeaderBg, // Table header background
ImGuiCol_TableHeaderText, // MicroStrain
ImGuiCol_TableBorderStrong, // Table outer and header borders (prefer using Alpha=1.0 here)
ImGuiCol_TableBorderLight, // Table inner borders (prefer using Alpha=1.0 here)
ImGuiCol_TableRowBg, // Table row background (even rows)
Expand Down
12 changes: 12 additions & 0 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst)
ImVec4* colors = style->Colors;

colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_ButtonText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); // MicroStrain
colors[ImGuiCol_HeaderText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TabText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TableHeaderText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
Expand Down Expand Up @@ -239,6 +243,10 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst)
ImVec4* colors = style->Colors;

colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
colors[ImGuiCol_ButtonText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); // MicroStrain
colors[ImGuiCol_HeaderText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); // MicroStrain
colors[ImGuiCol_TabText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); // MicroStrain
colors[ImGuiCol_TableHeaderText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); // MicroStrain
colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
Expand Down Expand Up @@ -302,6 +310,10 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)
ImVec4* colors = style->Colors;

colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_ButtonText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); // MicroStrain
colors[ImGuiCol_HeaderText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TabText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TableHeaderText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); // MicroStrain
colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
Expand Down
4 changes: 2 additions & 2 deletions imgui_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,12 +3114,12 @@ void ImGui::TableHeader(const char* label)
float y = label_pos.y;
if (column->SortOrder > 0)
{
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text, 0.70f));
PushStyleColor(ImGuiCol_TableHeaderText, GetColorU32(ImGuiCol_TableHeaderText, 0.70f)); // MicroStrain
RenderText(ImVec2(x + g.Style.ItemInnerSpacing.x, y), sort_order_suf);
PopStyleColor();
x += w_sort_text;
}
RenderArrow(window->DrawList, ImVec2(x, y), GetColorU32(ImGuiCol_Text), column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Up : ImGuiDir_Down, ARROW_SCALE);
RenderArrow(window->DrawList, ImVec2(x, y), GetColorU32(ImGuiCol_TableHeaderText), column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Up : ImGuiDir_Down, ARROW_SCALE); // MicroStrain
}

// Handle clicking on column header to adjust Sort Order
Expand Down
34 changes: 27 additions & 7 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags

if (g.LogEnabled)
LogSetNextTextDecoration("[", "]");

PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonText));
RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
PopStyleColor();

// Automatically close popups
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
Expand Down Expand Up @@ -781,7 +784,7 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu

// Render
const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
const ImU32 text_col = GetColorU32(ImGuiCol_Text);
const ImU32 text_col = GetColorU32(ImGuiCol_ButtonText); // MicroStrain
RenderNavHighlight(bb, id);
RenderFrame(bb.Min, bb.Max, bg_col, true, g.Style.FrameRounding);
RenderArrow(window->DrawList, bb.Min + ImVec2(ImMax(0.0f, (size.x - g.FontSize) * 0.5f), ImMax(0.0f, (size.y - g.FontSize) * 0.5f)), text_col, dir);
Expand Down Expand Up @@ -6538,7 +6541,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_ToggledSelection;

// Render
const ImU32 text_col = GetColorU32(ImGuiCol_Text);
const ImU32 text_col = GetColorU32(ImGuiCol_HeaderText); // MicroStrain
ImGuiNavHighlightFlags nav_highlight_flags = ImGuiNavHighlightFlags_TypeThin;
if (display_frame)
{
Expand Down Expand Up @@ -6578,12 +6581,16 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
if (span_all_columns)
TablePopBackgroundChannel();

PushStyleColor(ImGuiCol_Text, text_col); // MicroStrain

// Label
if (display_frame)
RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size);
else
RenderText(text_pos, label, label_end, false);

PopStyleColor(); // MicroStrain

if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
TreePushOverrideID(id);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | (is_leaf ? 0 : ImGuiItemStatusFlags_Openable) | (is_open ? ImGuiItemStatusFlags_Opened : 0));
Expand Down Expand Up @@ -6852,8 +6859,18 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
PopColumnsBackground();
}

// MicroStrain
if(hovered || selected)
ImGui::PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_HeaderText));
else if(disabled_item || disabled_global)
ImGui::PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_TextDisabled));

RenderTextClipped(text_min, text_max, label, NULL, &label_size, style.SelectableTextAlign, &bb);

// MicroStrain
if(hovered || selected || disabled_item || disabled_global)
ImGui::PopStyleColor();

// Automatically close popups
if (pressed && ((window->Flags & ImGuiWindowFlags_Popup) || (window->IsExplicitChild && window->ParentWindow->Flags & ImGuiWindowFlags_Popup)) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.LastItemData.InFlags & ImGuiItemFlags_SelectableDontClosePopup))
CloseCurrentPopup();
Expand Down Expand Up @@ -8672,10 +8689,10 @@ static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar)
//window->DrawList->AddRect(ImVec2(tab_bar->BarRect.Max.x - scrolling_buttons_width, tab_bar->BarRect.Min.y), ImVec2(tab_bar->BarRect.Max.x, tab_bar->BarRect.Max.y), IM_COL32(255,0,0,255));

int select_dir = 0;
ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text];
ImVec4 arrow_col = g.Style.Colors[ImGuiCol_TabText]; // MicroStrain
arrow_col.w *= 0.5f;

PushStyleColor(ImGuiCol_Text, arrow_col);
PushStyleColor(ImGuiCol_TabText, arrow_col); // MicroStrain
PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
const float backup_repeat_delay = g.IO.KeyRepeatDelay;
const float backup_repeat_rate = g.IO.KeyRepeatRate;
Expand Down Expand Up @@ -8732,9 +8749,9 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar)
window->DC.CursorPos = ImVec2(tab_bar->BarRect.Min.x - g.Style.FramePadding.y, tab_bar->BarRect.Min.y);
tab_bar->BarRect.Min.x += tab_list_popup_button_width;

ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text];
ImVec4 arrow_col = g.Style.Colors[ImGuiCol_TabText]; // MicroStrain
arrow_col.w *= 0.5f;
PushStyleColor(ImGuiCol_Text, arrow_col);
PushStyleColor(ImGuiCol_TabText, arrow_col); // MicroStrain
PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
bool open = BeginCombo("##v", NULL, ImGuiComboFlags_NoPreview | ImGuiComboFlags_HeightLargest);
PopStyleColor(2);
Expand Down Expand Up @@ -9245,7 +9262,7 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
else if (unsaved_marker_visible)
{
const ImRect bullet_bb(button_pos, button_pos + ImVec2(button_sz, button_sz));
RenderBullet(draw_list, bullet_bb.GetCenter(), GetColorU32(ImGuiCol_Text));
RenderBullet(draw_list, bullet_bb.GetCenter(), GetColorU32(ImGuiCol_TabText)); // MicroStrain
}

// This is all rather complicated
Expand All @@ -9258,7 +9275,10 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
text_ellipsis_clip_bb.Max.x -= unsaved_marker_visible ? (button_sz * 0.80f) : 0.0f;
ellipsis_max_x = text_pixel_clip_bb.Max.x;
}

PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_TabText)); // MicroStrain
RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size);
PopStyleColor(); // MicroStrain

#if 0
if (!is_contents_visible)
Expand Down

0 comments on commit e21d366

Please sign in to comment.