diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-11 00:21:57 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-11 00:21:57 +0000 |
commit | 54211c3efb9d4a9b47f3369bdc9f95827e39465e (patch) | |
tree | 1dc9c9f18e3b7a369651ab082c2fee9b323621d9 /chrome/common | |
parent | b2b462c79bd4365c76ec90dd74f15ea4e8252638 (diff) | |
download | chromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.zip chromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.tar.gz chromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.tar.bz2 |
Add helper for creating table of labeled controls.
BUG=none
Review URL: http://codereview.chromium.org/118489
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18120 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/gtk_util.cc | 26 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 8 |
2 files changed, 34 insertions, 0 deletions
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 95fe87b..b280a6b 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -4,6 +4,7 @@ #include "chrome/common/gtk_util.h" +#include <cstdarg> #include <gtk/gtk.h> #include <gdk/gdkx.h> @@ -37,6 +38,31 @@ WindowOpenDisposition DispositionFromEventFlags(guint event_flags) { namespace gtk_util { +GtkWidget* CreateLabeledControlsGroup(const char* text, ...) { + va_list ap; + va_start(ap, text); + GtkWidget* table = gtk_table_new(0, 2, FALSE); + gtk_table_set_col_spacing(GTK_TABLE(table), 0, kLabelSpacing); + gtk_table_set_row_spacings(GTK_TABLE(table), kControlSpacing); + + for (guint row = 0; text; ++row) { + gtk_table_resize(GTK_TABLE(table), row + 1, 2); + GtkWidget* control = va_arg(ap, GtkWidget*); + GtkWidget* label = gtk_label_new(text); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, + 0, 1, row, row + 1, + GTK_FILL, GTK_FILL, + 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), control, + 1, 2, row, row + 1); + text = va_arg(ap, const char*); + } + va_end(ap); + + return table; +} + GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color, int top, int bottom, int left, int right) { // Use a GtkEventBox to get the background painted. However, we can't just diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index 52629d3..92ea54e 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -44,6 +44,14 @@ const int kContentAreaBorder = 12; // Spacing between groups of controls. const int kContentAreaSpacing = 18; +// Create a table of labeled controls, using proper spacing and alignment. +// Arguments should be pairs of const char*, GtkWidget*, concluding with a NULL. +// For example: +// controls = CreateLabeledControlsGroup("Name:", title_entry_, +// "Folder:", folder_combobox_, +// NULL); +GtkWidget* CreateLabeledControlsGroup(const char* text, ...); + // Create a GtkBin with |child| as its child widget. This bin will paint a // border of color |color| with the sizes specified in pixels. GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color, |