Centralize computations of border and padding into StThemeNode

Rather than repeating the computation of borders in many different
widget subclasses, add helper functions:

 st_theme_node_adjust_for_height()
 st_theme_node_adjust_preferred_width()
 st_theme_node_adjust_for_width()
 st_theme_node_adjust_preferred_height()
 st_theme_node_get_content_box()

That are used in get_preferred_width()/get_preferred_height() and
allocate() methods to consistently apply the necessary adjustments.
This allows removing the StPadding type.

Queueing a relayout when the borders/padding change is moved from
st_widget_real_style_changed() to the invoking code to allow access
to the old StThemeNode for comparison. (Should this be added as
a parameter to the signal?)

Borders are included in the geometry adjustments, but borders
are not yet drawn.

https://bugzilla.gnome.org/show_bug.cgi?id=595993
This commit is contained in:
Owen W. Taylor
2009-09-20 13:41:13 -04:00
parent 8c72623da3
commit 076e902b2c
12 changed files with 446 additions and 387 deletions

View File

@ -269,71 +269,65 @@ st_scroll_bar_allocate (ClutterActor *actor,
ClutterAllocationFlags flags)
{
StScrollBarPrivate *priv = ST_SCROLL_BAR (actor)->priv;
StPadding padding;
ClutterActorBox bw_box, fw_box, trough_box;
gfloat x, y, width, height, stepper_size;
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
ClutterActorBox content_box, bw_box, fw_box, trough_box;
gfloat stepper_size;
/* Chain up */
CLUTTER_ACTOR_CLASS (st_scroll_bar_parent_class)->
allocate (actor, box, flags);
st_widget_get_padding (ST_WIDGET (actor), &padding);
/* calculate the child area */
x = padding.left;
y = padding.top;
width = (box->x2 - box->x1) - padding.left - padding.right;
height = (box->y2 - box->y1) - padding.top - padding.bottom;
st_theme_node_get_content_box (theme_node, box, &content_box);
if (priv->vertical)
{
stepper_size = width;
stepper_size = content_box.x2 - content_box.x1;
/* Backward stepper */
bw_box.x1 = x;
bw_box.y1 = y;
bw_box.x2 = bw_box.x1 + stepper_size;
bw_box.x1 = content_box.x1;
bw_box.y1 = content_box.y1;
bw_box.x2 = content_box.x2;
bw_box.y2 = bw_box.y1 + stepper_size;
clutter_actor_allocate (priv->bw_stepper, &bw_box, flags);
/* Forward stepper */
fw_box.x1 = x;
fw_box.y1 = y + height - stepper_size;
fw_box.x2 = fw_box.x1 + stepper_size;
fw_box.y2 = fw_box.y1 + stepper_size;
fw_box.x1 = content_box.x1;
fw_box.y1 = content_box.y2 - stepper_size;
fw_box.x2 = content_box.x2;
fw_box.y2 = content_box.y2;
clutter_actor_allocate (priv->fw_stepper, &fw_box, flags);
/* Trough */
trough_box.x1 = x;
trough_box.y1 = y + stepper_size;
trough_box.x2 = x + width;
trough_box.y2 = y + height - stepper_size;
trough_box.x1 = content_box.x1;
trough_box.y1 = content_box.y1 + stepper_size;
trough_box.x2 = content_box.x2;
trough_box.y2 = content_box.y2 - stepper_size;
clutter_actor_allocate (priv->trough, &trough_box, flags);
}
else
{
stepper_size = height;
stepper_size = content_box.y2 - content_box.y1;
/* Backward stepper */
bw_box.x1 = x;
bw_box.y1 = y;
bw_box.x1 = content_box.x1;
bw_box.y1 = content_box.y1;
bw_box.x2 = bw_box.x1 + stepper_size;
bw_box.y2 = bw_box.y1 + stepper_size;
bw_box.y2 = content_box.y2;
clutter_actor_allocate (priv->bw_stepper, &bw_box, flags);
/* Forward stepper */
fw_box.x1 = x + width - stepper_size;
fw_box.y1 = y;
fw_box.x2 = fw_box.x1 + stepper_size;
fw_box.y2 = fw_box.y1 + stepper_size;
fw_box.x1 = content_box.x2 - stepper_size;
fw_box.y1 = content_box.y1;
fw_box.x2 = content_box.x2;
fw_box.y2 = content_box.y2;
clutter_actor_allocate (priv->fw_stepper, &fw_box, flags);
/* Trough */
trough_box.x1 = x + stepper_size;
trough_box.y1 = y;
trough_box.x2 = x + width - stepper_size;
trough_box.y2 = y + height;
trough_box.x1 = content_box.x1 + stepper_size;
trough_box.y1 = content_box.y1;
trough_box.x2 = content_box.x2 - stepper_size;
trough_box.y2 = content_box.y2;
clutter_actor_allocate (priv->trough, &trough_box, flags);
}
@ -371,27 +365,27 @@ st_scroll_bar_allocate (ClutterActor *actor,
if (priv->vertical)
{
avail_size = height - stepper_size * 2;
avail_size = content_box.y2 - content_box.y1 - stepper_size * 2;
handle_size = increment * avail_size;
handle_size = CLAMP (handle_size, min_size, max_size);
handle_box.x1 = x;
handle_box.x1 = content_box.x1;
handle_box.y1 = bw_box.y2 + position * (avail_size - handle_size);
handle_box.x2 = handle_box.x1 + width;
handle_box.x2 = content_box.x2;
handle_box.y2 = handle_box.y1 + handle_size;
}
else
{
avail_size = width - stepper_size * 2;
avail_size = content_box.x2 - content_box.x1 - stepper_size * 2;
handle_size = increment * avail_size;
handle_size = CLAMP (handle_size, min_size, max_size);
handle_box.x1 = bw_box.x2 + position * (avail_size - handle_size);
handle_box.y1 = y;
handle_box.y1 = content_box.y1;
handle_box.x2 = handle_box.x1 + handle_size;
handle_box.y2 = handle_box.y1 + height;
handle_box.y2 = content_box.y2;
}
/* snap to pixel */