X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftext.cpp;h=cdaae859abb481f301ad5a610ae42241f45b5e36;hb=8a911be6fd3c2840befcef44ac7b24969563d34e;hp=8ef17392f353259c0fa83ec95b1f5b4e6a08a41c;hpb=bf4dbeb94ef7ce7fc7f9fb3e5f1d75cfe5cefff2;p=libs%2Fgltk.git diff --git a/source/text.cpp b/source/text.cpp index 8ef1739..cdaae85 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -160,7 +160,7 @@ Geometry Text::coords_to_geometry(const Part &part, const Geometry &parent, unsi data.row = row; data.col = col; - process_lines(part, parent, first_row, data); + process_lines(part, parent, first_row, &Text::coords_to_geom_line, data); return data.result; } @@ -182,7 +182,7 @@ void Text::build(const Part &part, State state, const Geometry &parent, unsigned RenderData data; data.bld = &bld; - process_lines(part, parent, first_row, data); + process_lines(part, parent, first_row, &Text::build_line, data); } Text &Text::operator=(const string &t) @@ -217,8 +217,8 @@ void Text::find_lines() } } -template -void Text::process_lines(const Part &part, const Geometry &parent, unsigned first_row, T &data) const +template +void Text::process_lines(const Part &part, const Geometry &parent, unsigned first_row, void (Text::*func)(unsigned, const Geometry &, T &) const, T &data) const { if(!style) return; @@ -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