Skip to content

How do I get a Selectable to fill a table cell/row height? #8542

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

Open
lailoken opened this issue Apr 1, 2025 · 2 comments
Open

How do I get a Selectable to fill a table cell/row height? #8542

lailoken opened this issue Apr 1, 2025 · 2 comments

Comments

@lailoken
Copy link

lailoken commented Apr 1, 2025

Version/Branch of Dear ImGui:

1.92.0 WIP

Back-ends:

any

Compiler, OS:

any

Full config/build information:

No response

Details:

My Question:

I have a table with texts and selectables.
I want:

  • The selectable must always fill the full row height exactly, no matter the current CellPadding (or ItemSpacing)
  • The selectable text must still align vertically with normal text on the row.

In my example I explicitly call TableNextRow() with a height because I sometimes don't have anything to render on certain lines and I want the line heights to be consistent (for clipper etc.)

This is a simplified example of what I'm trying to do, in reality I may not even know in my table loop whether I am rendering a selectable or text (that is determined in a called module).

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

void test()
{
    ImGui::Begin("Test", nullptr, LocalConfig::ViewportWindowFlags());
    ImGui::BeginTable("Test", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders);
    const float rowHeight = ImGui::GetTextLineHeight() + ImGui::GetStyle().CellPadding.y * 2;  // force height, even if we don't have text
    for (int i = 0; i < 10; i++)
    {
        ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
        ImGui::PushID(i);
        ImGui::TableNextColumn();
        ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.f));
        ImGui::Selectable("Selectable", false, ImGuiSelectableFlags_SpanAllColumns);
        ImGui::PopStyleVar();
        ImGui::TableNextColumn();
        ImGui::Text("Text");
        ImGui::PopID();
    }
    ImGui::EndTable();
    ImGui::End();
}
@ocornut
Copy link
Owner

ocornut commented Apr 1, 2025

Out of curiosity are you using the Selectable() only for highlight or as a clicking device?

We ought to add a ImGuiTableFlags_HighlightHoveredRow (#8498) but you could technically use TableSetBgColor().

The selectable text must still align vertically with normal text on the row.

For this, in case you end up manually submitting a Selectable() from the top of the cell, the simpler may be to submit a Selectable() with no label, and the Text() separately.

But we ought to aim to support that a little better, e.g. hypothetically a ImGuiSelectableFlags_SpanAllRow could alter Y1/Y2 of the selectable.

@lailoken
Copy link
Author

lailoken commented Apr 15, 2025

I use it mostly as buttons but with variations.

Sometimes we:

  • Show selection state,
  • Right click context
  • Left click to select or execute (sometimes also double click)
  • Sometimes we span all columns, and other times not.
  • (or combintations of these)

What I want is a way to fill the entire cell/row with the selection, up to the edges (ignoring frame/item/cell-padding whaever it is at the time)

Not this:

Image

I have found ways to do it, but then I have text alignment issues (which I then need to solve by just writing text and using a blank selection overlay). But I would prefer to avoid this. For now it's purely aesthetic, not a big problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants