Allow to override Ardour button text padding

This commit is contained in:
Robin Gareus 2022-11-05 15:11:45 +01:00
parent 88ff1fa192
commit 3d6ecaad79
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 17 additions and 1 deletions

View File

@ -64,6 +64,7 @@ ArdourButton::ArdourButton (Element e, bool toggle)
, _char_pixel_width (0)
, _char_pixel_height (0)
, _char_avg_pixel_width (0)
, _width_padding (1.75)
, _custom_font_set (false)
, _text_width (0)
, _text_height (0)
@ -111,6 +112,7 @@ ArdourButton::ArdourButton (const std::string& str, Element e, bool toggle)
, _char_pixel_width (0)
, _char_pixel_height (0)
, _char_avg_pixel_width (0)
, _width_padding (1.75)
, _custom_font_set (false)
, _text_width (0)
, _text_height (0)
@ -691,7 +693,7 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
} else /*if (!_text.empty() || !_sizing_texts.empty()) */ {
req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
req->width += rint(1.75 * char_pixel_width()); // padding
req->width += rint(_width_padding * char_pixel_width()); // padding
int sizing_text_width = 0, sizing_text_height = 0;
@ -1337,6 +1339,18 @@ ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e)
}
}
void
ArdourButton::set_width_padding (float p)
{
if (_width_padding == p) {
return;
}
_width_padding = p;
if (get_realized ()) {
queue_resize ();
}
}
void
ArdourButton::ensure_layout ()
{

View File

@ -102,6 +102,7 @@ class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activ
void set_layout_ellipsize_width (int w);
void set_layout_font (const Pango::FontDescription&);
void set_text_ellipsize (Pango::EllipsizeMode);
void set_width_padding (float);
/* Sets the text used for size request computation. Pass an
* empty string to return to the default behavior which uses
@ -171,6 +172,7 @@ class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activ
unsigned int _char_pixel_width;
unsigned int _char_pixel_height;
float _char_avg_pixel_width;
float _width_padding;
bool _custom_font_set;
int _text_width;