Text alignment with PangoTabArray

Hi,
I want to display a simple text with an alignment, but cannot figure out how to use PangoTabArray.
Here is my sample code:

	char aaa[] =	"Just a value:\t 0,2588\n"
					"text:\t 11,98\n"
					"third line:\t 8744,599874";

	tab = pango_tab_array_new_with_positions (2, TRUE,
			PANGO_TAB_RIGHT, 200,
			PANGO_TAB_DECIMAL, 320);

	pango_layout_set_tabs (pangolay, tab);
	pango_layout_set_text (pangolay, aaa, -1);
	pango_cairo_show_layout (cr, pangolay);

and this is the output:
image
What I want is to align the text left from ‘:’ to the right (first tab) and the text after ‘:’ with a decimal alignment.
In my locale ‘,’ is the decimal separator.

You can see that your numbers are being right-aligned, so they’re using the first tab stop. It seems that you need to add a tab character at the start of each line so your layout will advance to the tab stop.

Hah! It works! Thank you! Alignment is perfect on both tab stops.

But could you maybe explain why it works like this? Is there some rule or a special way Pango is handling this? I could not find much in help.

It’s just like setting tab stops in a word processor, isn’t it? You have to tab to the stop.

It’s a little confusing that the Tabs demo in gtk4-demo has three tab stops with only two \ts per line, but it seems that the first stop is basically a no-op because it’s at position 0.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.