summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-07-30 18:27:12 -0400
committerDavid Robillard <d@drobilla.net>2014-07-30 18:30:42 -0400
commitb75b88a1eb881d9c95fcea5b50346fac09bc7302 (patch)
tree6af38f01c82cdb327025a56d83ea344f4bede32f /libs
parent394ea9cb860354c1f24bbecf5a85e88d1a16d136 (diff)
Use text to specify combo box padding for better font/display tolerance.
Consistent mixer strip button height. The latter works by setting all the button size request heights to the calculated height of the alphabet. Thus, all buttons of the same class will be the same height regardless of their actual text.
Diffstat (limited to 'libs')
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/utils.h11
-rw-r--r--libs/gtkmm2ext/utils.cc61
2 files changed, 72 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h
index bad9ca75d6..799d3970c2 100644
--- a/libs/gtkmm2ext/gtkmm2ext/utils.h
+++ b/libs/gtkmm2ext/gtkmm2ext/utils.h
@@ -65,6 +65,13 @@ namespace Gtkmm2ext {
gint hpadding,
gint vpadding);
+ LIBGTKMM2EXT_API void set_size_request_to_display_given_text_width (Gtk::Widget& w,
+ const gchar* htext,
+ gint hpadding,
+ gint vpadding);
+
+ LIBGTKMM2EXT_API void set_height_request_to_display_any_text (Gtk::Widget& w, gint vpadding);
+
LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
std::string const & text,
gint hpadding,
@@ -73,6 +80,10 @@ namespace Gtkmm2ext {
const std::vector<std::string>&,
gint hpadding,
gint vpadding);
+ LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
+ const std::vector<std::string>&,
+ const std::string& hpadding,
+ gint vpadding);
LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Pixbuf> pixbuf_from_string (const std::string& name,
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc
index 37ed4ba66b..f3c5b6795f 100644
--- a/libs/gtkmm2ext/utils.cc
+++ b/libs/gtkmm2ext/utils.cc
@@ -76,6 +76,40 @@ Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *
w.set_size_request(width + hpadding, height + vpadding);
}
+/** Set width request to display given text, and height to display anything.
+ This is useful for setting many widgets to the same height for consistency. */
+void
+Gtkmm2ext::set_size_request_to_display_given_text_width (Gtk::Widget& w,
+ const gchar* htext,
+ gint hpadding,
+ gint vpadding)
+{
+ static const gchar* vtext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ w.ensure_style ();
+
+ int hwidth, hheight;
+ get_pixel_size (w.create_pango_layout (htext), hwidth, hheight);
+
+ int vwidth, vheight;
+ get_pixel_size (w.create_pango_layout (vtext), vwidth, vheight);
+
+ w.set_size_request(hwidth + hpadding, vheight + vpadding);
+}
+
+void
+Gtkmm2ext::set_height_request_to_display_any_text (Gtk::Widget& w, gint vpadding)
+{
+ static const gchar* vtext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ w.ensure_style ();
+
+ int width, height;
+ get_pixel_size (w.create_pango_layout (vtext), width, height);
+
+ w.set_size_request(-1, height + vpadding);
+}
+
void
Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, std::string const & text,
gint hpadding, gint vpadding)
@@ -125,6 +159,33 @@ Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w,
w.set_size_request(width_max + hpadding, height_max + vpadding);
}
+/** This version specifies horizontal padding in text to avoid assumptions
+ about font size. Should be used anywhere padding is used to avoid text,
+ like combo boxes. */
+void
+Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget& w,
+ const std::vector<std::string>& strings,
+ const std::string& hpadding,
+ gint vpadding)
+{
+ int width_max = 0;
+ int height_max = 0;
+ w.ensure_style ();
+
+ for (vector<string>::const_iterator i = strings.begin(); i != strings.end(); ++i) {
+ int width, height;
+ get_pixel_size (w.create_pango_layout (*i), width, height);
+ width_max = max(width_max,width);
+ height_max = max(height_max, height);
+ }
+
+ int pad_width;
+ int pad_height;
+ get_pixel_size (w.create_pango_layout (hpadding), pad_width, pad_height);
+
+ w.set_size_request(width_max + pad_width, height_max + vpadding);
+}
+
static inline guint8
demultiply_alpha (guint8 src,
guint8 alpha)