]> git.tdb.fi Git - libs/gltk.git/commitdiff
Improve vertical positioning of text
authorMikko Rasa <tdb@tdb.fi>
Thu, 12 Sep 2019 09:11:39 +0000 (12:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 12 Sep 2019 09:11:39 +0000 (12:11 +0300)
Applying alignment to only the number of lines that fit in the widget
results in a more consistent position.

source/text.cpp

index 1d7a7930dc4bc58c695e8d2082fb5895e9598f66..cdaae859abb481f301ad5a610ae42241f45b5e36 100644 (file)
@@ -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<unsigned>((font.get_ascent()-font.get_descent())*font_size);
        unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
-       unsigned height = line_height+(lines.size()-1)*line_spacing;
        int y_offset = static_cast<int>(-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<unsigned>(lines.size(), max(fit_height/line_spacing, 1U));
+       fit_height = line_height+(n_lines-1)*line_spacing;
        first_row = min<unsigned>(first_row, lines.size()-n_lines);
 
        for(unsigned i=0; i<n_lines; ++i)
@@ -241,7 +241,7 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs
 
                Geometry rgeom;
                rgeom.w = line.width;
-               rgeom.h = height;
+               rgeom.h = fit_height;
                rgeom.y = (n_lines-1-i)*line_spacing+y_offset;
                part.get_alignment().apply(rgeom, parent, part.get_margin());