Blame clients/tui/newt/nmt-newt-grid.c

Packit Service 87a54e
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2013 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * SECTION:nmt-newt-grid
Packit 5756e2
 * @short_description: Grid container
Packit 5756e2
 *
Packit 5756e2
 * #NmtNewtGrid is the most general-purpose container widget in NmtNewt.
Packit 5756e2
 *
Packit 5756e2
 * An #NmtNewtGrid consists of a number of rows and columns. There is
Packit 5756e2
 * no pre-established maximum row or columns. Rather, rows and columns
Packit 5756e2
 * exist if and only if there are widgets in them.
Packit 5756e2
 *
Packit 5756e2
 * The width of each column is the width of the widest widget in that
Packit 5756e2
 * column, and the height of each row is the height of the tallest
Packit 5756e2
 * widget in that row. Empty rows and empty columns take up no space,
Packit 5756e2
 * so a grid with a single widget at 0,0 would look exactly the same
Packit 5756e2
 * if the widget was at 5,10 instead.
Packit 5756e2
 *
Packit 5756e2
 * If a widget's cell ends up being larger than the widget's requested
Packit 5756e2
 * size, then by default the widget will be centered in its cell.
Packit 5756e2
 * However, this can be modified by changing its #NmtNewtGridFlags.
Packit 5756e2
 * FIXME: the FILL/ANCHOR flags can be implemented in #NmtNewtWidget
Packit 5756e2
 * and so should move there. Less clear about the EXPAND flags, which
Packit 5756e2
 * must be implemented by the container...
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nmt-newt-grid.h"
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_TYPE(NmtNewtGrid, nmt_newt_grid, NMT_TYPE_NEWT_CONTAINER)
Packit 5756e2
Packit Service a1bd4f
#define NMT_NEWT_GRID_GET_PRIVATE(o) \
Packit Service a1bd4f
    (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_GRID, NmtNewtGridPrivate))
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NmtNewtWidget *  widget;
Packit Service a1bd4f
    int              x, y;
Packit Service a1bd4f
    NmtNewtGridFlags flags;
Packit Service a1bd4f
    int              req_height, req_width;
Packit 5756e2
} NmtNewtGridChild;
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    GArray *  children;
Packit Service a1bd4f
    int       max_x, max_y;
Packit Service a1bd4f
    int *     row_heights, *col_widths;
Packit Service a1bd4f
    gboolean *expand_rows, *expand_cols;
Packit Service a1bd4f
    int       n_expand_rows, n_expand_cols;
Packit Service a1bd4f
    int       req_height, req_width;
Packit 5756e2
} NmtNewtGridPrivate;
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_grid_new:
Packit 5756e2
 *
Packit 5756e2
 * Creates a new #NmtNewtGrid
Packit 5756e2
 *
Packit 5756e2
 * Returns: a new #NmtNewtGrid
Packit 5756e2
 */
Packit 5756e2
NmtNewtWidget *
Packit Service a1bd4f
nmt_newt_grid_new(void)
Packit 5756e2
{
Packit Service a1bd4f
    return g_object_new(NMT_TYPE_NEWT_GRID, NULL);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_init(NmtNewtGrid *grid)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit 5756e2
Packit Service a1bd4f
    priv->children = g_array_new(FALSE, FALSE, sizeof(NmtNewtGridChild));
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_finalize(GObject *object)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(object);
Packit 5756e2
Packit Service a1bd4f
    g_array_unref(priv->children);
Packit Service a1bd4f
    nm_clear_g_free(&priv->row_heights);
Packit Service a1bd4f
    nm_clear_g_free(&priv->col_widths);
Packit Service a1bd4f
    nm_clear_g_free(&priv->expand_rows);
Packit Service a1bd4f
    nm_clear_g_free(&priv->expand_cols);
Packit 5756e2
Packit Service a1bd4f
    G_OBJECT_CLASS(nmt_newt_grid_parent_class)->finalize(object);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static int
Packit Service a1bd4f
child_sort_func(gconstpointer a, gconstpointer b)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridChild *child_a = (NmtNewtGridChild *) a;
Packit Service a1bd4f
    NmtNewtGridChild *child_b = (NmtNewtGridChild *) b;
Packit 5756e2
Packit Service a1bd4f
    if (child_a->y != child_b->y)
Packit Service a1bd4f
        return child_a->y - child_b->y;
Packit Service a1bd4f
    else
Packit Service a1bd4f
        return child_a->x - child_b->x;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static newtComponent *
Packit Service a1bd4f
nmt_newt_grid_get_components(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(widget);
Packit Service a1bd4f
    NmtNewtGridChild *  children;
Packit Service a1bd4f
    GPtrArray *         cos;
Packit Service a1bd4f
    newtComponent *     child_cos;
Packit Service a1bd4f
    int                 i, c;
Packit 5756e2
Packit Service a1bd4f
    g_array_sort(priv->children, child_sort_func);
Packit Service a1bd4f
    children = (NmtNewtGridChild *) priv->children->data;
Packit 5756e2
Packit Service a1bd4f
    cos = g_ptr_array_new();
Packit 5756e2
Packit Service a1bd4f
    for (i = 0; i < priv->children->len; i++) {
Packit Service a1bd4f
        if (!nmt_newt_widget_get_visible(children[i].widget))
Packit Service a1bd4f
            continue;
Packit 5756e2
Packit Service a1bd4f
        child_cos = nmt_newt_widget_get_components(children[i].widget);
Packit Service a1bd4f
        for (c = 0; child_cos[c]; c++)
Packit Service a1bd4f
            g_ptr_array_add(cos, child_cos[c]);
Packit Service a1bd4f
        g_free(child_cos);
Packit Service a1bd4f
    }
Packit Service a1bd4f
    g_ptr_array_add(cos, NULL);
Packit 5756e2
Packit Service a1bd4f
    return (newtComponent *) g_ptr_array_free(cos, FALSE);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_size_request(NmtNewtWidget *widget, int *width, int *height)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGrid *       grid     = NMT_NEWT_GRID(widget);
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data;
Packit Service a1bd4f
    int                 row, col, i;
Packit Service a1bd4f
Packit Service a1bd4f
    g_free(priv->row_heights);
Packit Service a1bd4f
    g_free(priv->col_widths);
Packit Service a1bd4f
    g_free(priv->expand_rows);
Packit Service a1bd4f
    g_free(priv->expand_cols);
Packit Service a1bd4f
Packit Service a1bd4f
    priv->row_heights   = g_new0(int, priv->max_y + 1);
Packit Service a1bd4f
    priv->col_widths    = g_new0(int, priv->max_x + 1);
Packit Service a1bd4f
    priv->expand_rows   = g_new0(gboolean, priv->max_y + 1);
Packit Service a1bd4f
    priv->expand_cols   = g_new0(gboolean, priv->max_x + 1);
Packit Service a1bd4f
    priv->n_expand_rows = priv->n_expand_cols = 0;
Packit Service a1bd4f
Packit Service a1bd4f
    for (row = 0; row < priv->max_y + 1; row++) {
Packit Service a1bd4f
        for (col = 0; col < priv->max_x + 1; col++) {
Packit Service a1bd4f
            for (i = 0; i < priv->children->len; i++) {
Packit Service a1bd4f
                if (children[i].x != col || children[i].y != row)
Packit Service a1bd4f
                    continue;
Packit Service a1bd4f
                if (!nmt_newt_widget_get_visible(children[i].widget))
Packit Service a1bd4f
                    continue;
Packit Service a1bd4f
Packit Service a1bd4f
                nmt_newt_widget_size_request(children[i].widget,
Packit Service a1bd4f
                                             &children[i].req_width,
Packit Service a1bd4f
                                             &children[i].req_height);
Packit Service a1bd4f
                if (children[i].req_height > priv->row_heights[row])
Packit Service a1bd4f
                    priv->row_heights[row] = children[i].req_height;
Packit Service a1bd4f
                if (children[i].req_width > priv->col_widths[col])
Packit Service a1bd4f
                    priv->col_widths[col] = children[i].req_width;
Packit Service a1bd4f
Packit Service a1bd4f
                if ((children[i].flags & NMT_NEWT_GRID_EXPAND_X)
Packit Service a1bd4f
                    && !priv->expand_cols[children[i].x]) {
Packit Service a1bd4f
                    priv->expand_cols[children[i].x] = TRUE;
Packit Service a1bd4f
                    priv->n_expand_cols++;
Packit Service a1bd4f
                }
Packit Service a1bd4f
                if ((children[i].flags & NMT_NEWT_GRID_EXPAND_Y)
Packit Service a1bd4f
                    && !priv->expand_rows[children[i].y]) {
Packit Service a1bd4f
                    priv->expand_rows[children[i].y] = TRUE;
Packit Service a1bd4f
                    priv->n_expand_rows++;
Packit Service a1bd4f
                }
Packit Service a1bd4f
            }
Packit Service a1bd4f
        }
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    priv->req_height = priv->req_width = 0;
Packit Service a1bd4f
    for (row = 0; row < priv->max_y + 1; row++)
Packit Service a1bd4f
        priv->req_height += priv->row_heights[row];
Packit Service a1bd4f
    for (col = 0; col < priv->max_x + 1; col++)
Packit Service a1bd4f
        priv->req_width += priv->col_widths[col];
Packit Service a1bd4f
Packit Service a1bd4f
    *height = priv->req_height;
Packit Service a1bd4f
    *width  = priv->req_width;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(widget);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data, *child;
Packit Service a1bd4f
    int                 i, row, col;
Packit Service a1bd4f
    int                 child_x, child_y, child_width, child_height;
Packit Service a1bd4f
    int                 extra, extra_all, extra_some;
Packit Service a1bd4f
Packit Service a1bd4f
    extra = width - priv->req_width;
Packit Service a1bd4f
    if (extra > 0 && priv->n_expand_cols) {
Packit Service a1bd4f
        extra_all  = extra / priv->n_expand_cols;
Packit Service a1bd4f
        extra_some = extra % priv->n_expand_cols;
Packit Service a1bd4f
Packit Service a1bd4f
        for (col = 0; col < priv->max_x + 1; col++) {
Packit Service a1bd4f
            if (!priv->expand_cols[col])
Packit Service a1bd4f
                continue;
Packit Service a1bd4f
            priv->col_widths[col] += extra_all;
Packit Service a1bd4f
            if (extra_some) {
Packit Service a1bd4f
                priv->col_widths[col]++;
Packit Service a1bd4f
                extra_some--;
Packit Service a1bd4f
            }
Packit Service a1bd4f
        }
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    extra = height - priv->req_height;
Packit Service a1bd4f
    if (extra > 0 && priv->n_expand_rows) {
Packit Service a1bd4f
        extra_all  = extra / priv->n_expand_rows;
Packit Service a1bd4f
        extra_some = extra % priv->n_expand_rows;
Packit Service a1bd4f
Packit Service a1bd4f
        for (row = 0; row < priv->max_y + 1; row++) {
Packit Service a1bd4f
            if (!priv->expand_rows[row])
Packit Service a1bd4f
                continue;
Packit Service a1bd4f
            priv->row_heights[row] += extra_all;
Packit Service a1bd4f
            if (extra_some) {
Packit Service a1bd4f
                priv->row_heights[row]++;
Packit Service a1bd4f
                extra_some--;
Packit Service a1bd4f
            }
Packit Service a1bd4f
        }
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    for (i = 0; i < priv->children->len; i++) {
Packit Service a1bd4f
        child = &children[i];
Packit Service a1bd4f
        if (!nmt_newt_widget_get_visible(child->widget))
Packit Service a1bd4f
            continue;
Packit Service a1bd4f
Packit Service a1bd4f
        child_x = x;
Packit Service a1bd4f
        for (col = 0; col < child->x; col++)
Packit Service a1bd4f
            child_x += priv->col_widths[col];
Packit Service a1bd4f
Packit Service a1bd4f
        if ((child->flags & NMT_NEWT_GRID_FILL_X) == NMT_NEWT_GRID_FILL_X) {
Packit Service a1bd4f
            child_width = priv->col_widths[child->x];
Packit Service a1bd4f
        } else {
Packit Service a1bd4f
            child_width = child->req_width;
Packit Service a1bd4f
            if (child->flags & NMT_NEWT_GRID_ANCHOR_RIGHT)
Packit Service a1bd4f
                child_x += priv->col_widths[child->x] - child->req_width;
Packit Service a1bd4f
            else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_LEFT))
Packit Service a1bd4f
                child_x += (priv->col_widths[child->x] - child->req_width) / 2;
Packit Service a1bd4f
        }
Packit Service a1bd4f
Packit Service a1bd4f
        child_y = y;
Packit Service a1bd4f
        for (row = 0; row < child->y; row++)
Packit Service a1bd4f
            child_y += priv->row_heights[row];
Packit Service a1bd4f
Packit Service a1bd4f
        if ((child->flags & NMT_NEWT_GRID_FILL_Y) == NMT_NEWT_GRID_FILL_Y) {
Packit Service a1bd4f
            child_height = priv->row_heights[child->y];
Packit Service a1bd4f
        } else {
Packit Service a1bd4f
            child_height = child->req_height;
Packit Service a1bd4f
            if (child->flags & NMT_NEWT_GRID_ANCHOR_BOTTOM)
Packit Service a1bd4f
                child_y += priv->row_heights[child->y] - child->req_height;
Packit Service a1bd4f
            else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_TOP))
Packit Service a1bd4f
                child_y += (priv->row_heights[child->y] - child->req_height) / 2;
Packit Service a1bd4f
        }
Packit Service a1bd4f
Packit Service a1bd4f
        nmt_newt_widget_size_allocate(child->widget, child_x, child_y, child_width, child_height);
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_find_size(NmtNewtGrid *grid)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data;
Packit Service a1bd4f
    int                 i;
Packit Service a1bd4f
Packit Service a1bd4f
    priv->max_x = priv->max_y = 0;
Packit Service a1bd4f
    for (i = 0; i < priv->children->len; i++) {
Packit Service a1bd4f
        if (children[i].x > priv->max_x)
Packit Service a1bd4f
            priv->max_x = children[i].x;
Packit Service a1bd4f
        if (children[i].y > priv->max_y)
Packit Service a1bd4f
            priv->max_y = children[i].y;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_grid_add:
Packit 5756e2
 * @grid: an #NmtNewtGrid
Packit 5756e2
 * @widget: the widget to add
Packit 5756e2
 * @x: x coordinate
Packit 5756e2
 * @y: y coordinate
Packit 5756e2
 *
Packit 5756e2
 * Adds @widget to @grid at @x, @y. See the discussion above for more
Packit 5756e2
 * details of exactly how this works.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_grid_add(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild    child;
Packit Service a1bd4f
Packit Service a1bd4f
    NMT_NEWT_CONTAINER_CLASS(nmt_newt_grid_parent_class)->add(NMT_NEWT_CONTAINER(grid), widget);
Packit Service a1bd4f
Packit Service a1bd4f
    memset(&child, 0, sizeof(child));
Packit Service a1bd4f
    child.widget = widget;
Packit Service a1bd4f
    child.x      = x;
Packit Service a1bd4f
    child.y      = y;
Packit Service a1bd4f
    child.flags  = NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y;
Packit Service a1bd4f
    g_array_append_val(priv->children, child);
Packit Service a1bd4f
Packit Service a1bd4f
    if (x > priv->max_x)
Packit Service a1bd4f
        priv->max_x = x;
Packit Service a1bd4f
    if (y > priv->max_y)
Packit Service a1bd4f
        priv->max_y = y;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static int
Packit Service a1bd4f
find_child(NmtNewtGrid *grid, NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data;
Packit Service a1bd4f
    int                 i;
Packit 5756e2
Packit Service a1bd4f
    for (i = 0; i < priv->children->len; i++) {
Packit Service a1bd4f
        if (children[i].widget == widget)
Packit Service a1bd4f
            return i;
Packit Service a1bd4f
    }
Packit 5756e2
Packit Service a1bd4f
    return -1;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGrid *       grid = NMT_NEWT_GRID(container);
Packit Service a1bd4f
    NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    int                 i;
Packit 5756e2
Packit Service a1bd4f
    i = find_child(grid, widget);
Packit Service a1bd4f
    if (i != -1) {
Packit Service a1bd4f
        g_array_remove_index(priv->children, i);
Packit Service a1bd4f
        nmt_newt_grid_find_size(grid);
Packit Service a1bd4f
    }
Packit 5756e2
Packit Service a1bd4f
    NMT_NEWT_CONTAINER_CLASS(nmt_newt_grid_parent_class)->remove(container, widget);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_grid_move:
Packit 5756e2
 * @grid: an #NmtNewtGrid
Packit 5756e2
 * @widget: a child of @grid
Packit 5756e2
 * @x: x coordinate
Packit 5756e2
 * @y: y coordinate
Packit 5756e2
 *
Packit 5756e2
 * Moves @widget to the given new coordinates.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_grid_move(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data;
Packit Service a1bd4f
    int                 i;
Packit Service a1bd4f
Packit Service a1bd4f
    i = find_child(grid, widget);
Packit Service a1bd4f
    if (i != -1 && (children[i].x != x || children[i].y != y)) {
Packit Service a1bd4f
        children[i].x = x;
Packit Service a1bd4f
        children[i].y = y;
Packit Service a1bd4f
        nmt_newt_grid_find_size(grid);
Packit Service a1bd4f
        nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(grid));
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * NmtNewtGridFlags:
Packit 5756e2
 * @NMT_NEWT_GRID_EXPAND_X: The widget's cell should expand
Packit 5756e2
 *   horizontally if the grid as a whole is given more width than
Packit 5756e2
 *   it requested.
Packit 5756e2
 * @NMT_NEWT_GRID_EXPAND_Y: The widget's cell should expand
Packit 5756e2
 *   vertically if the grid as a whole is given more height than
Packit 5756e2
 *   it requested.
Packit 5756e2
 * @NMT_NEWT_GRID_ANCHOR_LEFT: If the widget's cell is wider than
Packit 5756e2
 *   the widget requested, the widget should be anchored to the
Packit 5756e2
 *   left of its cell rather than being centered.
Packit 5756e2
 * @NMT_NEWT_GRID_ANCHOR_RIGHT: If the widget's cell is wider than
Packit 5756e2
 *   the widget requested, the widget should be anchored to the
Packit 5756e2
 *   right of its cell rather than being centered.
Packit 5756e2
 * @NMT_NEWT_GRID_FILL_X: If the widget's cell is wider than
Packit 5756e2
 *   the widget requested, the widget should be allocated the
Packit 5756e2
 *   full width of the cell; this is equivalent to specifying
Packit 5756e2
 *   both %NMT_NEWT_GRID_ANCHOR_LEFT and %NMT_NEWT_GRID_ANCHOR_RIGHT.
Packit 5756e2
 * @NMT_NEWT_GRID_ANCHOR_TOP: If the widget's cell is taller than
Packit 5756e2
 *   the widget requested, the widget should be anchored to the
Packit 5756e2
 *   top of its cell rather than being centered.
Packit 5756e2
 * @NMT_NEWT_GRID_ANCHOR_BOTTOM: If the widget's cell is taller than
Packit 5756e2
 *   the widget requested, the widget should be anchored to the
Packit 5756e2
 *   bottom of its cell rather than being centered.
Packit 5756e2
 * @NMT_NEWT_GRID_FILL_Y: If the widget's cell is taller than
Packit 5756e2
 *   the widget requested, the widget should be allocated the
Packit 5756e2
 *   full height of the cell; this is equivalent to specifying
Packit 5756e2
 *   both %NMT_NEWT_GRID_ANCHOR_TOP and %NMT_NEWT_GRID_ANCHOR_BOTTOM.
Packit 5756e2
 *
Packit 5756e2
 * Flags describing how a widget is placed within its grid cell.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_grid_set_flags:
Packit 5756e2
 * @grid: an #NmtNewtGrid
Packit 5756e2
 * @widget: a child of @grid
Packit 5756e2
 * @flags: #NmtNewtGridFlags for @widget
Packit 5756e2
 *
Packit 5756e2
 * Sets the #NmtNewtGridFlags on @widget
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_grid_set_flags(NmtNewtGrid *grid, NmtNewtWidget *widget, NmtNewtGridFlags flags)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtGridPrivate *priv     = NMT_NEWT_GRID_GET_PRIVATE(grid);
Packit Service a1bd4f
    NmtNewtGridChild *  children = (NmtNewtGridChild *) priv->children->data;
Packit Service a1bd4f
    int                 i;
Packit 5756e2
Packit Service a1bd4f
    i = find_child(grid, widget);
Packit Service a1bd4f
    if (i != -1)
Packit Service a1bd4f
        children[i].flags = flags;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_grid_class_init(NmtNewtGridClass *grid_class)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass *         object_class    = G_OBJECT_CLASS(grid_class);
Packit Service a1bd4f
    NmtNewtWidgetClass *   widget_class    = NMT_NEWT_WIDGET_CLASS(grid_class);
Packit Service a1bd4f
    NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(grid_class);
Packit 5756e2
Packit Service a1bd4f
    g_type_class_add_private(grid_class, sizeof(NmtNewtGridPrivate));
Packit 5756e2
Packit Service a1bd4f
    /* virtual methods */
Packit Service a1bd4f
    object_class->finalize = nmt_newt_grid_finalize;
Packit 5756e2
Packit Service a1bd4f
    widget_class->get_components = nmt_newt_grid_get_components;
Packit Service a1bd4f
    widget_class->size_request   = nmt_newt_grid_size_request;
Packit Service a1bd4f
    widget_class->size_allocate  = nmt_newt_grid_size_allocate;
Packit 5756e2
Packit Service a1bd4f
    container_class->remove = nmt_newt_grid_remove;
Packit 5756e2
}