overlay: fix highlights, alignment in presets table (#769)

* Fix table row highlight hover detection in Options tab when row has
two lines of text
* Fix text alignment in controller presets table
This commit is contained in:
bicarus
2026-06-19 00:40:54 -07:00
committed by GitHub
parent db71a0b24d
commit e8949a2612
4 changed files with 26 additions and 31 deletions
+12 -11
View File
@@ -2,6 +2,7 @@
#include <cmath> #include <cmath>
#include "external/imgui/imgui.h" #include "external/imgui/imgui.h"
#include "external/imgui/imgui_internal.h"
#include "overlay/overlay.h" #include "overlay/overlay.h"
@@ -209,17 +210,17 @@ namespace ImGui {
return open; return open;
} }
void InvisibleTableRowSelectable() { void HighlightTableRowOnHover() {
ImGui::TableSetColumnIndex(0); // hit-test the row rect directly so the row layout and height are untouched
ImGui::PushStyleColor(ImGuiCol_Header, 0); ImGuiTable *table = ImGui::GetCurrentTable();
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, 0); if (table == nullptr) {
ImGui::PushStyleColor(ImGuiCol_HeaderActive, 0); return;
ImGui::PushTabStop(false); // prevent tab navigation }
ImGui::Selectable("##row", false, if (ImGui::IsWindowHovered() &&
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap); ImGui::IsMouseHoveringRect(
ImGui::PopTabStop(); ImVec2(table->WorkRect.Min.x, table->RowPosY1),
ImGui::PopStyleColor(3); ImVec2(table->WorkRect.Max.x, table->RowPosY2),
if (ImGui::IsItemHovered()) { false)) {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg1, IM_COL32(200, 200, 200, 24)); ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg1, IM_COL32(200, 200, 200, 24));
} }
} }
+1 -1
View File
@@ -20,7 +20,7 @@ namespace ImGui {
void TextTruncated(const std::string& p_text, float p_truncated_width); void TextTruncated(const std::string& p_text, float p_truncated_width);
bool DeleteButton(const std::string& tooltip); bool DeleteButton(const std::string& tooltip);
bool ClearButton(const std::string& tooltip); bool ClearButton(const std::string& tooltip);
void InvisibleTableRowSelectable(); void HighlightTableRowOnHover();
// Config tab bar with extra label padding and uniform, centered tab widths. // Config tab bar with extra label padding and uniform, centered tab widths.
// Wrap items in BeginPaddedTabItem between BeginPaddedTabBar/EndTabBar. // Wrap items in BeginPaddedTabItem between BeginPaddedTabBar/EndTabBar.
+12 -17
View File
@@ -928,18 +928,14 @@ namespace overlay::windows {
// primary // primary
build_button(name, primary_button, &primary_button, button_it, button_it_max, 0); build_button(name, primary_button, &primary_button, button_it, button_it_max, 0);
ImGui::PushID(&primary_button); ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
ImGui::PopID();
// alternatives // alternatives
int alt_index = 1; // 0 is primary int alt_index = 1; // 0 is primary
for (auto &alt : primary_button.getAlternatives()) { for (auto &alt : primary_button.getAlternatives()) {
if (alt.isValid()) { if (alt.isValid()) {
build_button(name, primary_button, &alt, button_it, button_it_max, alt_index); build_button(name, primary_button, &alt, button_it, button_it_max, alt_index);
ImGui::PushID(&alt); ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
ImGui::PopID();
} }
alt_index++; alt_index++;
} }
@@ -2519,8 +2515,7 @@ namespace overlay::windows {
edit_analog_popup(analog, title); edit_analog_popup(analog, title);
// row hover detection (invisible selectable that spans entire row) ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
// clean up // clean up
ImGui::PopID(); ImGui::PopID();
@@ -3174,16 +3169,12 @@ namespace overlay::windows {
} }
build_light(light, &light, i, 0); build_light(light, &light, i, 0);
ImGui::PushID(&light); ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
ImGui::PopID();
int alt_index = 1; int alt_index = 1;
for (auto &alt : light.getAlternatives()) { for (auto &alt : light.getAlternatives()) {
if (alt.isValid()) { if (alt.isValid()) {
build_light(light, &alt, i, alt_index); build_light(light, &alt, i, alt_index);
ImGui::PushID(&alt); ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
ImGui::PopID();
} }
alt_index++; alt_index++;
} }
@@ -5296,8 +5287,7 @@ namespace overlay::windows {
} }
} }
// row hover detection (invisible selectable that spans entire row) ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
// next item // next item
ImGui::PopID(); ImGui::PopID();
@@ -5790,23 +5780,28 @@ namespace overlay::windows {
// name // name
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::TextTruncated( ImGui::TextTruncated(
t.name, ImGui::GetContentRegionAvail().x - overlay::apply_scaling(20)); t.name, ImGui::GetContentRegionAvail().x - overlay::apply_scaling(20));
// type // type
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(t.is_builtin ? "Built-in" : "User"); ImGui::TextUnformatted(t.is_builtin ? "Built-in" : "User");
// buttons // buttons
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::Text("%d", (int)t.buttons.size()); ImGui::Text("%d", (int)t.buttons.size());
// analogs // analogs
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::Text("%d", (int)t.analogs.size()); ImGui::Text("%d", (int)t.analogs.size());
// lights // lights
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::Text("%d", (int)t.lights.size()); ImGui::Text("%d", (int)t.lights.size());
// actions // actions
@@ -5834,7 +5829,7 @@ namespace overlay::windows {
} }
} }
ImGui::InvisibleTableRowSelectable(); ImGui::HighlightTableRowOnHover();
ImGui::PopID(); ImGui::PopID();
} }
@@ -876,8 +876,7 @@ namespace overlay::windows {
ImGui::EndDisabled(); ImGui::EndDisabled();
} }
// row hover detection (invisible selectable that spans entire row) ImGui::HighlightTableRowOnHover();
ImGui::InvisibleTableRowSelectable();
ImGui::PopID(); ImGui::PopID();
} }