Fix size-request that rely on Pango::Layout
A Pango::Layout created by Gtk::Widget::get_pango_context () does not have any font set. The Font is inherited from the layout's context. The actual font is set when the layout is used in on_expose_event() via get_window ()->create_cairo_context (). In some cases we rely on the font-size to calculate the widget's size before rendering. At this point in time there is no drawing context from which to inherit the style. Furthermore, even after a call to `ensure_style()` in the c'tor of a Widget get_font() simply returns the default value. All Widgets that rely an Pango::Layout font size during size-requests have to explicitly set the font. This fixes various overlarge buttons with the initial default layout.
This commit is contained in:
parent
d42b09f1d3
commit
2abf9c66a4
@ -66,6 +66,7 @@ ArdourButton::ArdourButton (Element e, bool toggle)
|
||||
, _char_pixel_width (0)
|
||||
, _char_pixel_height (0)
|
||||
, _char_avg_pixel_width (0)
|
||||
, _custom_font_set (false)
|
||||
, _text_width (0)
|
||||
, _text_height (0)
|
||||
, _diameter (0)
|
||||
@ -113,6 +114,7 @@ ArdourButton::ArdourButton (const std::string& str, Element e, bool toggle)
|
||||
, _char_pixel_width (0)
|
||||
, _char_pixel_height (0)
|
||||
, _char_avg_pixel_width (0)
|
||||
, _custom_font_set (false)
|
||||
, _text_width (0)
|
||||
, _text_height (0)
|
||||
, _diameter (0)
|
||||
@ -179,6 +181,7 @@ ArdourButton::set_layout_font (const Pango::FontDescription& fd)
|
||||
queue_resize ();
|
||||
_char_pixel_width = 0;
|
||||
_char_pixel_height = 0;
|
||||
_custom_font_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -974,7 +977,7 @@ ArdourButton::on_size_allocate (Allocation& alloc)
|
||||
setup_led_rect ();
|
||||
if (_layout) {
|
||||
/* re-center text */
|
||||
_layout->get_pixel_size (_text_width, _text_height);
|
||||
//_layout->get_pixel_size (_text_width, _text_height);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1047,13 +1050,20 @@ ArdourButton::action_toggled ()
|
||||
}
|
||||
|
||||
void
|
||||
ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
|
||||
ArdourButton::on_style_changed (const RefPtr<Gtk::Style>& style)
|
||||
{
|
||||
_update_colors = true;
|
||||
CairoWidget::on_style_changed (style);
|
||||
Glib::RefPtr<Gtk::Style> const& new_style = get_style();
|
||||
|
||||
CairoWidget::set_dirty ();
|
||||
_update_colors = true;
|
||||
_char_pixel_width = 0;
|
||||
_char_pixel_height = 0;
|
||||
if (is_realized()) {
|
||||
|
||||
if (!_custom_font_set && _layout && _layout->get_font_description () != new_style->get_font ()) {
|
||||
_layout->set_font_description (new_style->get_font ());
|
||||
queue_resize ();
|
||||
} else if (is_realized()) {
|
||||
queue_resize ();
|
||||
}
|
||||
}
|
||||
@ -1288,6 +1298,7 @@ ArdourButton::ensure_layout ()
|
||||
if (!_layout) {
|
||||
ensure_style ();
|
||||
_layout = Pango::Layout::create (get_pango_context());
|
||||
_layout->set_font_description (get_style()->get_font());
|
||||
_layout->set_ellipsize(_ellipsis);
|
||||
if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
|
||||
_layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE);
|
||||
|
@ -713,13 +713,15 @@ ArdourFader::on_state_changed (Gtk::StateType old_state)
|
||||
}
|
||||
|
||||
void
|
||||
ArdourFader::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
|
||||
ArdourFader::on_style_changed (const Glib::RefPtr<Gtk::Style>& style)
|
||||
{
|
||||
if (_layout) {
|
||||
std::string txt = _layout->get_text();
|
||||
_layout.clear (); // drop reference to existing layout
|
||||
_text = "";
|
||||
set_text (txt, _centered_text, false);
|
||||
CairoWidget::on_style_changed (style);
|
||||
Glib::RefPtr<Gtk::Style> const& new_style = get_style ();
|
||||
if (_layout && (_layout->get_font_description ().gobj () == 0 || _layout->get_font_description () != new_style->get_font ())) {
|
||||
_layout->set_font_description (new_style->get_font ());
|
||||
queue_resize ();
|
||||
} else if (is_realized ()) {
|
||||
queue_resize ();
|
||||
}
|
||||
/* patterns are cached and re-created as needed
|
||||
* during 'expose' in the GUI thread */
|
||||
|
@ -165,9 +165,11 @@ class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activ
|
||||
|
||||
void set_text_internal ();
|
||||
void recalc_char_pixel_geometry ();
|
||||
|
||||
unsigned int _char_pixel_width;
|
||||
unsigned int _char_pixel_height;
|
||||
float _char_avg_pixel_width;
|
||||
float _char_avg_pixel_width;
|
||||
bool _custom_font_set;
|
||||
|
||||
int _text_width;
|
||||
int _text_height;
|
||||
|
Loading…
Reference in New Issue
Block a user