[wxGTK] wxChoice label clipping with long item(s)

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
tessman
Earned some good credits
Earned some good credits
Posts: 109
Joined: Tue Oct 06, 2009 5:25 pm

[wxGTK] wxChoice label clipping with long item(s)

Post by tessman »

(Screenshots from wxWidgets 3.1.6 widgets sample, pulled today, built against GTK 3, running on Ubuntu 18.04.)

Note the wxChoice on the right-hand side (after clicking "Insert a few strings".) The left-hand side of the choice is clipped, because the selected item "another one" is much shorter than "and the last very, very, very, very, very, very...long one". (If "another one" was a little longer, you might see the end of it peeking in at the visible left of the wxChoice.)
Screen Shot 2021-06-22 at 5.46.50 PM.png
Screen Shot 2021-06-22 at 5.47.36 PM.png
I've tried a couple of different solutions to this, including specifying the size of the wxChoice (resulting in clipping), or leaving it to wxDefaultSize (resulting in a long, long, long wxChoice in the layout).

As far as I know there's no way to tweak force alignment, or ellipsization, or anything that would help.

This seems to be solely a GTK 3 problem. GTK 2 rendering shows "another one" properly in the wxChoice when selected without oversizing/clipping.

Has anyone successfully worked around this behaviour?
tessman
Earned some good credits
Earned some good credits
Posts: 109
Joined: Tue Oct 06, 2009 5:25 pm

Re: [wxGTK] wxChoice label clipping with long item(s)

Post by tessman »

To answer my own question, this issue has been discussed with a solution proposed here: https://groups.google.com/u/4/g/wx-users/c/CwLLldm1UN4

Essentially the ellipsize mode must be explicitly set; the PR does it in wxChoice::Create().

Code: Select all

    // GTK 3 has a sizing issue with long combobox text: it needs ellipsization set
    GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_widget));
    if (cells)
    {
        GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
        if (cell)
            g_object_set(G_OBJECT(cell), "ellipsize", PANGO_ELLIPSIZE_END, NULL); 
        // Only the list of cells must be freed, the renderer isn't ours to free
        g_list_free(cells); 
    }
Post Reply