]> git.tdb.fi Git - libs/gltk.git/commitdiff
Make sure that at least one line of text is always rendered
authorMikko Rasa <tdb@tdb.fi>
Fri, 15 Oct 2010 04:50:20 +0000 (04:50 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 15 Oct 2010 04:50:20 +0000 (04:50 +0000)
Initialize Entry's visible rows and make sure it's always at least 1

source/entry.cpp
source/text.cpp

index 654ac6c673f17025917f72ad1af4bf0cdcde0631..3fa4c91bb36423d64e10986bafcd156e995fdf28 100644 (file)
@@ -27,6 +27,7 @@ Entry::Entry(const Resources &r, const string &t):
        multiline(false),
        edit_pos(0),
        first_row(0),
+       visible_rows(1),
        text_part(0),
        slider(0)
 {
@@ -187,7 +188,7 @@ void Entry::check_view_range()
        unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
 
        const Sides &margin = text_part->get_margin();
-       visible_rows = (geom.h-margin.top-margin.bottom)/line_spacing;
+       visible_rows = max((geom.h-margin.top-margin.bottom)/line_spacing, 1U);
 
        unsigned row, col;
        text.offset_to_coords(edit_pos, row, col);
index 1b465120a31d5b5b50ff699969c646aaa5f625a8..c173a8a5edb3a603351661dca1f22347270d85b6 100644 (file)
@@ -209,7 +209,7 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs
        int y_offset = static_cast<int>(-font->get_descent()*font_size);
 
        const Sides &margin = part.get_margin();
-       unsigned n_lines = min(lines.size(), (parent.h-margin.top-margin.bottom)/line_spacing);
+       unsigned n_lines = max(min(lines.size(), (parent.h-margin.top-margin.bottom)/line_spacing), 1U);
        first_row = min(first_row, lines.size()-n_lines);
 
        for(unsigned i=0; i<n_lines; ++i)