forked from AuroraMiddleware/gtk
Merge branch 'wip/otte/inscription' into 'main'
Inscription: Derive row alignment from xalign See merge request GNOME/gtk!4811
This commit is contained in:
commit
f9b0866415
@ -233,6 +233,24 @@ gtk_inscription_set_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_pango_alignment (GtkInscription *self)
|
||||
{
|
||||
PangoAlignment align;
|
||||
gboolean ltr;
|
||||
|
||||
ltr = _gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL;
|
||||
|
||||
if (self->xalign < 0.33)
|
||||
align = ltr ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
|
||||
else if (self->xalign < 0.67)
|
||||
align = PANGO_ALIGN_CENTER;
|
||||
else
|
||||
align = ltr ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
|
||||
|
||||
pango_layout_set_alignment (self->layout, align);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inscription_update_layout_attributes (GtkInscription *self,
|
||||
PangoAttrList *css_attrs)
|
||||
@ -267,6 +285,17 @@ gtk_inscription_css_changed (GtkWidget *widget,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inscription_direction_changed (GtkWidget *widget,
|
||||
GtkTextDirection previous_direction)
|
||||
{
|
||||
GtkInscription *self = GTK_INSCRIPTION (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_inscription_parent_class)->direction_changed (widget, previous_direction);
|
||||
|
||||
update_pango_alignment (self);
|
||||
}
|
||||
|
||||
static PangoFontMetrics *
|
||||
gtk_inscription_get_font_metrics (GtkInscription *self)
|
||||
{
|
||||
@ -395,7 +424,10 @@ gtk_inscription_get_layout_location (GtkInscription *self,
|
||||
xalign = 1.0 - xalign;
|
||||
|
||||
pango_layout_get_pixel_extents (self->layout, NULL, &logical);
|
||||
x = floor ((xalign * (widget_width - logical.width)) - logical.x);
|
||||
if (pango_layout_get_width (self->layout) > 0)
|
||||
x = 0.f;
|
||||
else
|
||||
x = floor ((xalign * (widget_width - logical.width)) - logical.x);
|
||||
|
||||
baseline = gtk_widget_get_allocated_baseline (widget);
|
||||
if (baseline != -1)
|
||||
@ -444,7 +476,17 @@ gtk_inscription_allocate (GtkWidget *widget,
|
||||
PangoRectangle rect;
|
||||
pango_layout_iter_get_line_extents (iter, NULL, &rect);
|
||||
if (rect.y + rect.height > height * PANGO_SCALE)
|
||||
pango_layout_set_width (self->layout, -1);
|
||||
{
|
||||
while (!pango_layout_line_is_paragraph_start (pango_layout_iter_get_line_readonly (iter)))
|
||||
{
|
||||
if (!pango_layout_iter_next_line (iter))
|
||||
break;
|
||||
}
|
||||
if (!pango_layout_line_is_paragraph_start (pango_layout_iter_get_line_readonly (iter)))
|
||||
{
|
||||
pango_layout_set_width (self->layout, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -491,6 +533,7 @@ gtk_inscription_class_init (GtkInscriptionClass *klass)
|
||||
gobject_class->set_property = gtk_inscription_set_property;
|
||||
|
||||
widget_class->css_changed = gtk_inscription_css_changed;
|
||||
widget_class->direction_changed = gtk_inscription_direction_changed;
|
||||
widget_class->measure = gtk_inscription_measure;
|
||||
widget_class->size_allocate = gtk_inscription_allocate;
|
||||
widget_class->snapshot = gtk_inscription_snapshot;
|
||||
@ -700,6 +743,7 @@ gtk_inscription_init (GtkInscription *self)
|
||||
|
||||
self->layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), NULL);
|
||||
pango_layout_set_wrap (self->layout, PANGO_WRAP_WORD_CHAR);
|
||||
update_pango_alignment (self);
|
||||
}
|
||||
|
||||
/* for a11y */
|
||||
@ -988,6 +1032,8 @@ gtk_inscription_set_xalign (GtkInscription *self,
|
||||
|
||||
self->xalign = xalign;
|
||||
|
||||
update_pango_alignment (self);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_XALIGN]);
|
||||
|
52
testsuite/reftests/inscription-xalign-rtl.ref.ui
Normal file
52
testsuite/reftests/inscription-xalign-rtl.ref.ui
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="default-width">200</property>
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.0</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.25</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.5</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.75</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">1.0</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
54
testsuite/reftests/inscription-xalign-rtl.ui
Normal file
54
testsuite/reftests/inscription-xalign-rtl.ui
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="default-width">200</property>
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<signal name="map" handler="reftest:set_default_direction_rtl" swapped="no"/>
|
||||
<signal name="destroy" handler="reftest:set_default_direction_ltr" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.0</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.25</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.5</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.75</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text">עִברִית
|
||||
English</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">1.0</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
42
testsuite/reftests/inscription-xalign.ref.ui
Normal file
42
testsuite/reftests/inscription-xalign.ref.ui
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="default-width">200</property>
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">align
|
||||
0.0</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="wrap">1</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="justify">left</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">align
|
||||
0.5</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="wrap">1</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="justify">center</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">align
|
||||
1.0</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="wrap">1</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
39
testsuite/reftests/inscription-xalign.ui
Normal file
39
testsuite/reftests/inscription-xalign.ui
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow">
|
||||
<property name="default-width">200</property>
|
||||
<property name="decorated">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text" translatable="yes">align
|
||||
0.0</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text" translatable="yes">align
|
||||
0.5</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">0.5</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInscription">
|
||||
<property name="text" translatable="yes">align
|
||||
1.0</property>
|
||||
<property name="wrap-mode">word</property>
|
||||
<property name="min-lines">2</property>
|
||||
<property name="xalign">1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
@ -375,6 +375,10 @@ testdata = [
|
||||
'inscription-overflow-multiline.ui',
|
||||
'inscription-overflow-yalign.ref.ui',
|
||||
'inscription-overflow-yalign.ui',
|
||||
'inscription-xalign.ref.ui',
|
||||
'inscription-xalign.ui',
|
||||
'inscription-xalign-rtl.ref.ui',
|
||||
'inscription-xalign-rtl.ui',
|
||||
'label-attribute-preference.css',
|
||||
'label-attribute-preference.ref.ui',
|
||||
'label-attribute-preference.ui',
|
||||
|
Loading…
Reference in New Issue
Block a user