static void
st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect)
{
  StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect);
  ClutterOffscreenEffectClass *parent;
  CoglHandle material;

  gdouble value, lower, upper, page_size;
  ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor));
  ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor));
  gboolean h_scroll_visible, v_scroll_visible;

  g_object_get (ST_SCROLL_VIEW (self->actor),
                "hscrollbar-visible", &h_scroll_visible,
                "vscrollbar-visible", &v_scroll_visible,
                NULL);

  if (self->program == COGL_INVALID_HANDLE)
    goto out;

  st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size);

  if (self->offset_top_uniform > -1) {
    if (value > lower + 0.1)
      cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset);
    else
      cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f);
  }

  if (self->offset_bottom_uniform > -1) {
    if (value < upper - page_size - 0.1)
      cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset);
    else
      cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f);
  }

  if (self->tex_uniform > -1)
    cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0);
  if (self->height_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor));
  if (self->width_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor));
  if (self->scrollbar_width_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->scrollbar_width_uniform, v_scroll_visible ? clutter_actor_get_width (vscroll) : 0);
  if (self->scrollbar_height_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->scrollbar_height_uniform, h_scroll_visible ? clutter_actor_get_height (hscroll) : 0);
  if (self->rtl_uniform > -1)
    cogl_program_set_uniform_1i (self->program, self->rtl_uniform, (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL));

  material = clutter_offscreen_effect_get_target (effect);
  cogl_material_set_user_program (material, self->program);

out:
  parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class);
  parent->paint_target (effect);
}
Beispiel #2
0
/**
 * _st_get_align_factors:
 * @widget: an #StWidget
 * @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. If @widget has
 * %ST_TEXT_DIRECTION_RTL, the @x_align_out value will be flipped
 * relative to @x_align.
 */
void
_st_get_align_factors (StWidget *widget,
                       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 (st_widget_get_direction (widget) == ST_TEXT_DIRECTION_RTL)
        *x_align_out = 1.0 - *x_align_out;
    }

  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;
        }
    }
}
Beispiel #3
0
static void
st_scroll_view_allocate (ClutterActor          *actor,
                         const ClutterActorBox *box,
                         ClutterAllocationFlags flags)
{
  ClutterActorBox content_box, child_box;
  ClutterActorClass *parent_parent_class;
  gfloat avail_width, avail_height, sb_width, sb_height;
  gboolean hscrollbar_visible, vscrollbar_visible;

  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
   *
   * We do this because we do not want StBin to allocate the child, as we
   * give it a different allocation later, depending on whether the scrollbars
   * are visible
   */
  parent_parent_class
    = g_type_class_peek_parent (st_scroll_view_parent_class);

  CLUTTER_ACTOR_CLASS (parent_parent_class)->
  allocate (actor, box, flags);

  st_theme_node_get_content_box (theme_node, box, &content_box);

  avail_width = content_box.x2 - content_box.x1;
  avail_height = content_box.y2 - content_box.y1;

  if (clutter_actor_get_request_mode (actor) == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
    {
      sb_width = get_scrollbar_width (ST_SCROLL_VIEW (actor), -1);
      sb_height = get_scrollbar_height (ST_SCROLL_VIEW (actor), sb_width);
    }
  else
    {
      sb_height = get_scrollbar_height (ST_SCROLL_VIEW (actor), -1);
      sb_width = get_scrollbar_width (ST_SCROLL_VIEW (actor), sb_height);
    }

  /* Determine what scrollbars are visible. The basic idea of the
   * handling of an automatic scrollbars is that we start off with the
   * assumption that we don't need any scrollbars, see if that works,
   * and if not add horizontal and vertical scrollbars until we are no
   * longer overflowing.
   */
  if (priv->child)
    {
      gfloat child_min_width;
      gfloat child_min_height;

      clutter_actor_get_preferred_width (priv->child, -1,
                                         &child_min_width, NULL);

      if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
        {
          if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
            {
              /* Pass one, try without a vertical scrollbar */
              clutter_actor_get_preferred_height (priv->child, avail_width, &child_min_height, NULL);
              vscrollbar_visible = child_min_height > avail_height;
              hscrollbar_visible = child_min_width > avail_width - (vscrollbar_visible ? sb_width : 0);
              vscrollbar_visible = child_min_height > avail_height - (hscrollbar_visible ? sb_height : 0);

              /* Pass two - if we needed a vertical scrollbar, get a new preferred height */
              if (vscrollbar_visible)
                {
                  clutter_actor_get_preferred_height (priv->child, MAX (avail_width - sb_width, 0),
                                                      &child_min_height, NULL);
                  hscrollbar_visible = child_min_width > avail_width - sb_width;
                }
            }
          else
            {
              hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;

              /* try without a vertical scrollbar */
              clutter_actor_get_preferred_height (priv->child, avail_width, &child_min_height, NULL);
              vscrollbar_visible = child_min_height > avail_height - (hscrollbar_visible ? sb_height : 0);
            }
        }
      else
        {
          vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;

          if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
            hscrollbar_visible = child_min_width > avail_height - (vscrollbar_visible ? 0 : sb_width);
          else
            hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
        }
    }
  else
    {
      hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
      vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
    }

  /* Whether or not we show the scrollbars, if the scrollbars are visible
   * actors, we need to give them some allocation, so we unconditionally
   * give them the "right" allocation; that might overlap the child when
   * the scrollbars are not visible, but it doesn't matter because we
   * don't include them in pick or paint.
   */

  /* Vertical scrollbar */
  if (CLUTTER_ACTOR_IS_VISIBLE (priv->vscroll))
    {
      if (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL)
        {
          child_box.x1 = content_box.x1;
          child_box.x2 = content_box.x1 + sb_width;
        }
      else
        {
          child_box.x1 = content_box.x2 - sb_width;
          child_box.x2 = content_box.x2;
        }
      child_box.y1 = content_box.y1;
      child_box.y2 = content_box.y2 - (hscrollbar_visible ? sb_height : 0);

      clutter_actor_allocate (priv->vscroll, &child_box, flags);
    }

  /* Horizontal scrollbar */
  if (CLUTTER_ACTOR_IS_VISIBLE (priv->hscroll))
    {
      if (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL)
        {
          child_box.x1 = content_box.x1 + (vscrollbar_visible ? sb_width : 0);
          child_box.x2 = content_box.x2;
        }
      else
        {
          child_box.x1 = content_box.x1;
          child_box.x2 = content_box.x2 - (vscrollbar_visible ? sb_width : 0);
        }
      child_box.y1 = content_box.y2 - sb_height;
      child_box.y2 = content_box.y2;

      clutter_actor_allocate (priv->hscroll, &child_box, flags);
    }

  /* Now fold visibility into the scrollbar sizes to simplify the rest
   * of the computations.
   */
  if (!hscrollbar_visible)
    sb_height = 0;
  if (!vscrollbar_visible)
    sb_width = 0;

  /* Child */
  if (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL)
    {
      child_box.x1 = content_box.x1 + sb_width;
      child_box.x2 = content_box.x2;
    }
  else
    {
      child_box.x1 = content_box.x1;
      child_box.x2 = content_box.x2 - sb_width;
    }
  child_box.y1 = content_box.y1;
  child_box.y2 = content_box.y2 - sb_height;

  if (priv->child)
    clutter_actor_allocate (priv->child, &child_box, flags);

  if (priv->hscrollbar_visible != hscrollbar_visible)
    {
      g_object_freeze_notify (G_OBJECT (actor));
      priv->hscrollbar_visible = hscrollbar_visible;
      g_object_notify (G_OBJECT (actor), "hscrollbar-visible");
      g_object_thaw_notify (G_OBJECT (actor));
    }

  if (priv->vscrollbar_visible != vscrollbar_visible)
    {
      g_object_freeze_notify (G_OBJECT (actor));
      priv->vscrollbar_visible = vscrollbar_visible;
      g_object_notify (G_OBJECT (actor), "vscrollbar-visible");
      g_object_thaw_notify (G_OBJECT (actor));
    }

}
static void
st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect)
{
  StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect);
  ClutterOffscreenEffectClass *parent;
  CoglHandle material;

  gdouble value, lower, upper, page_size;
  ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor));
  ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor));
  gboolean h_scroll_visible, v_scroll_visible;

  ClutterActorBox allocation, content_box, paint_box;

  /*
   * Used to pass the fade area to the shader
   *
   * [0][0] = x1
   * [0][1] = y1
   * [1][0] = x2
   * [1][1] = y2
   *
   */
  float fade_area[2][2];
  ClutterVertex verts[4];

  if (self->program == COGL_INVALID_HANDLE)
    goto out;

  clutter_actor_get_paint_box (self->actor, &paint_box);
  clutter_actor_get_abs_allocation_vertices (self->actor, verts);

  clutter_actor_get_allocation_box (self->actor, &allocation);
  st_theme_node_get_content_box (st_widget_get_theme_node (ST_WIDGET (self->actor)),
                                (const ClutterActorBox *)&allocation, &content_box);

  /*
   * The FBO is based on the paint_volume's size which can be larger then the actual
   * allocation, so we have to account for that when passing the positions
   */
  fade_area[0][0] = content_box.x1 + (verts[0].x - paint_box.x1);
  fade_area[0][1] = content_box.y1 + (verts[0].y - paint_box.y1);
  fade_area[1][0] = content_box.x2 + (verts[3].x - paint_box.x2);
  fade_area[1][1] = content_box.y2 + (verts[3].y - paint_box.y2);

  g_object_get (ST_SCROLL_VIEW (self->actor),
                "hscrollbar-visible", &h_scroll_visible,
                "vscrollbar-visible", &v_scroll_visible,
                NULL);

  if (v_scroll_visible)
    {
      if (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL)
          fade_area[0][0] += clutter_actor_get_width (vscroll);

      fade_area[1][0] -= clutter_actor_get_width (vscroll);
    }

  if (h_scroll_visible)
      fade_area[1][1] -= clutter_actor_get_height (hscroll);

  st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size);

  if (self->offset_top_uniform > -1) {
    if (value > lower + 0.1)
      cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset);
    else
      cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f);
  }

  if (self->offset_bottom_uniform > -1) {
    if (value < upper - page_size - 0.1)
      cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset);
    else
      cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f);
  }

  if (self->tex_uniform > -1)
    cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0);
  if (self->height_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor));
  if (self->width_uniform > -1)
    cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor));
  if (self->fade_area_uniform > -1)
    cogl_program_set_uniform_matrix (self->program, self->fade_area_uniform, 2, 1, FALSE, (const float *)fade_area);

  material = clutter_offscreen_effect_get_target (effect);
  cogl_material_set_user_program (material, self->program);

out:
  parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class);
  parent->paint_target (effect);
}
Beispiel #5
0
static void
st_box_layout_allocate (ClutterActor          *actor,
                        const ClutterActorBox *box,
                        ClutterAllocationFlags flags)
{
  StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (actor)->priv;
  StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
  ClutterActorBox content_box;
  gfloat avail_width, avail_height, min_width, natural_width, min_height, natural_height;
  gfloat position, next_position;
  GList *l, *children;
  gint n_expand_children = 0, i;
  gfloat expand_amount, shrink_amount;
  BoxChildShrink *shrinks = NULL;
  gboolean flip = (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL)
                   && (!priv->is_vertical);

  CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->allocate (actor, box,
                                                              flags);

  children = st_container_get_children_list (ST_CONTAINER (actor));
  if (children == NULL)
    return;

  st_theme_node_get_content_box (theme_node, box, &content_box);

  avail_width  = content_box.x2 - content_box.x1;
  avail_height = content_box.y2 - content_box.y1;

  get_content_preferred_width (ST_BOX_LAYOUT (actor), avail_height,
                               &min_width, &natural_width);
  get_content_preferred_height (ST_BOX_LAYOUT (actor), MAX (avail_width, min_width),
                                &min_height, &natural_height);


  /* update adjustments for scrolling */
  if (priv->vadjustment)
    {
      gdouble prev_value;

      g_object_set (G_OBJECT (priv->vadjustment),
                    "lower", 0.0,
                    "upper", MAX (min_height, avail_height),
                    "page-size", avail_height,
                    "step-increment", avail_height / 6,
                    "page-increment", avail_height - avail_height / 6,
                    NULL);

      prev_value = st_adjustment_get_value (priv->vadjustment);
      st_adjustment_set_value (priv->vadjustment, prev_value);
    }

  if (priv->hadjustment)
    {
      gdouble prev_value;

      g_object_set (G_OBJECT (priv->hadjustment),
                    "lower", 0.0,
                    "upper", MAX (min_width, avail_width),
                    "page-size", avail_width,
                    "step-increment", avail_width / 6,
                    "page-increment", avail_width - avail_width / 6,
                    NULL);

      prev_value = st_adjustment_get_value (priv->hadjustment);
      st_adjustment_set_value (priv->hadjustment, prev_value);
    }

  if (avail_height < min_height)
    {
      avail_height = min_height;
      content_box.y2 = content_box.y1 + avail_height;
    }

  if (avail_width < min_width)
    {
      avail_width = min_width;
      content_box.x2 = content_box.x1 + avail_width;
    }

  if (priv->is_vertical)
    {
      expand_amount = MAX (0, avail_height - natural_height);
      shrink_amount = MAX (0, natural_height - avail_height);
    }
  else
    {
      expand_amount = MAX (0, avail_width - natural_width);
      shrink_amount = MAX (0, natural_width - avail_width);
    }


  if (expand_amount > 0)
    {
      /* count the number of children with expand set to TRUE */
      n_expand_children = 0;
      for (l = children; l; l = l->next)
        {
          ClutterActor *child = l->data;
          gboolean expand;

          if (!CLUTTER_ACTOR_IS_VISIBLE (child) ||
              clutter_actor_get_fixed_position_set (child))
            continue;

          clutter_container_child_get ((ClutterContainer *) actor,
                                       child,
                                       "expand", &expand,
                                       NULL);
          if (expand)
            n_expand_children++;
        }

      if (n_expand_children == 0)
        expand_amount = 0;
    }
  else if (shrink_amount > 0)
    {
      shrinks = compute_shrinks (ST_BOX_LAYOUT (actor),
                                 priv->is_vertical ? avail_width : avail_height,
                                 shrink_amount);
     }

  if (priv->is_vertical)
    position = content_box.y1;
  else if (flip)
    position = content_box.x2;
  else
    position = content_box.x1;

  if (priv->is_pack_start)
    {
      l = g_list_last (children);
      i = g_list_length (children);
    }
  else
    {
      l = children;
      i = 0;
    }
    
  gboolean firstchild = TRUE;
  gfloat init_padding = (avail_width/2) - (natural_width/2);
  while (l)
    {
      ClutterActor *child = (ClutterActor*) l->data;
      ClutterActorBox child_box;
      gfloat child_min, child_nat, child_allocated;
      gboolean xfill, yfill, expand, fixed;
      StAlign xalign, yalign;

      if (!CLUTTER_ACTOR_IS_VISIBLE (child))
        goto next_child;

      fixed = clutter_actor_get_fixed_position_set (child);
      if (fixed)
        {
          clutter_actor_allocate_preferred_size (child, flags);
          goto next_child;
        }

      clutter_container_child_get ((ClutterContainer*) actor, child,
                                   "x-fill", &xfill,
                                   "y-fill", &yfill,
                                   "x-align", &xalign,
                                   "y-align", &yalign,
                                   "expand", &expand,
                                   NULL);

      if (priv->is_vertical)
        {
          _st_actor_get_preferred_height (child, avail_width, xfill,
                                          &child_min, &child_nat);
        }
      else
        {
          _st_actor_get_preferred_width (child, avail_height, yfill,
                                         &child_min, &child_nat);
        }

      child_allocated = child_nat;
      if (expand_amount > 0 && expand)
        child_allocated +=  expand_amount / n_expand_children;
      else if (shrink_amount > 0)
        child_allocated -= shrinks[i].shrink_amount;

      if (flip) {
        next_position = position - child_allocated;
        if (xalign == ST_ALIGN_CENTER_SPECIAL && next_position < content_box.x1)
          next_position = content_box.x1;
      }
      else {
        next_position = position + child_allocated;
        if (xalign == ST_ALIGN_CENTER_SPECIAL && next_position > content_box.x2)
          next_position = content_box.x2;
      }

      if (priv->is_vertical)
        {
          child_box.y1 = (int)(0.5 + position);
          child_box.y2 = (int)(0.5 + next_position);
          child_box.x1 = content_box.x1;
          child_box.x2 = content_box.x2;

          _st_allocate_fill (ST_WIDGET (actor), child, &child_box,
                             xalign, yalign, xfill, yfill);
          clutter_actor_allocate (child, &child_box, flags);

        }
      else
        {
          if (flip)
            {
              if (firstchild && xalign == ST_ALIGN_CENTER_SPECIAL)
                {
                  position -= init_padding;
                  next_position = position - child_allocated;
                  firstchild = FALSE;
                }
                if (xalign == ST_ALIGN_CENTER_SPECIAL && position > content_box.x2) {
                  position = content_box.x2;
                }
              child_box.x1 = (int)(0.5 + next_position);
              child_box.x2 = (int)(0.5 + position);
            }
          else
            {
              if (firstchild && xalign == ST_ALIGN_CENTER_SPECIAL)
                {
                  position += init_padding;
                  if (position < content_box.x1) {
                    position = content_box.x1;
                  }
                  next_position = position + child_allocated;
                  firstchild = FALSE;
                }
              if (xalign == ST_ALIGN_CENTER_SPECIAL && position < content_box.x1) {
                    position = content_box.x1;
                  }
              child_box.x1 = (int)(0.5 + position);
              child_box.x2 = (int)(0.5 + next_position);
            }

          child_box.y1 = content_box.y1;
          child_box.y2 = content_box.y2;

          _st_allocate_fill (ST_WIDGET (actor), child, &child_box,
                             xalign, yalign, xfill, yfill);
          clutter_actor_allocate (child, &child_box, flags);
        }

      if (flip)
        position = next_position - priv->spacing;
      else
        position = next_position + priv->spacing;

    next_child:
      if (priv->is_pack_start)
        {
          l = l->prev;
          i--;
        }
      else
        {
          l = l->next;
          i++;
        }
    }

  if (shrinks)
    g_free (shrinks);
}
Beispiel #6
0
static void
st_table_preferred_allocate (ClutterActor          *self,
                             const ClutterActorBox *content_box,
                             gboolean               flags)
{
  GList *list, *children;
  gint row_spacing, col_spacing;
  gint i;
  StTable *table;
  StTablePrivate *priv;
  gboolean ltr;
  DimensionData *rows, *columns;

  table = ST_TABLE (self);
  priv = ST_TABLE (self)->priv;

  col_spacing = (priv->col_spacing);
  row_spacing = (priv->row_spacing);

  st_table_calculate_dimensions (table,
                                 content_box->x2 - content_box->x1,
                                 content_box->y2 - content_box->y1);

  ltr = (st_widget_get_direction (ST_WIDGET (self)) == ST_TEXT_DIRECTION_LTR);
  rows = &g_array_index (priv->rows, DimensionData, 0);
  columns = &g_array_index (priv->columns, DimensionData, 0);

  children = st_container_get_children_list (ST_CONTAINER (self));
  for (list = children; list; list = list->next)
    {
      gint row, col, row_span, col_span;
      gint col_width, row_height;
      StTableChild *meta;
      ClutterActor *child;
      ClutterActorBox childbox;
      gint child_x, child_y;
      StAlign x_align, y_align;
      gboolean x_fill, y_fill;

      child = CLUTTER_ACTOR (list->data);

      meta = (StTableChild *) clutter_container_get_child_meta (CLUTTER_CONTAINER (self), child);

      if (!meta->allocate_hidden && !CLUTTER_ACTOR_IS_VISIBLE (child))
        continue;

      /* get child properties */
      col = meta->col;
      row = meta->row;
      row_span = meta->row_span;
      col_span = meta->col_span;
      x_align = meta->x_align;
      y_align = meta->y_align;
      x_fill = meta->x_fill;
      y_fill = meta->y_fill;

      /* initialise the width and height */
      col_width = columns[col].final_size;
      row_height = rows[row].final_size;

      /* Add the widths of the spanned columns:
       *
       * First check that we have a non-zero span. Then we loop over each of
       * the columns that we're spanning but we stop short if we go past the
       * number of columns in the table. This is necessary to avoid accessing
       * uninitialised memory. We add the spacing in here too since we only
       * want to add as much spacing as times we successfully span.
       */
      if (col + col_span > priv->n_cols)
        g_warning ("StTable: the child at %d,%d's col-span, %d, exceeds number of columns, %d",
                   col, row, col_span, priv->n_cols);
      if (row + row_span > priv->n_rows)
        g_warning ("StTable: the child at %d,%d's row-span, %d, exceeds number of rows, %d",
                   col, row, row_span, priv->n_rows);

      if (col_span > 1)
        {
          for (i = col + 1; i < col + col_span && i < priv->n_cols; i++)
            {
              col_width += columns[i].final_size;
              col_width += col_spacing;
            }
        }

      /* add the height of the spanned rows */
      if (row_span > 1)
        {
          for (i = row + 1; i < row + row_span && i < priv->n_rows; i++)
            {
              row_height += rows[i].final_size;
              row_height += row_spacing;
            }
        }

      /* calculate child x */
      if (ltr)
        {
          child_x = (int) content_box->x1
                    + col_spacing * col;
          for (i = 0; i < col; i++)
            child_x += columns[i].final_size;
        }
      else
        {
          child_x = (int) content_box->x2
                    - col_spacing * col;
          for (i = 0; i < col; i++)
            child_x -= columns[i].final_size;
        }

      /* calculate child y */
      child_y = (int) content_box->y1
                + row_spacing * row;
      for (i = 0; i < row; i++)
        child_y += rows[i].final_size;

      /* set up childbox */
      if (ltr)
        {
          childbox.x1 = (float) child_x;
          childbox.x2 = (float) MAX (0, child_x + col_width);
        }
      else
        {
          childbox.x2 = (float) child_x;
          childbox.x1 = (float) MAX (0, child_x - col_width);
        }

      childbox.y1 = (float) child_y;
      childbox.y2 = (float) MAX (0, child_y + row_height);


      _st_allocate_fill (ST_WIDGET (self), child, &childbox,
                         x_align, y_align, x_fill, y_fill);

      clutter_actor_allocate (child, &childbox, flags);
    }
}
Beispiel #7
0
static void
st_table_homogeneous_allocate (ClutterActor          *self,
                               const ClutterActorBox *content_box,
                               gboolean               flags)
{
  GList *list, *children;
  gfloat col_width, row_height;
  gint row_spacing, col_spacing;
  StTablePrivate *priv = ST_TABLE (self)->priv;
  gboolean ltr = st_widget_get_direction (ST_WIDGET (self)) == ST_TEXT_DIRECTION_LTR;

  col_spacing = priv->col_spacing;
  row_spacing = priv->row_spacing;

  col_width = (int) ((content_box->x2 - content_box->x1
                      - (col_spacing * (priv->n_cols - 1)))
                     / priv->n_cols + 0.5);
  row_height = (int) ((content_box->y2 - content_box->y1
                      - (row_spacing * (priv->n_rows - 1)))
                      / priv->n_rows + 0.5);

  children = st_container_get_children_list (ST_CONTAINER (self));
  for (list = children; list; list = list->next)
    {
      gint row, col, row_span, col_span;
      StTableChild *meta;
      ClutterActor *child;
      ClutterActorBox childbox;
      StAlign x_align, y_align;
      gboolean x_fill, y_fill;

      child = CLUTTER_ACTOR (list->data);

      meta = (StTableChild *) clutter_container_get_child_meta (CLUTTER_CONTAINER (self), child);

      if (!meta->allocate_hidden && !CLUTTER_ACTOR_IS_VISIBLE (child))
        continue;

      /* get child properties */
      col = meta->col;
      row = meta->row;
      row_span = meta->row_span;
      col_span = meta->col_span;
      x_align = meta->x_align;
      y_align = meta->y_align;
      x_fill = meta->x_fill;
      y_fill = meta->y_fill;

      if (ltr)
        {
          childbox.x1 = content_box->x1 + (col_width + col_spacing) * col;
          childbox.x2 = childbox.x1 + (col_width * col_span) + (col_spacing * (col_span - 1));
        }
      else
        {
          childbox.x2 = content_box->x2 - (col_width + col_spacing) * col;
          childbox.x1 = childbox.x2 - (col_width * col_span) - (col_spacing * (col_span - 1));
        }

      childbox.y1 = content_box->y1 + (row_height + row_spacing) * row;
      childbox.y2 = childbox.y1 + (row_height * row_span) + (row_spacing * (row_span - 1));

      _st_allocate_fill (ST_WIDGET (self), child, &childbox,
                         x_align, y_align, x_fill, y_fill);

      clutter_actor_allocate (child, &childbox, flags);
    }

}