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:
@ -207,14 +207,13 @@ st_scroll_view_get_preferred_width (ClutterActor *actor,
|
||||
gfloat *min_width_p,
|
||||
gfloat *natural_width_p)
|
||||
{
|
||||
StPadding padding;
|
||||
|
||||
StScrollViewPrivate *priv = ST_SCROLL_VIEW (actor)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
||||
|
||||
if (!priv->child)
|
||||
return;
|
||||
|
||||
st_widget_get_padding (ST_WIDGET (actor), &padding);
|
||||
st_theme_node_adjust_for_height (theme_node, &for_height);
|
||||
|
||||
/* Our natural width is the natural width of the child */
|
||||
clutter_actor_get_preferred_width (priv->child,
|
||||
@ -234,12 +233,10 @@ st_scroll_view_get_preferred_width (ClutterActor *actor,
|
||||
*natural_width_p += get_scrollbar_width (ST_SCROLL_VIEW (actor));
|
||||
}
|
||||
|
||||
/* Add space for padding */
|
||||
if (min_width_p)
|
||||
*min_width_p = padding.left + padding.right;
|
||||
*min_width_p = 0;
|
||||
|
||||
if (natural_width_p)
|
||||
*natural_width_p += padding.left + padding.right;
|
||||
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -248,14 +245,13 @@ st_scroll_view_get_preferred_height (ClutterActor *actor,
|
||||
gfloat *min_height_p,
|
||||
gfloat *natural_height_p)
|
||||
{
|
||||
StPadding padding;
|
||||
|
||||
StScrollViewPrivate *priv = ST_SCROLL_VIEW (actor)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
||||
|
||||
if (!priv->child)
|
||||
return;
|
||||
|
||||
st_widget_get_padding (ST_WIDGET (actor), &padding);
|
||||
st_theme_node_adjust_for_width (theme_node, &for_width);
|
||||
|
||||
/* Our natural height is the natural height of the child */
|
||||
clutter_actor_get_preferred_height (priv->child,
|
||||
@ -275,12 +271,10 @@ st_scroll_view_get_preferred_height (ClutterActor *actor,
|
||||
*natural_height_p += get_scrollbar_height (ST_SCROLL_VIEW (actor));
|
||||
}
|
||||
|
||||
/* Add space for padding */
|
||||
if (min_height_p)
|
||||
*min_height_p = padding.top + padding.bottom;
|
||||
*min_height_p = 0;
|
||||
|
||||
if (natural_height_p)
|
||||
*natural_height_p += padding.top + padding.bottom;
|
||||
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -288,12 +282,12 @@ st_scroll_view_allocate (ClutterActor *actor,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
StPadding padding;
|
||||
ClutterActorBox child_box;
|
||||
ClutterActorBox content_box, child_box;
|
||||
ClutterActorClass *parent_parent_class;
|
||||
gfloat avail_width, avail_height, sb_width, sb_height;
|
||||
|
||||
StScrollViewPrivate *priv = ST_SCROLL_VIEW (actor)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
||||
|
||||
/* Chain up to the parent's parent class
|
||||
*
|
||||
@ -308,10 +302,10 @@ st_scroll_view_allocate (ClutterActor *actor,
|
||||
allocate (actor, box, flags);
|
||||
|
||||
|
||||
st_widget_get_padding (ST_WIDGET (actor), &padding);
|
||||
st_theme_node_get_content_box (theme_node, box, &content_box);
|
||||
|
||||
avail_width = (box->x2 - box->x1) - padding.left - padding.right;
|
||||
avail_height = (box->y2 - box->y1) - padding.top - padding.bottom;
|
||||
avail_width = content_box.x2 - content_box.x1;
|
||||
avail_height = content_box.y2 - content_box.y1;
|
||||
|
||||
sb_width = get_scrollbar_width (ST_SCROLL_VIEW (actor));
|
||||
sb_height = get_scrollbar_width (ST_SCROLL_VIEW (actor));
|
||||
@ -325,10 +319,10 @@ st_scroll_view_allocate (ClutterActor *actor,
|
||||
/* Vertical scrollbar */
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (priv->vscroll))
|
||||
{
|
||||
child_box.x1 = avail_width - sb_width;
|
||||
child_box.y1 = padding.top;
|
||||
child_box.x2 = avail_width;
|
||||
child_box.y2 = child_box.y1 + avail_height - sb_height;
|
||||
child_box.x1 = content_box.x2 - sb_width;
|
||||
child_box.y1 = content_box.y1;
|
||||
child_box.x2 = content_box.x2;
|
||||
child_box.y2 = content_box.y2 - sb_height;
|
||||
|
||||
clutter_actor_allocate (priv->vscroll, &child_box, flags);
|
||||
}
|
||||
@ -336,20 +330,20 @@ st_scroll_view_allocate (ClutterActor *actor,
|
||||
/* Horizontal scrollbar */
|
||||
if (CLUTTER_ACTOR_IS_VISIBLE (priv->hscroll))
|
||||
{
|
||||
child_box.x1 = padding.left;
|
||||
child_box.x2 = child_box.x1 + avail_width - sb_width;
|
||||
child_box.y1 = avail_height - sb_height;
|
||||
child_box.y2 = avail_height;
|
||||
child_box.x1 = content_box.x1;
|
||||
child_box.y1 = content_box.y2 - sb_height;
|
||||
child_box.x2 = content_box.x2 - sb_width;
|
||||
child_box.y2 = content_box.y2;
|
||||
|
||||
clutter_actor_allocate (priv->hscroll, &child_box, flags);
|
||||
}
|
||||
|
||||
|
||||
/* Child */
|
||||
child_box.x1 = padding.left;
|
||||
child_box.x2 = avail_width - sb_width;
|
||||
child_box.y1 = padding.top;
|
||||
child_box.y2 = avail_height - sb_height;
|
||||
child_box.x1 = content_box.x1;
|
||||
child_box.y1 = content_box.y1;
|
||||
child_box.x2 = content_box.x2 - sb_width;
|
||||
child_box.y2 = content_box.y2 - sb_height;
|
||||
|
||||
if (priv->child)
|
||||
clutter_actor_allocate (priv->child, &child_box, flags);
|
||||
|
Reference in New Issue
Block a user