Re: gtk box and flow layout



Paul Pogonyshev wrote:
daa84 wrote:
daa84 ?????:
  > I start to write my widget with FlowLayout functionality (with
row-breaking). And find next problem:

gtk_widget_size_request function obtains the preferred size of a widget
gtk_widget_size_allocate assign a size and position to child widgets

When I fill GtkRequisition structure I send my preferred size of a widget (width and height). But in size_allocate function I get new width that smaller then first width value. Than it is need to increase size. How can I do it? Initiate call size_request function another one time or change GtkAllocation values.

This is only my thoughts, I don't test this in code for now.

Initiate new resizing session and be sure to request smaller size next time
(so that you are not allocated this size again.)  GTK+ is not really suited
for full-scaled negotiation of size.

Adjusting allocation values will not achieve anything since the container
(the one which your flow-layout one is in) will not care.

I solve this problem using gtk_widget_set_size_request function in allocation function.

This is good as long as the number and size requests of the widgets your
container contains don't change, which is hard to say in advance, especially
the latter part.  Less importantly, this will break if theme/font/etc. is
changed in runtime.

Paul



I write next code for size_allocate function and all work fine (window resizing processed normally):



    width = 0;
    rows_count = 1;
    row_height = 1;

for (cur = g_list_first (priv->buttons_list); cur != NULL; cur = g_list_next (cur))
    {
        child = GTK_WIDGET (cur->data);

        if (GTK_WIDGET_VISIBLE (child))
        {
            gtk_widget_size_request (child, &child_req);

            width += child_req.width;

            if (width > allocation->width &&
                    width != child_req.width)
            {
                rows_count++;
                width = child_req.width;
            }

            row_height = MAX (row_height, child_req.height);
        }
    }

    if (priv->rows_count != rows_count ||
            priv->row_height != row_height)
    {
        priv->rows_count = rows_count;
        priv->row_height = row_height;
        gtk_widget_set_size_request (widget, -1, row_height * rows_count);
    }

    width = 0;
    row = 1;
for (cur = g_list_first (priv->buttons_list); cur != NULL; cur = g_list_next (cur))
    {
        child = GTK_WIDGET (cur->data);

        if (GTK_WIDGET_VISIBLE (child))
        {
            gtk_widget_get_child_requisition (child, &child_req);

            width += child_req.width;

            if (width > allocation->width &&
                    width != child_req.width) // this need when width is vary small
            {
                row++;
                width = child_req.width;
            }

            child_alloc.width = child_req.width;
            child_alloc.height = row_height;
            child_alloc.x = allocation->x + width - child_req.width;
            child_alloc.y = allocation->y + row_height * (row - 1);
            gtk_widget_size_allocate (child, &child_alloc);
        }
    }


And no implementation for size_request function.

I don't fully understand what gtk_widget_set_size_request doing, I find this solution in gimp sources.

Thanks!

Sorry for my bad English.

--
Andrey Dubravin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]