if(!multiline || !text_part)
return;
- float font_size = style->get_font_size();
- unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
-
- const Sides &margin = text_part->get_margin();
- visible_rows = max((geom.h-margin.top-margin.bottom)/line_spacing, 1U);
+ visible_rows = text.get_visible_lines(*text_part, geom, 0);
unsigned row, col;
text.offset_to_coords(edit_pos, row, col);
}
}
+unsigned Text::get_visible_lines(const Part &part, const Geometry &parent, unsigned *fit_height) const
+{
+ const GL::Font &font = style->get_font();
+ 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);
+
+ const Sides &margin = part.get_margin();
+ unsigned vmargin = margin.top+margin.bottom+line_height-line_spacing;
+ unsigned n_lines = min<unsigned>(lines.size(), max((max(parent.h, vmargin)-vmargin)/line_spacing, 1U));
+ if(fit_height)
+ *fit_height = line_height+(n_lines-1)*line_spacing;
+
+ return n_lines;
+}
+
unsigned Text::get_line_length(unsigned i) const
{
if(i>=lines.size())
const GL::Font &font = style->get_font();
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);
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;
+ unsigned fit_height;
+ unsigned n_lines = get_visible_lines(part, parent, &fit_height);
first_row = min<unsigned>(first_row, lines.size()-n_lines);
for(unsigned i=0; i<n_lines; ++i)
const std::string &get() const { return text; }
unsigned size() const { return text.size(); }
unsigned get_n_lines() const { return lines.size(); }
+ unsigned get_visible_lines(const Part &, const Geometry &, unsigned *) const;
unsigned get_line_length(unsigned) const;
void offset_to_coords(unsigned, unsigned &, unsigned &) const;
unsigned coords_to_offset(unsigned, unsigned) const;