tui: tweak NmtEditorGrid column rules

If an NmtEditorGrid row has a widget, but no label, then we make the
widget span both the label and widget columns. But previously we
weren't doing the same for rows with labels but no widgets. (In fact,
we didn't even allow rows with no widgets; label-only rows had to
specify dummy widgets.)

Fix it so that labels will span into an empty widget column. (This
ensures that a long section name won't force the entire grid to have
an overwide label column).

Also, in both the "no label" and "no widget" cases, still show the
"extra" column if it's present.
This commit is contained in:
Dan Winship
2014-09-24 17:00:50 -04:00
committed by Dan Winship
parent 5f6b0be525
commit 04ef74b16f
2 changed files with 32 additions and 27 deletions

View File

@@ -101,20 +101,17 @@ nmt_editor_grid_finalize (GObject *object)
* nmt_editor_grid_append: * nmt_editor_grid_append:
* @grid: the #NmtEditorGrid * @grid: the #NmtEditorGrid
* @label: (allow-none): the label text for @widget, or %NULL * @label: (allow-none): the label text for @widget, or %NULL
* @widget: the (main) widget * @widget: (allow-none): the (main) widget
* @extra: (allow-none): optional extra widget * @extra: (allow-none): optional extra widget
* *
* Adds a row to @grid. * Adds a row to @grid.
* *
* If @label is non-%NULL, this will add a three-column row, * If @label and @widget are both non-%NULL, this will add a three-column row,
* containing a right-aligned #NmtNewtLabel in the first column, * containing a right-aligned #NmtNewtLabel in the first column, @widget in the
* @widget in the second column, and @extra (if non-%NULL) in * second column, and @extra (if non-%NULL) in the third column.
* the third column.
* *
* If @label is %NULL, then this will add a row with a single * If either @label or @widget is %NULL, then the other column will expand into
* grid-spanning column, containing @widget. * it.
*
* FIXME: That's sort of weird.
* *
* See also nmt_editor_grid_set_row_flags(). * See also nmt_editor_grid_set_row_flags().
*/ */
@@ -129,8 +126,15 @@ nmt_editor_grid_append (NmtEditorGrid *grid,
NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid); NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid);
NmtEditorGridRow row; NmtEditorGridRow row;
g_return_if_fail (label != NULL || widget != NULL);
memset (&row, 0, sizeof (row)); memset (&row, 0, sizeof (row));
if (label && !widget) {
widget = nmt_newt_label_new (label);
label = NULL;
}
if (label) { if (label) {
row.label = nmt_newt_label_new (label); row.label = nmt_newt_label_new (label);
parent_class->add (container, row.label); parent_class->add (container, row.label);
@@ -408,27 +412,28 @@ nmt_editor_grid_size_allocate (NmtNewtWidget *widget,
y + row, y + row,
col1_width, col1_width,
priv->row_heights[i]); priv->row_heights[i]);
if (rows[i].extra) {
int wwidth, wheight, ex;
if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT)
ex = x + col0_width + col1_width + 2;
else {
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
ex = x + col0_width + wwidth + 2;
}
nmt_newt_widget_size_allocate (rows[i].extra,
ex,
y + row,
col2_width,
priv->row_heights[i]);
}
} else { } else {
nmt_newt_widget_size_allocate (rows[i].widget, nmt_newt_widget_size_allocate (rows[i].widget,
x, x,
y + row, y + row,
col0_width + col1_width + col2_width + 2, col0_width + col1_width + 1,
priv->row_heights[i]);
}
if (rows[i].extra) {
int wwidth, wheight, ex;
if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT)
ex = x + col0_width + col1_width + 2;
else {
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
ex = x + col0_width + wwidth + 2;
}
nmt_newt_widget_size_allocate (rows[i].extra,
ex,
y + row,
col2_width,
priv->row_heights[i]); priv->row_heights[i]);
} }

View File

@@ -87,7 +87,7 @@ rebuild_header (NmtEditorSection *section)
nmt_editor_grid_append (priv->header, nmt_editor_grid_append (priv->header,
priv->title, priv->title,
priv->header_widget ? priv->header_widget : nmt_newt_separator_new (), priv->header_widget,
priv->toggle); priv->toggle);
nmt_editor_grid_set_row_flags (priv->header, nmt_editor_grid_set_row_flags (priv->header,
priv->toggle, priv->toggle,