fix layouting when button text changes
This commit is contained in:
parent
fcb4556a4e
commit
e52bbce5e0
4 changed files with 8 additions and 6 deletions
|
@ -31,10 +31,11 @@ void Button::on_paint() {
|
|||
auto painter = window()->painter();
|
||||
auto text_color = styles()->button_text_color();
|
||||
auto max_geometry = current_geometry().max_geometry();
|
||||
bool set_size = current_geometry().max_width() != -1 && current_geometry().max_height() != -1;
|
||||
|
||||
painter.source_rgb(text_color);
|
||||
painter.set_pango_font_description(styles()->controls_font_description());
|
||||
auto point = painter.text(max_geometry, m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END);
|
||||
auto point = painter.text(max_geometry, m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, set_size);
|
||||
resize(point);
|
||||
painter.fill();
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ void Label::on_paint() {
|
|||
auto painter = window()->painter();
|
||||
auto text_color = styles()->label_text_color();
|
||||
auto text_geometry = current_geometry().max_geometry();
|
||||
bool set_size = current_geometry().max_width() != -1 && current_geometry().max_height() != -1;
|
||||
|
||||
painter.source_rgb(text_color);
|
||||
painter.set_pango_font_description(styles()->controls_font_description());
|
||||
auto point = painter.text(text_geometry, m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE);
|
||||
auto point = painter.text(text_geometry, m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, set_size);
|
||||
resize(point);
|
||||
painter.fill();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ bool Painter::text(Point &where, std::string &text) {
|
|||
return true;
|
||||
}
|
||||
|
||||
Point Painter::text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize) {
|
||||
Point Painter::text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize, bool set_size) {
|
||||
if (m_pango_font_description == nullptr)
|
||||
return {-1,-1};
|
||||
|
||||
|
@ -51,9 +51,9 @@ Point Painter::text(Box &geometry, std::string &text, PaintTextAlign align, Pang
|
|||
int pango_height;
|
||||
|
||||
pango_layout_set_font_description(layout, m_pango_font_description);
|
||||
if (geometry.width() > 0)
|
||||
if (geometry.width() > 0 && set_size)
|
||||
pango_layout_set_width(layout, pango_units_from_double(geometry.width()));
|
||||
if (geometry.height() > 0)
|
||||
if (geometry.height() > 0 && set_size)
|
||||
pango_layout_set_height(layout, pango_units_from_double(geometry.height()));
|
||||
pango_layout_set_ellipsize(layout, ellipsize);
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
void rounded_rectangle(Box &geometry, double border_radius);
|
||||
bool text(Point &where, std::string &text);
|
||||
Point text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize);
|
||||
Point text(Box &geometry, std::string &text, PaintTextAlign align, PangoEllipsizeMode ellipsize, bool set_size);
|
||||
|
||||
bool can_paint() { if (m_cairo) return true; else return false; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue