fpaquet / gtksheet

A spreadsheet widget for Gtk+
http://fpaquet.github.io/gtksheet/
Other
27 stars 9 forks source link

Mouse over column header button refreshes 'column title text' into cell to left (clipping issue?) #20

Closed wmclaugh closed 4 years ago

wmclaugh commented 4 years ago

If a column title label is longer than the column width, it is clipped in the default gtksheet display. However, if the cursor is dragged into a column header cell where the label is 'clipped', the text is re-rendered with the left side of the text rendered into the cell to the left of the one moused over. Extended text on the right side of the label remains correctly clipped. For example, if the column titles are set to "MyColumnC#", the default displayed button text may display "Column". On a mouse over of the button, the "My" portion of the label gets rendered in the Column title of the cell to the left.

This behavior occurs on Linux (RedHat 7.4) and macOS (10.14) using gtk 3.22.10 and gtksheet v4.3.3. To replicate the issue, simply change 1 line in the build_example1 routine in testgtksheet.c. Change line ~626 from:

  //sprintf(title, "%c", 'A'+i);
  sprintf(title, "MyColumn_%c%d", 'A'+i,i);

and recompile. If you move the cursor over the column headers, you can view the rendering issue. The attached PNG shows the issue where the cursor has been moved over the two column headers to the left of the cell with the smiley icon:

testgtksheet

fpaquet commented 4 years ago

The label ist an internal widget of a GtkToolButton with a given width. It happens when label text is wider than toggle button.

This overlap can be prevented by setting ellipsize property of the label widget.

fpaquet commented 4 years ago

I'm not convinced to set ellipsize per default.

Code to achieve default ellipsize would be:

function _gtk_sheet_column_button_add_label_internal(), near end of function (line 198) add:

    gtk_button_set_label(GTK_BUTTON(colobj->col_button), label);
+    GtkWidget *label_widget = gtk_bin_get_child(GTK_BIN(colobj->col_button));
+    gtk_label_set_ellipsize(GTK_LABEL(label_widget), PANGO_ELLIPSIZE_END);
}
fpaquet commented 4 years ago

Experimentally enabled ellipsis on sheet column title labels. Checkt into branch gtk3_fixes

wmclaugh commented 4 years ago

Thanks for the fix. Using your suggested change to set ellipsize appears to fix the clipping issue. I note that I added a check on the returned child widget:

GtkWidget *label_widget = gtk_bin_get_child(GTK_BIN(colobj->col_button));
if (label_widget)  gtk_label_set_ellipsize(GTK_LABEL(label_widget), PANGO_ELLIPSIZE_END);

to avoid getting spurious warnings at startup:

(lt-testgtksheet:27237): Gtk-CRITICAL **: 10:14:47.804: gtk_label_set_ellipsize: assertion 'GTK_IS_LABEL (label)' failed

fpaquet commented 4 years ago

Thank you for reporting, i thought widget type should be clear, but obviously it isn't.

I will incorporate the fix next weekend.

fpaquet commented 4 years ago

Patch applied to branch gtk_fixes