summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-24 17:00:50 -0400
committerDan Winship <danw@gnome.org>2014-11-01 12:41:42 -0400
commitbe6b42bb850a7117411788b90ab327ff4d772d90 (patch)
tree27b4681b18ef9d1dcf20da2927d2f334ac9d1e6f
parent3dd117faa2552c10f41c103e84c4fb28be4fbfe4 (diff)
downloadNetworkManager-danw/tui-sections-bgo719768.tar.gz
tui: tweak NmtEditorGrid column rulesdanw/tui-sections-bgo719768
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.
-rw-r--r--clients/tui/nmt-editor-grid.c57
-rw-r--r--clients/tui/nmt-editor-section.c2
2 files changed, 32 insertions, 27 deletions
diff --git a/clients/tui/nmt-editor-grid.c b/clients/tui/nmt-editor-grid.c
index 7fb2f6bf1d..118bf01d3a 100644
--- a/clients/tui/nmt-editor-grid.c
+++ b/clients/tui/nmt-editor-grid.c
@@ -101,20 +101,17 @@ nmt_editor_grid_finalize (GObject *object)
* nmt_editor_grid_append:
* @grid: the #NmtEditorGrid
* @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
*
* Adds a row to @grid.
*
- * If @label is non-%NULL, this will add a three-column row,
- * containing a right-aligned #NmtNewtLabel in the first column,
- * @widget in the second column, and @extra (if non-%NULL) in
- * the third column.
+ * If @label and @widget are both non-%NULL, this will add a three-column row,
+ * containing a right-aligned #NmtNewtLabel in the first column, @widget in the
+ * second column, and @extra (if non-%NULL) in the third column.
*
- * If @label is %NULL, then this will add a row with a single
- * grid-spanning column, containing @widget.
- *
- * FIXME: That's sort of weird.
+ * If either @label or @widget is %NULL, then the other column will expand into
+ * it.
*
* See also nmt_editor_grid_set_row_flags().
*/
@@ -129,8 +126,15 @@ nmt_editor_grid_append (NmtEditorGrid *grid,
NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid);
NmtEditorGridRow row;
+ g_return_if_fail (label != NULL || widget != NULL);
+
memset (&row, 0, sizeof (row));
+ if (label && !widget) {
+ widget = nmt_newt_label_new (label);
+ label = NULL;
+ }
+
if (label) {
row.label = nmt_newt_label_new (label);
parent_class->add (container, row.label);
@@ -408,27 +412,28 @@ nmt_editor_grid_size_allocate (NmtNewtWidget *widget,
y + row,
col1_width,
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 {
nmt_newt_widget_size_allocate (rows[i].widget,
x,
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]);
}
diff --git a/clients/tui/nmt-editor-section.c b/clients/tui/nmt-editor-section.c
index 9d892cc521..ad970a90d7 100644
--- a/clients/tui/nmt-editor-section.c
+++ b/clients/tui/nmt-editor-section.c
@@ -87,7 +87,7 @@ rebuild_header (NmtEditorSection *section)
nmt_editor_grid_append (priv->header,
priv->title,
- priv->header_widget ? priv->header_widget : nmt_newt_separator_new (),
+ priv->header_widget,
priv->toggle);
nmt_editor_grid_set_row_flags (priv->header,
priv->toggle,