Skip to content

Commit

Permalink
Repo UI: Improved item visibility in 'compact' view.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and tritonas00 committed Mar 12, 2022
1 parent b3831d3 commit 888147a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions source/main/gui/panels/GUI_RepositorySelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ void RepositorySelector::Draw()
}

// Draw table body
int num_drawn_items = 0;
for (int i = 0; i < m_data.items.size(); i++)
{
// Skip items from non mod categories
Expand Down Expand Up @@ -912,6 +913,24 @@ void RepositorySelector::Draw()
else if (m_view_mode == "Compact")
{
float orig_cursor_x = ImGui::GetCursorPos().x;

// Calc box size: Draw 3 boxes per line, 2 for small resolutions
float box_width = (ImGui::GetIO().DisplaySize.x / 1.4) / 3;
if (ImGui::GetIO().DisplaySize.x <= 1280)
{
box_width = (ImGui::GetIO().DisplaySize.x / 1.4) / 2;
}

// Skip to new line if at least 50% of the box can't fit on current line.
if (orig_cursor_x > ImGui::GetWindowContentRegionMax().x - (box_width * 0.5))
{
// Unless this is the 1st line... not much to do with such narrow window.
if (num_drawn_items != 0)
{
ImGui::NewLine();
}
}

ImGui::BeginGroup();

ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.70f, 0.70f, 0.70f, 0.90f));
Expand All @@ -922,13 +941,6 @@ void RepositorySelector::Draw()
float orig_cursor_y = ImGui::GetCursorPosY();
std::string item_id = "##" + std::to_string(i);

// Draw 3 boxes per line, 2 for small resolutions
float box_width = (ImGui::GetIO().DisplaySize.x / 1.4) / 3;
if (ImGui::GetIO().DisplaySize.x <= 1280)
{
box_width = (ImGui::GetIO().DisplaySize.x / 1.4) / 2;
}

if (ImGui::Selectable(item_id.c_str(), m_selected_item.resource_id == m_data.items[i].resource_id, 0, ImVec2(box_width - ImGui::GetStyle().ItemSpacing.x, 100)))
{
m_selected_item = m_data.items[i];
Expand Down Expand Up @@ -998,12 +1010,6 @@ void RepositorySelector::Draw()

ImGui::EndGroup();
ImGui::SameLine();

// Add new line
if ( orig_cursor_x > ImGui::GetWindowSize().x - box_width)
{
ImGui::NewLine();
}
}
else if (m_view_mode == "Basic")
{
Expand Down Expand Up @@ -1068,6 +1074,7 @@ void RepositorySelector::Draw()
ImGui::Separator();
}
ImGui::PopID();
num_drawn_items++;
}
}
ImGui::EndChild();
Expand Down

0 comments on commit 888147a

Please # to comment.