extend ArdourButton API to provide a new tweak for buttons with occasional text
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 14 Jun 2016 15:47:25 +0000 (11:47 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 14 Jun 2016 15:47:25 +0000 (11:47 -0400)
Buttons with this tweak do not change their size request based on their text (or lack of it)

gtk2_ardour/ardour_button.cc
gtk2_ardour/ardour_button.h

index 0fa53c53728175152b7f0b98ed8bee37d34fa4f9..aa283828234e3b36081b3a67f8b3793ecb722b02 100644 (file)
@@ -541,14 +541,30 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
                }
        }
 
-       if ((_elements & Text) && !_text.empty()) {
-               // if _layout does not exist, char_pixel_height() creates it,
-               req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
-               assert (_layout);
-               _layout->get_pixel_size (_text_width, _text_height);
-
-               req->width += rint(1.75 * char_pixel_width()); // padding
-               req->width += _text_width;
+       if (_elements & Text) {
+
+               if (_tweaks & OccasionalText) {
+
+                       /* size should not change based on presence or absence
+                        * of text.
+                        */
+
+                       if (!_text.empty()) {
+                               ensure_layout ();
+                               _layout->set_text (_text);
+                               _layout->get_pixel_size (_text_width, _text_height);
+                       }
+
+               } else if (!_text.empty()) {
+
+                       //if _layout does not exist, char_pixel_height() creates it,
+
+                       req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
+                       assert (_layout);
+                       _layout->get_pixel_size (_text_width, _text_height);
+                       req->width += rint(1.75 * char_pixel_width()); // padding
+                       req->width += _text_width;
+               }
 
                /* XXX hack (surprise). Deal with two common rotation angles */
 
index 928f4a8355e581e14e59d43f7a35cfc9db48a200..78c2f5e369ae7f5bed1ab125e78bb9d978a189cb 100644 (file)
@@ -55,7 +55,8 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
        enum Tweaks {
                Square = 0x1,
                TrackHeader = 0x2,
-               unused3 = 0x4,
+               OccasionalText = 0x4,
+               unused4 = 0x8,
        };
 
        Tweaks tweaks() const { return _tweaks; }