From: Mikko Rasa Date: Thu, 12 Sep 2019 09:11:39 +0000 (+0300) Subject: Improve vertical positioning of text X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8a911be6fd3c2840befcef44ac7b24969563d34e;p=libs%2Fgltk.git Improve vertical positioning of text Applying alignment to only the number of lines that fit in the widget results in a more consistent position. --- diff --git a/source/text.cpp b/source/text.cpp index 1d7a793..cdaae85 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -227,12 +227,12 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs float font_size = style->get_font_size(); unsigned line_height = static_cast((font.get_ascent()-font.get_descent())*font_size); unsigned line_spacing = static_cast(font_size*6/5); - unsigned height = line_height+(lines.size()-1)*line_spacing; int y_offset = static_cast(-font.get_descent()*font_size); const Sides &margin = part.get_margin(); unsigned fit_height = parent.h-margin.top-margin.bottom+line_spacing-line_height; unsigned n_lines = min(lines.size(), max(fit_height/line_spacing, 1U)); + fit_height = line_height+(n_lines-1)*line_spacing; first_row = min(first_row, lines.size()-n_lines); for(unsigned i=0; i