popupMenu: Simplify allocation code

Use ClutterActor.allocate_align_fill() so we don't have to do
this math ourselves. At the same time, clean up the RTL handling
so that it's easier to follow.

https://bugzilla.gnome.org/show_bug.cgi?id=702539
This commit is contained in:
Jasper St. Pierre
2013-06-14 17:53:59 -04:00
parent 2aae272d86
commit 2fa40555e6
9 changed files with 97 additions and 136 deletions

View File

@ -104,8 +104,8 @@ shell_slicer_paint_child (ShellSlicer *self)
return;
st_bin_get_alignment (ST_BIN (self), &x_align, &y_align);
_st_get_align_factors (x_align, y_align,
&x_align_factor, &y_align_factor);
st_get_align_factors (x_align, y_align,
&x_align_factor, &y_align_factor);
clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &self_box);
clutter_actor_get_allocation_box (child, &child_box);

View File

@ -108,8 +108,8 @@ st_bin_allocate (ClutterActor *self,
gdouble x_align_f, y_align_f;
st_theme_node_get_content_box (theme_node, box, &childbox);
_st_get_align_factors (priv->x_align, priv->y_align,
&x_align_f, &y_align_f);
st_get_align_factors (priv->x_align, priv->y_align,
&x_align_f, &y_align_f);
clutter_actor_allocate_align_fill (priv->child, &childbox,
x_align_f, y_align_f,
priv->x_fill, priv->y_fill,

View File

@ -736,7 +736,7 @@ st_box_layout_allocate (ClutterActor *actor,
"expand", &expand,
NULL);
_st_get_align_factors (xalign, yalign, &xalign_f, &yalign_f);
st_get_align_factors (xalign, yalign, &xalign_f, &yalign_f);
if (priv->is_vertical)
{

View File

@ -98,66 +98,6 @@ _st_actor_get_preferred_height (ClutterActor *actor,
clutter_actor_get_preferred_height (actor, for_width, min_height_p, natural_height_p);
}
/**
* _st_get_align_factors:
* @x_align: an #StAlign
* @y_align: an #StAlign
* @x_align_out: (out) (allow-none): @x_align as a #gdouble
* @y_align_out: (out) (allow-none): @y_align as a #gdouble
*
* Converts @x_align and @y_align to #gdouble values.
*/
void
_st_get_align_factors (StAlign x_align,
StAlign y_align,
gdouble *x_align_out,
gdouble *y_align_out)
{
if (x_align_out)
{
switch (x_align)
{
case ST_ALIGN_START:
*x_align_out = 0.0;
break;
case ST_ALIGN_MIDDLE:
*x_align_out = 0.5;
break;
case ST_ALIGN_END:
*x_align_out = 1.0;
break;
default:
g_warn_if_reached ();
break;
}
}
if (y_align_out)
{
switch (y_align)
{
case ST_ALIGN_START:
*y_align_out = 0.0;
break;
case ST_ALIGN_MIDDLE:
*y_align_out = 0.5;
break;
case ST_ALIGN_END:
*y_align_out = 1.0;
break;
default:
g_warn_if_reached ();
break;
}
}
}
/**
* _st_set_text_from_style:
* @text: Target #ClutterText

View File

@ -45,11 +45,6 @@ G_END_DECLS
ClutterActor *_st_widget_get_dnd_clone (StWidget *widget);
void _st_get_align_factors (StAlign x_align,
StAlign y_align,
gdouble *x_align_out,
gdouble *y_align_out);
void _st_actor_get_preferred_width (ClutterActor *actor,
gfloat for_height,
gboolean y_fill,

View File

@ -257,8 +257,8 @@ st_table_homogeneous_allocate (ClutterActor *self,
row_span = meta->row_span;
col_span = meta->col_span;
_st_get_align_factors (meta->x_align, meta->y_align,
&x_align_f, &y_align_f);
st_get_align_factors (meta->x_align, meta->y_align,
&x_align_f, &y_align_f);
if (ltr)
{
@ -609,8 +609,8 @@ st_table_preferred_allocate (ClutterActor *self,
row_span = meta->row_span;
col_span = meta->col_span;
_st_get_align_factors (meta->x_align, meta->y_align,
&x_align_f, &y_align_f);
st_get_align_factors (meta->x_align, meta->y_align,
&x_align_f, &y_align_f);
/* initialise the width and height */
col_width = col_widths[col];

View File

@ -2885,3 +2885,63 @@ st_widget_get_focus_chain (StWidget *widget)
{
return ST_WIDGET_GET_CLASS (widget)->get_focus_chain (widget);
}
/**
* st_get_align_factors:
* @x_align: an #StAlign
* @y_align: an #StAlign
* @x_align_out: (out) (allow-none): @x_align as a #gdouble
* @y_align_out: (out) (allow-none): @y_align as a #gdouble
*
* Converts @x_align and @y_align to #gdouble values.
*/
void
st_get_align_factors (StAlign x_align,
StAlign y_align,
gdouble *x_align_out,
gdouble *y_align_out)
{
if (x_align_out)
{
switch (x_align)
{
case ST_ALIGN_START:
*x_align_out = 0.0;
break;
case ST_ALIGN_MIDDLE:
*x_align_out = 0.5;
break;
case ST_ALIGN_END:
*x_align_out = 1.0;
break;
default:
g_warn_if_reached ();
break;
}
}
if (y_align_out)
{
switch (y_align)
{
case ST_ALIGN_START:
*y_align_out = 0.0;
break;
case ST_ALIGN_MIDDLE:
*y_align_out = 0.5;
break;
case ST_ALIGN_END:
*y_align_out = 1.0;
break;
default:
g_warn_if_reached ();
break;
}
}
}

View File

@ -151,7 +151,6 @@ StThemeNode * st_widget_peek_theme_node (StWidget *widg
GList * st_widget_get_focus_chain (StWidget *widget);
void st_widget_paint_background (StWidget *widget);
/* debug methods */
char *st_describe_actor (ClutterActor *actor);
void st_set_slow_down_factor (gfloat factor);
@ -169,6 +168,12 @@ void st_widget_set_accessible_name (StWidget *widget,
const gchar *name);
const gchar * st_widget_get_accessible_name (StWidget *widget);
/* utility methods */
void st_get_align_factors (StAlign x_align,
StAlign y_align,
gdouble *x_align_out,
gdouble *y_align_out);
G_END_DECLS
#endif /* __ST_WIDGET_H__ */