libgimpwidgets: improving (kinda) GimpSpinScale in RTL layout.

The label was simply completely invisible because of broken progress
computation. Now it is visible at least when the progress fully cover
the label, but a part of the label is not drawn when the progression is
smaller than the label. I still have not figured out how to fix this,
though I am starting to wonder if we should not just drop this 2-color
fancy drawing of the label. Clearly the fact we can't get the exact
progression gadget dimension is biting us.

Another issue I noticed when playing with RTL layout is that when
editing the value, it gets printed on the right side (together with the
label) which gets messy. This is also something to figure out, hoping we
get an API for this on the GTK side.

Also I am setting "auto dir" to FALSE on the Pango layout, making sure
it follows the widget direction, whatsoever. In particular, even if the
contents is not RTL characters, we should keep a RTL layout to avoid
completely broken layout.
This commit is contained in:
Jehan 2022-02-16 18:46:13 +01:00
parent dfd05c0717
commit c93742f178

View file

@ -399,6 +399,12 @@ gimp_spin_scale_draw (GtkWidget *widget,
private->layout = gtk_widget_create_pango_layout (widget,
private->label_text);
pango_layout_set_ellipsize (private->layout, PANGO_ELLIPSIZE_END);
/* Needing to force right-to-left layout when the widget is
* set so, even when the text is not RTL text. Without this,
* such case is broken because on the left side, we'd have
* both the value and the label texts.
*/
pango_layout_set_auto_dir (private->layout, FALSE);
if (private->mnemonics_visible)
{
@ -436,23 +442,14 @@ gimp_spin_scale_draw (GtkWidget *widget,
gtk_style_context_restore (style);
progress_fraction = gtk_entry_get_progress_fraction (GTK_ENTRY (widget));
progress_y = 0.0;
progress_width = (gdouble) text_area.width * progress_fraction;
progress_height = text_area.height;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
{
progress_fraction = 1.0 - progress_fraction;
progress_x = (gdouble) text_area.width * progress_fraction + text_area.x;
progress_y = 0.0;
progress_width = text_area.width - progress_x;
progress_height = text_area.height;
}
progress_x = text_area.width + text_area.x - progress_width;
else
{
progress_x = text_area.x;
progress_y = 0.0;
progress_width = (gdouble) text_area.width * progress_fraction;
progress_height = text_area.height;
}
progress_x = text_area.x;
cairo_save (cr);