Implement "text-align"

"text-align" allows setting the alignment of text, with respect to
other lines and allocated space, without requiring a reference to
the ClutterText (which is private for most widgets).
If not specified, all text is left-aligned.

https://bugzilla.gnome.org/show_bug.cgi?id=622447
This commit is contained in:
Giovanni Campagna 2010-06-22 22:04:45 +02:00 committed by Florian Müllner
parent 3af4ca3fe9
commit 97f883b10e
5 changed files with 67 additions and 1 deletions

View File

@ -553,6 +553,7 @@ StTooltip {
height: 70px;
font-size: 10px;
transition-duration: 100;
text-align: center;
}
.app-well-app.running {

View File

@ -456,7 +456,6 @@ AppIcon.prototype = {
box.add(this.icon, { expand: true, x_fill: false, y_fill: false });
this._name = new St.Label({ text: this.app.get_name() });
this._name.clutter_text.line_alignment = Pango.Alignment.CENTER;
box.add_actor(this._name);
}
};

View File

@ -280,6 +280,7 @@ _st_set_text_from_style (ClutterText *text,
PangoAttrList *attribs;
const PangoFontDescription *font;
gchar *font_string;
StTextAlign align;
st_theme_node_get_foreground_color (theme_node, &color);
clutter_text_set_color (text, &color);
@ -309,6 +310,15 @@ _st_set_text_from_style (ClutterText *text,
clutter_text_set_attributes (text, attribs);
pango_attr_list_unref (attribs);
align = st_theme_node_get_text_align (theme_node);
if(align == ST_TEXT_ALIGN_JUSTIFY) {
clutter_text_set_justify (text, TRUE);
clutter_text_set_line_alignment (text, PANGO_ALIGN_LEFT);
} else {
clutter_text_set_justify (text, FALSE);
clutter_text_set_line_alignment (text, (PangoAlignment) align);
}
}
gboolean

View File

@ -1761,6 +1761,53 @@ st_theme_node_get_text_decoration (StThemeNode *node)
return 0;
}
StTextAlign
st_theme_node_get_text_align(StThemeNode *node)
{
int i;
ensure_properties(node);
for (i = node->n_properties - 1; i >= 0; i--)
{
CRDeclaration *decl = node->properties[i];
if (strcmp(decl->property->stryng->str, "text-align") == 0)
{
CRTerm *term = decl->value;
if (term->type != TERM_IDENT || term->next)
continue;
if (strcmp(term->content.str->stryng->str, "inherit") == 0)
{
if (node->parent_node)
return st_theme_node_get_text_align(node->parent_node);
return ST_TEXT_ALIGN_LEFT;
}
else if (strcmp(term->content.str->stryng->str, "left") == 0)
{
return ST_TEXT_ALIGN_LEFT;
}
else if (strcmp(term->content.str->stryng->str, "right") == 0)
{
return ST_TEXT_ALIGN_RIGHT;
}
else if (strcmp(term->content.str->stryng->str, "center") == 0)
{
return ST_TEXT_ALIGN_CENTER;
}
else if (strcmp(term->content.str->stryng->str, "justify") == 0)
{
return ST_TEXT_ALIGN_JUSTIFY;
}
}
}
if(node->parent_node)
return st_theme_node_get_text_align(node->parent_node);
return ST_TEXT_ALIGN_LEFT;
}
static gboolean
font_family_from_terms (CRTerm *term,
char **family)

View File

@ -58,6 +58,13 @@ typedef enum {
ST_TEXT_DECORATION_BLINK = 1 << 3
} StTextDecoration;
typedef enum {
ST_TEXT_ALIGN_LEFT = PANGO_ALIGN_LEFT,
ST_TEXT_ALIGN_CENTER = PANGO_ALIGN_CENTER,
ST_TEXT_ALIGN_RIGHT = PANGO_ALIGN_RIGHT,
ST_TEXT_ALIGN_JUSTIFY
} StTextAlign;
typedef enum {
ST_GRADIENT_NONE,
ST_GRADIENT_VERTICAL,
@ -149,6 +156,8 @@ int st_theme_node_get_transition_duration (StThemeNode *node);
StTextDecoration st_theme_node_get_text_decoration (StThemeNode *node);
StTextAlign st_theme_node_get_text_align (StThemeNode *node);
/* Font rule processing is pretty complicated, so we just hardcode it
* under the standard font/font-family/font-size/etc names. This means
* you can't have multiple separate styled fonts for a single item,