]> git.tdb.fi Git - libs/gltk.git/commitdiff
Use size_t to represent counts and indices
authorMikko Rasa <tdb@tdb.fi>
Mon, 21 Aug 2023 08:22:43 +0000 (11:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 21 Aug 2023 12:51:07 +0000 (15:51 +0300)
17 files changed:
source/dropdown.cpp
source/dropdown.h
source/entry.cpp
source/entry.h
source/graphic.cpp
source/grid.cpp
source/grid.h
source/layout.cpp
source/layout.h
source/list.cpp
source/list.h
source/listdata.h
source/panel.cpp
source/panel.h
source/slider.cpp
source/text.cpp
source/text.h

index 68c1beed1321fea803981b36701246576273a397..ab00c4c3f0c7bd06c0edc453d18c0315ebf36063 100644 (file)
@@ -51,7 +51,7 @@ void Dropdown::autosize_special(const Part &part, Geometry &ageom) const
 
                unsigned max_w = 0;
                const ListData &data = list.get_data();
-               for(unsigned i=0; i<data.size(); ++i)
+               for(size_t i=0; i<data.size(); ++i)
                {
                        unsigned w = static_cast<unsigned>(font.get_string_width(data.get_string(i))*font_size);
                        max_w = max(max_w, w);
@@ -177,7 +177,7 @@ void Dropdown::resize_list()
        list.set_geometry(lgeom);
 }
 
-void Dropdown::list_item_selected(unsigned index)
+void Dropdown::list_item_selected(size_t index)
 {
        if(dropped)
        {
index c5b535d599bcaae434bb29f0fd53f06f0334890f..3a42d007755a38c6478fc46fbd032224df7e4a0b 100644 (file)
@@ -23,7 +23,7 @@ public:
                void item(const std::string &);
        };
 
-       sigc::signal<void, unsigned> signal_item_selected;
+       sigc::signal<void, std::size_t> signal_item_selected;
 
 private:
        List list;
@@ -68,7 +68,7 @@ private:
        void close_list();
        void list_autosize_changed();
        void resize_list();
-       void list_item_selected(unsigned);
+       void list_item_selected(std::size_t);
        void list_selection_cleared();
 };
 
index b113b2040de556001b5a3e28e631761860eb0909..b212f5f6ecdf66a557ee614b37ca9cf0c1765089 100644 (file)
@@ -51,7 +51,7 @@ void Entry::set_text(const string &t)
        set_edit_position(text.size());
 }
 
-void Entry::insert(unsigned pos, const string &t)
+void Entry::insert(size_t pos, const string &t)
 {
        if(t.empty())
                return;
@@ -66,7 +66,7 @@ void Entry::insert(unsigned pos, const string &t)
        mark_rebuild();
 }
 
-void Entry::erase(unsigned pos, unsigned len)
+void Entry::erase(size_t pos, size_t len)
 {
        if(!len)
                return;
@@ -81,7 +81,7 @@ void Entry::erase(unsigned pos, unsigned len)
        mark_rebuild();
 }
 
-bool Entry::get_selection(unsigned &start, unsigned &end) const
+bool Entry::get_selection(size_t &start, size_t &end) const
 {
        if(!selection_active)
                return false;
@@ -94,12 +94,12 @@ bool Entry::get_selection(unsigned &start, unsigned &end) const
        return true;
 }
 
-void Entry::translate_position(unsigned pos, unsigned &row, unsigned &col) const
+void Entry::translate_position(size_t pos, size_t &row, size_t &col) const
 {
        text.offset_to_coords(pos, row, col);
 }
 
-unsigned Entry::translate_position(unsigned row, unsigned col) const
+size_t Entry::translate_position(size_t row, size_t col) const
 {
        return text.coords_to_offset(row, col);
 }
@@ -139,7 +139,7 @@ void Entry::rebuild_special(const Part &part)
                if(!text_part || !graphic || !graphic->get_texture())
                        return;
 
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
 
                if(row<first_row || row>=first_row+visible_rows)
@@ -160,12 +160,12 @@ void Entry::rebuild_special(const Part &part)
                if(!text_part || !graphic || !graphic->get_texture())
                        return;
 
-               unsigned start, end;
+               size_t start, end;
                get_selection(start, end);
 
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(start, row, col);
-               unsigned end_row, end_col;
+               size_t end_row, end_col;
                text.offset_to_coords(end, end_row, end_col);
 
                if(end_row<first_row || row>=first_row+visible_rows)
@@ -185,7 +185,7 @@ void Entry::rebuild_special(const Part &part)
 
                while(row<=end_row)
                {
-                       unsigned ec = (row==end_row ? end_col : text.get_line_length(row));
+                       size_t ec = (row==end_row ? end_col : text.get_line_length(row));
                        if(ec>col)
                        {
                                Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col);
@@ -234,7 +234,7 @@ bool Entry::key_press(unsigned key, unsigned mod)
                        erase_selection(true);
                else if(edit_pos>0)
                {
-                       unsigned start_pos = text.move_offset(edit_pos, -1);
+                       size_t start_pos = text.move_offset(edit_pos, -1);
                        erase(start_pos, edit_pos-start_pos);
                }
        }
@@ -244,7 +244,7 @@ bool Entry::key_press(unsigned key, unsigned mod)
                        erase_selection(true);
                else
                {
-                       unsigned end_pos = text.move_offset(edit_pos, 1);
+                       size_t end_pos = text.move_offset(edit_pos, 1);
                        erase(edit_pos, end_pos-edit_pos);
                }
        }
@@ -252,25 +252,25 @@ bool Entry::key_press(unsigned key, unsigned mod)
                insert(edit_pos, "\n");
        else if(key==Input::KEY_END)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position(text.coords_to_offset(row, text.get_line_length(row)), mod==MOD_SHIFT);
        }
        else if(key==Input::KEY_HOME)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position(text.coords_to_offset(row, 0), mod==MOD_SHIFT);
        }
        else if(key==Input::KEY_PGUP)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position(text.coords_to_offset((row<visible_rows ? 0 : row-visible_rows), col), mod==MOD_SHIFT);
        }
        else if(key==Input::KEY_PGDN)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position(text.coords_to_offset(row+visible_rows, col), mod==MOD_SHIFT);
        }
@@ -363,13 +363,13 @@ void Entry::move_edit_position(Navigation nav, bool select)
                set_edit_position(text.move_offset(edit_pos, 1), select);
        else if(nav==NAV_DOWN)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position(text.coords_to_offset(row+1, col), select);
        }
        else if(nav==NAV_UP)
        {
-               unsigned row, col;
+               size_t row, col;
                text.offset_to_coords(edit_pos, row, col);
                set_edit_position((row>0 ? text.coords_to_offset(row-1, col) : 0), select);
        }
@@ -377,10 +377,10 @@ void Entry::move_edit_position(Navigation nav, bool select)
                throw invalid_argument("Entry::move_edit_position");
 }
 
-void Entry::adjust_edit_position_for_change(unsigned pos, int change)
+void Entry::adjust_edit_position_for_change(size_t pos, ptrdiff_t change)
 {
-       unsigned old_edit_pos = edit_pos;
-       unsigned old_select_pos = selection_pos;
+       size_t old_edit_pos = edit_pos;
+       size_t old_select_pos = selection_pos;
 
        if(change>0)
        {
@@ -392,35 +392,35 @@ void Entry::adjust_edit_position_for_change(unsigned pos, int change)
        else if(change<0)
        {
                if(edit_pos>=pos)
-                       edit_pos -= min<unsigned>(edit_pos-pos, -change);
+                       edit_pos -= min<size_t>(edit_pos-pos, -change);
                if(selection_active && selection_pos>=pos)
-                       selection_pos -= min<unsigned>(selection_pos-pos, -change);
+                       selection_pos -= min<size_t>(selection_pos-pos, -change);
        }
 
        if(edit_pos!=old_edit_pos)
                signal_edit_position_changed.emit(edit_pos);
        if(selection_active && (edit_pos!=old_edit_pos || selection_pos!=old_select_pos))
        {
-               unsigned start, end;
+               size_t start, end;
                if(get_selection(start, end))
                        signal_selection_changed.emit(start, end);
        }
 }
 
-void Entry::set_edit_position(unsigned ep, bool select)
+void Entry::set_edit_position(size_t ep, bool select)
 {
        bool selection_was_active = selection_active;
        if(select && !selection_active)
                selection_pos = edit_pos;
        selection_active = select;
 
-       unsigned old_edit_pos = edit_pos;
+       size_t old_edit_pos = edit_pos;
        edit_pos = min(ep, text.size());
 
        if(edit_pos!=old_edit_pos)
        {
                signal_edit_position_changed.emit(edit_pos);
-               unsigned start, end;
+               size_t start, end;
                if(get_selection(start, end))
                        signal_selection_changed.emit(start, end);
                else if(selection_was_active)
@@ -434,7 +434,7 @@ void Entry::set_edit_position(unsigned ep, bool select)
 
 void Entry::erase_selection(bool emit_change)
 {
-       unsigned start, end;
+       size_t start, end;
        if(!get_selection(start, end))
                return;
 
@@ -470,16 +470,16 @@ void Entry::check_view_range()
 
        visible_rows = text.get_visible_lines(*text_part, geom, nullptr);
 
-       unsigned row, col;
+       size_t row, col;
        text.offset_to_coords(edit_pos, row, col);
 
-       unsigned old_first_row = first_row;
+       size_t old_first_row = first_row;
        if(first_row>row)
                first_row = row;
        else if(row>=first_row+visible_rows)
                first_row = row+1-visible_rows;
 
-       unsigned scroll = max(text.get_n_lines(), visible_rows)-visible_rows;
+       size_t scroll = max<size_t>(text.get_n_lines(), visible_rows)-visible_rows;
        if(first_row>scroll)
                first_row = scroll;
 
@@ -495,8 +495,8 @@ void Entry::slider_value_changed(double value)
 {
        if(text.get_n_lines()>visible_rows)
        {
-               unsigned old_first_row = first_row;
-               first_row = text.get_n_lines()-visible_rows-static_cast<unsigned>(value);
+               size_t old_first_row = first_row;
+               first_row = text.get_n_lines()-visible_rows-static_cast<size_t>(value);
                if(first_row!=old_first_row)
                        signal_scroll_position_changed.emit(first_row);
                mark_rebuild();
index 0573671abfded057908d9fc320b0671e59a883e4..ee390a0421116df51cc2b701a21249fd26f8faed 100644 (file)
@@ -42,15 +42,15 @@ private:
        bool multiline = false;
        unsigned edit_width = 10;
        unsigned edit_height = 1;
-       unsigned edit_pos = 0;
-       unsigned first_row = 0;
+       std::size_t edit_pos = 0;
+       std::size_t first_row = 0;
        unsigned visible_rows = 1;
        const Part *text_part = nullptr;
        VSlider *slider = nullptr;
        bool got_key_press = false;
        bool cursor_blink = true;
        bool selection_active = false;
-       unsigned selection_pos = 0;
+       std::size_t selection_pos = 0;
 
 public:
        Entry(const std::string & = std::string());
@@ -62,17 +62,17 @@ private:
 
 public:
        void set_text(const std::string &);
-       void insert(unsigned, const std::string &);
-       void erase(unsigned, unsigned);
+       void insert(std::size_t, const std::string &);
+       void erase(std::size_t, std::size_t);
        const std::string &get_text() const { return text.get(); }
 
-       void set_edit_position(unsigned p) { set_edit_position(p, false); }
-       unsigned get_edit_position() const { return edit_pos; }
+       void set_edit_position(std::size_t p) { set_edit_position(p, false); }
+       std::size_t get_edit_position() const { return edit_pos; }
        unsigned get_scroll_position() const { return first_row; }
        unsigned get_visible_rows() const { return visible_rows; }
-       bool get_selection(unsigned &, unsigned &) const;
-       void translate_position(unsigned, unsigned &, unsigned &) const;
-       unsigned translate_position(unsigned, unsigned) const;
+       bool get_selection(std::size_t &, std::size_t &) const;
+       void translate_position(std::size_t, std::size_t &, std::size_t &) const;
+       std::size_t translate_position(std::size_t, std::size_t) const;
 
        /** Sets the minimum size of the editing area, in characters and rows.  This
        only affects autosizing. */
@@ -98,8 +98,8 @@ private:
        void on_style_change() override;
 
        void move_edit_position(Navigation, bool);
-       void adjust_edit_position_for_change(unsigned, int);
-       void set_edit_position(unsigned, bool);
+       void adjust_edit_position_for_change(std::size_t, std::ptrdiff_t);
+       void set_edit_position(std::size_t, bool);
        void erase_selection(bool);
        void check_cursor_blink();
        void check_view_range();
index 095e19441be082aed682be2f4b6a928229cbe7fb..fb3f8893d2460112b88d0b71a6ce6c9790c92b61 100644 (file)
@@ -16,18 +16,18 @@ void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const
        create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u);
        create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v);
 
-       unsigned xmin = border.left ? 0 : 1;
-       unsigned xmax = x.size()-(border.right ? 2 : 3);
-       unsigned ymin = border.bottom ? 0 : 1;
-       unsigned ymax = y.size()-(border.top ? 2 : 3);
+       size_t xmin = border.left ? 0 : 1;
+       size_t xmax = x.size()-(border.right ? 2 : 3);
+       size_t ymin = border.bottom ? 0 : 1;
+       size_t ymax = y.size()-(border.top ? 2 : 3);
 
        bld.color(1.0f, 1.0f, 1.0f);
-       for(unsigned i=ymin; i<=ymax; ++i)
+       for(size_t i=ymin; i<=ymax; ++i)
        {
-               unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
-               for(unsigned j=xmin; j<=xmax; ++j)
+               size_t i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
+               for(size_t j=xmin; j<=xmax; ++j)
                {
-                       unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
+                       size_t j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
                        if(j==xmin || (j>1 && j<x.size()-2))
                        {
                                if(j>xmin)
index c8631cf84bc6d6b6e8ed4ac714a2c9dac1e44213..eb32cc91d8c4ec2f0c757d36b8f2ceb8f7d3cdea 100644 (file)
@@ -3,7 +3,7 @@
 namespace Msp {
 namespace GLtk {
 
-Grid::Grid(Layout &l, unsigned c):
+Grid::Grid(Layout &l, size_t c):
        Arrangement(l),
        columns(c)
 { }
index 4ed43d56442f59d0b475ba7b3cf6fd097b676225..be1c2661c9c8533846c6a440dfedfe4ccbd8a9c4 100644 (file)
@@ -31,10 +31,10 @@ private:
        Edge row_top;
        Edge row_bottom;
        bool first_row = true;
-       unsigned column = 0;
+       std::size_t column = 0;
 
 public:
-       Grid(Layout &, unsigned);
+       Grid(Layout &, std::size_t);
 
        void skip();
        void next_row();
index 4d6b6643a3c630bb99e5c54a25c02e5eb30fff9d..e9461b5eddf855e72fed34b8e6b4fa31bd90eefa 100644 (file)
@@ -19,44 +19,44 @@ public:
        {
        private:
                LinearProgram &linprog;
-               unsigned index;
+               size_t index;
 
        public:
-               Row(LinearProgram &, unsigned);
+               Row(LinearProgram &, size_t);
 
-               float &operator[](unsigned);
+               float &operator[](size_t);
                float &back();
        };
 
 private:
        struct Column
        {
-               unsigned basic;
+               size_t basic;
                std::vector<float> values;
 
                Column();
        };
 
-       unsigned n_columns = 1;
-       unsigned n_rows = 1;
+       size_t n_columns = 1;
+       size_t n_rows = 1;
        std::vector<Column> columns;
        bool solved = false;
        bool infeasible = false;
 
 public:
-       LinearProgram(unsigned);
+       LinearProgram(size_t);
 
        Row add_row();
-       Row operator[](unsigned);
+       Row operator[](size_t);
        Row get_objective_row();
-       float get_variable(unsigned);
+       float get_variable(size_t);
        bool solve();
 private:
        void prepare_columns();
        void add_artificial_variables();
        void remove_artificial_variables();
-       unsigned find_minimal_ratio(unsigned);
-       void make_basic_column(unsigned, unsigned);
+       size_t find_minimal_ratio(size_t);
+       void make_basic_column(size_t, size_t);
        bool pivot();
 };
 
@@ -199,7 +199,7 @@ void Layout::remove_widget(Widget &wdg)
 void Layout::update_slot_indices()
 {
        n_active_slots = 0;
-       unsigned n_floating = 0;
+       size_t n_floating = 0;
        for(Slot *s: slots)
        {
                if(s->widget.is_visible() || s->ghost)
@@ -351,7 +351,7 @@ void Layout::solve_constraints(int dir, SolveMode mode)
        remaining three are slack columns; see below for their purposes. */
        LinearProgram linprog(n_active_slots*5+n_slack_vars[dir]+1);
        float weight = slots.size()+1;
-       unsigned k = n_active_slots*5;
+       size_t k = n_active_slots*5;
        for(const Slot *s: slots)
        {
                if(s->index<0)
@@ -624,7 +624,7 @@ void operator>>(const LexicalConverter &conv, Layout::ConstraintType &ctype)
 }
 
 
-Layout::LinearProgram::LinearProgram(unsigned s):
+Layout::LinearProgram::LinearProgram(size_t s):
        n_columns(s),
        columns(n_columns)
 { }
@@ -634,7 +634,7 @@ Layout::LinearProgram::Row Layout::LinearProgram::add_row()
        return Row(*this, n_rows++);
 }
 
-Layout::LinearProgram::Row Layout::LinearProgram::operator[](unsigned r)
+Layout::LinearProgram::Row Layout::LinearProgram::operator[](size_t r)
 {
        if(r>=n_rows)
                throw out_of_range("LinearProgram::operator[]");
@@ -647,14 +647,14 @@ Layout::LinearProgram::Row Layout::LinearProgram::get_objective_row()
        return Row(*this, 0);
 }
 
-float Layout::LinearProgram::get_variable(unsigned i)
+float Layout::LinearProgram::get_variable(size_t i)
 {
        if(!solved || infeasible)
                throw logic_error("not solved");
        if(i+1>=n_columns)
                throw out_of_range("LinearProgram::get_variable");
 
-       if(unsigned r = columns[i].basic)
+       if(size_t r = columns[i].basic)
                return columns.back().values[r];
        else
                return 0;
@@ -707,7 +707,7 @@ void Layout::LinearProgram::prepare_columns()
                if(c.values.size()>=2 && c.values.back()!=0.0f && (constants.size()<c.values.size() || c.values.back()*constants[c.values.size()-1]>=0.0f) && obj_coeff[c.values.size()-1]==0.0f)
                {
                        bool basic = true;
-                       for(unsigned j=1; (basic && j+1<c.values.size()); ++j)
+                       for(size_t j=1; (basic && j+1<c.values.size()); ++j)
                                basic = (c.values[j]==0.0f);
                        if(basic)
                        {
@@ -722,7 +722,7 @@ void Layout::LinearProgram::prepare_columns()
        for(Column &c: columns)
                if(!c.values.empty())
                {
-                       for(unsigned j=0; j<c.values.size(); ++j)
+                       for(size_t j=0; j<c.values.size(); ++j)
                        {
                                c.values[j] *= row_coeff[j];
                                c.values.front() += obj_coeff[j]*c.values[j];
@@ -732,8 +732,8 @@ void Layout::LinearProgram::prepare_columns()
 
 void Layout::LinearProgram::add_artificial_variables()
 {
-       vector<unsigned> artificial_rows(n_rows-1);
-       for(unsigned i=0; i<artificial_rows.size(); ++i)
+       vector<size_t> artificial_rows(n_rows-1);
+       for(size_t i=0; i<artificial_rows.size(); ++i)
                artificial_rows[i] = i+1;
 
        for(const Column &c: columns)
@@ -752,7 +752,7 @@ void Layout::LinearProgram::add_artificial_variables()
                        {
                                objective = c.values.front();
                                c.values.front() = 0.0f;
-                               for(unsigned r: artificial_rows)
+                               for(size_t r: artificial_rows)
                                        if(r<c.values.size())
                                                c.values.front() += c.values[r];
                        }
@@ -769,7 +769,7 @@ void Layout::LinearProgram::add_artificial_variables()
        columns.resize(n_columns+artificial_rows.size());
        columns.back() = columns[n_columns-1];
        columns[n_columns-1].values.clear();
-       for(unsigned i=0; i<artificial_rows.size(); ++i)
+       for(size_t i=0; i<artificial_rows.size(); ++i)
                columns[n_columns+i-1].basic = artificial_rows[i];
 }
 
@@ -780,10 +780,10 @@ void Layout::LinearProgram::remove_artificial_variables()
        some of the original variables basic instead.
 
        I don't fully understand why this is needed, but it appears to work. */
-       for(unsigned i=n_columns-1; i+1<columns.size(); ++i)
+       for(size_t i=n_columns-1; i+1<columns.size(); ++i)
                if(columns[i].basic && columns.back().values[columns[i].basic]==0.0f)
                {
-                       for(unsigned j=0; j+1<n_columns; ++j)
+                       for(size_t j=0; j+1<n_columns; ++j)
                                if(!columns[j].basic && columns[j].values[columns[i].basic]!=0.0f)
                                {
                                        make_basic_column(j, columns[i].basic);
@@ -802,7 +802,7 @@ void Layout::LinearProgram::remove_artificial_variables()
                }
 }
 
-unsigned Layout::LinearProgram::find_minimal_ratio(unsigned c)
+size_t Layout::LinearProgram::find_minimal_ratio(size_t c)
 {
        /* Pick the row with the minimum ratio between the constant column and the
        pivot column.  This ensures that when the pivot column is made basic, values
@@ -811,8 +811,8 @@ unsigned Layout::LinearProgram::find_minimal_ratio(unsigned c)
        The use of n_rows instead of the true size of the column is intentional,
        since the relocated objective row must be ignored in phase 1. */
        float best = numeric_limits<float>::infinity();
-       unsigned row = 0;
-       for(unsigned i=1; i<n_rows; ++i)
+       size_t row = 0;
+       for(size_t i=1; i<n_rows; ++i)
                if(columns[c].values[i]>0)
                {
                        float ratio = columns.back().values[i]/columns[c].values[i];
@@ -826,11 +826,11 @@ unsigned Layout::LinearProgram::find_minimal_ratio(unsigned c)
        return row;
 }
 
-void Layout::LinearProgram::make_basic_column(unsigned c, unsigned r)
+void Layout::LinearProgram::make_basic_column(size_t c, size_t r)
 {
        /* Perform row transfer operations to make the pivot column basic,
        containing a 1 on the pivot row. */
-       for(unsigned i=0; i<columns.size(); ++i)
+       for(size_t i=0; i<columns.size(); ++i)
                if(i!=c && (columns[i].basic==r || (!columns[i].basic && columns[i].values[r])))
                {
                        if(columns[i].basic)
@@ -843,7 +843,7 @@ void Layout::LinearProgram::make_basic_column(unsigned c, unsigned r)
                        float scale = columns[i].values[r]/columns[c].values[r];
 
                        columns[i].values[r] = scale;
-                       for(unsigned j=0; j<columns[i].values.size(); ++j)
+                       for(size_t j=0; j<columns[i].values.size(); ++j)
                                if(j!=r)
                                        columns[i].values[j] -= scale*columns[c].values[j];
                }
@@ -857,9 +857,9 @@ bool Layout::LinearProgram::pivot()
        /* Pick a nonbasic column and make it basic.  Requiring a positive objective
        coefficient ensures that the objective function's value will decrease in the
        process. */
-       for(unsigned i=0; i+1<columns.size(); ++i)
+       for(size_t i=0; i+1<columns.size(); ++i)
                if(!columns[i].basic && columns[i].values.front()>0)
-                       if(unsigned row = find_minimal_ratio(i))
+                       if(size_t row = find_minimal_ratio(i))
                        {
                                make_basic_column(i, row);
                                return true;
@@ -869,12 +869,12 @@ bool Layout::LinearProgram::pivot()
 }
 
 
-Layout::LinearProgram::Row::Row(LinearProgram &lp, unsigned i):
+Layout::LinearProgram::Row::Row(LinearProgram &lp, size_t i):
        linprog(lp),
        index(i)
 { }
 
-float &Layout::LinearProgram::Row::operator[](unsigned c)
+float &Layout::LinearProgram::Row::operator[](size_t c)
 {
        if(c>=linprog.n_columns)
                throw out_of_range("Row::operator[]");
index 14def25e718bc83e00f28d975ad4b08ba7945c29..2e58505881c351856c0bc0aedc015da5a984f439 100644 (file)
@@ -174,8 +174,8 @@ private:
 
        Container *container = nullptr;
        std::vector<Slot *> slots;
-       unsigned n_active_slots = 0;
-       unsigned n_slack_vars[2] = { 0, 0 };
+       std::size_t n_active_slots = 0;
+       std::size_t n_slack_vars[2] = { 0, 0 };
        Sides margin{ 8 };
        unsigned row_spacing = 5;
        unsigned col_spacing = 4;
index 963b442775f982840f27b6d796437f02227e9fac..4b6854f72a91fd5cf1785af6adf2a76b70dc1b25 100644 (file)
@@ -53,7 +53,7 @@ void List::autosize_special(const Part &part, Geometry &ageom) const
 
                unsigned items_w = 0;
                unsigned items_h = 0;
-               for(unsigned i=0; i<items.size(); ++i)
+               for(size_t i=0; i<items.size(); ++i)
                {
                        Geometry igeom;
                        items[i]->autosize(igeom);
@@ -100,8 +100,8 @@ void List::set_data(ListData &d)
        for(Item *i: items)
                delete i;
        items.clear();
-       unsigned n_items = data->size();
-       for(unsigned i=0; i<n_items; ++i)
+       size_t n_items = data->size();
+       for(size_t i=0; i<n_items; ++i)
        {
                Item *item = create_item(i);
                items.push_back(item);
@@ -116,14 +116,14 @@ void List::items_changed()
        mark_rebuild();
 }
 
-List::Item *List::create_item(unsigned index)
+List::Item *List::create_item(size_t index)
 {
        Item *item = nullptr;
        if(item_factory)
                item = item_factory->create_item(index);
        else
                item = new BasicItem(data->get_string(index));
-       if(static_cast<int>(index)==sel_index)
+       if(index==sel_index)
                item->set_active(true);
        add(*item);
        item->autosize();
@@ -148,27 +148,26 @@ void List::set_view_all()
        set_view_size(0);
 }
 
-void List::set_selected_index(int i)
+void List::set_selected_index(size_t i)
 {
-       if(i>=static_cast<int>(data->size()))
+       if(i>=data->size() && i!=INVALID_INDEX)
                throw out_of_range("List::set_selected_index");
 
-       if(i==sel_index || (i<0 && sel_index<0))
+       if(i==sel_index)
                return;
 
-       if(sel_index>=0)
+       if(sel_index!=INVALID_INDEX)
                items[sel_index]->set_active(false);
-       if(i<0)
+
+       sel_index = i;
+       focus_index = i;
+       if(i==INVALID_INDEX)
        {
-               sel_index = -1;
-               focus_index = -1;
                set_input_focus(nullptr);
                signal_selection_cleared.emit();
        }
        else
        {
-               sel_index = i;
-               focus_index = i;
                items[sel_index]->set_active(true);
                if(state&FOCUS)
                        set_input_focus(items[focus_index]);
@@ -178,7 +177,7 @@ void List::set_selected_index(int i)
 
 void List::set_selected_item(Widget *item)
 {
-       for(unsigned i=rows[first_row].first; (i<items.size() && items[i]->is_visible()); ++i)
+       for(size_t i=rows[first_row].first; (i<items.size() && items[i]->is_visible()); ++i)
                if(item==items[i])
                        return set_selected_index(i);
 }
@@ -191,8 +190,8 @@ void List::rebuild_special(const Part &part)
        {
                SetFlag flag(ignore_slider_change);
                reposition_items(true);
-               unsigned old_first_row = first_row;
-               unsigned old_max_scroll = max_scroll;
+               size_t old_first_row = first_row;
+               size_t old_max_scroll = max_scroll;
                check_view_range();
                if(first_row!=old_first_row || max_scroll!=old_max_scroll)
                        reposition_items(false);
@@ -205,7 +204,7 @@ void List::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="items")
        {
-               for(unsigned i=rows[first_row].first; (i<items.size() && items[i]->is_visible()); ++i)
+               for(size_t i=rows[first_row].first; (i<items.size() && items[i]->is_visible()); ++i)
                        items[i]->render(renderer);
        }
        else if(part.get_name()=="slider")
@@ -228,7 +227,7 @@ void List::button_press(int x, int y, unsigned btn)
 {
        if(btn==4 || btn==5)
        {
-               unsigned change = 3;
+               size_t change = 3;
                if(btn==4)
                {
                        change = min(first_row, change);
@@ -305,11 +304,11 @@ void List::touch_motion(int, int y, unsigned finger)
 void List::focus_in()
 {
        Container::focus_in();
-       if(focus_index>=0 && items[focus_index]->is_visible())
+       if(focus_index!=INVALID_INDEX && items[focus_index]->is_visible())
                set_input_focus(items[focus_index]);
        else
        {
-               if(sel_index>=0 && items[sel_index]->is_visible())
+               if(sel_index!=INVALID_INDEX && items[sel_index]->is_visible())
                        set_focus_index(sel_index);
                else if(!items.empty())
                        set_focus_index(rows[first_row].first);
@@ -337,7 +336,7 @@ void List::move_focus(Navigation nav, bool select)
 {
        if(nav==NAV_UP && view_mode==GRID)
        {
-               unsigned row = item_index_to_row(focus_index);
+               size_t row = item_index_to_row(focus_index);
                if(row>0)
                        set_focus_index(rows[row-1].first+focus_index-rows[row].first);
                else
@@ -345,7 +344,7 @@ void List::move_focus(Navigation nav, bool select)
        }
        else if(nav==NAV_DOWN && view_mode==GRID)
        {
-               unsigned row = item_index_to_row(focus_index);
+               size_t row = item_index_to_row(focus_index);
                if(row+1<rows.size())
                        set_focus_index(rows[row+1].first+focus_index-rows[row].first);
                else
@@ -358,7 +357,7 @@ void List::move_focus(Navigation nav, bool select)
        }
        else if(nav==NAV_DOWN || (nav==NAV_RIGHT && view_mode==GRID))
        {
-               if(static_cast<unsigned>(focus_index+1)<items.size())
+               if(focus_index+1<items.size())
                        set_focus_index(focus_index+1);
        }
 
@@ -366,10 +365,10 @@ void List::move_focus(Navigation nav, bool select)
                set_selected_index(focus_index);
 }
 
-void List::set_focus_index(int i)
+void List::set_focus_index(size_t i)
 {
        focus_index = i;
-       if(focus_index>=0)
+       if(focus_index!=INVALID_INDEX)
        {
                scroll_to_focus();
                if(state&FOCUS)
@@ -400,7 +399,7 @@ void List::reposition_items(bool record_rows)
        unsigned x = 0;
        unsigned y = 0;
        unsigned row_h = 0;
-       for(unsigned i=0; i<items.size(); ++i)
+       for(size_t i=0; i<items.size(); ++i)
        {
                const Geometry &igeom = items[i]->get_geometry();
 
@@ -430,7 +429,7 @@ void List::reposition_items(bool record_rows)
                }
                else
                {
-                       for(unsigned j=rows.back().first; j<=i; ++j)
+                       for(size_t j=rows.back().first; j<=i; ++j)
                                items[j]->set_visible(false);
                        y = 0;
                }
@@ -443,7 +442,7 @@ void List::reposition_items(bool record_rows)
                rows.back().height = row_h;
 }
 
-unsigned List::last_to_first_row(unsigned last) const
+size_t List::last_to_first_row(size_t last) const
 {
        if(!items_part)
                return last;
@@ -452,7 +451,7 @@ unsigned List::last_to_first_row(unsigned last) const
        unsigned view_h = geom.h-min(geom.h, margin.top+margin.bottom);
 
        unsigned items_h = 0;
-       for(unsigned i=last; i<rows.size(); --i)
+       for(size_t i=last; i<rows.size(); --i)
        {
                items_h += rows[i].height;
                if(items_h>view_h)
@@ -462,9 +461,9 @@ unsigned List::last_to_first_row(unsigned last) const
        return 0;
 }
 
-unsigned List::item_index_to_row(unsigned index) const
+size_t List::item_index_to_row(size_t index) const
 {
-       for(unsigned i=0; i+1<rows.size(); ++i)
+       for(size_t i=0; i+1<rows.size(); ++i)
                if(rows[i+1].first>index)
                        return i;
        return rows.size()-1;
@@ -490,10 +489,10 @@ void List::check_view_range()
 
 void List::scroll_to_focus()
 {
-       if(focus_index<0 || items[focus_index]->is_visible())
+       if(focus_index==INVALID_INDEX || items[focus_index]->is_visible())
                return;
 
-       unsigned focus_row = item_index_to_row(static_cast<unsigned>(focus_index));
+       size_t focus_row = item_index_to_row(focus_index);
        if(focus_row<first_row)
                slider.set_value(max_scroll-focus_row);
        else
@@ -504,17 +503,19 @@ void List::slider_value_changed(double value)
 {
        if(max_scroll>0 && !ignore_slider_change)
        {
-               first_row = max_scroll-static_cast<unsigned>(value);
+               first_row = max_scroll-static_cast<size_t>(value);
                mark_rebuild();
        }
 }
 
-void List::adjust_index(int &index, int pos, int change)
+void List::adjust_index(size_t &index, size_t pos, ptrdiff_t change)
 {
-       if(index>pos)
+       if(index==INVALID_INDEX)
+               return;
+       else if(index>pos)
                index += change;
        else if(index==pos)
-               index = (change>0 ? index+change : -1);
+               index = (change>0 ? index+change : INVALID_INDEX);
 }
 
 
@@ -527,7 +528,7 @@ List::DataObserver::DataObserver(List &l):
        list.data->signal_refresh_item.connect(sigc::mem_fun(this, &DataObserver::refresh_item));
 }
 
-void List::DataObserver::item_added(unsigned i)
+void List::DataObserver::item_added(size_t i)
 {
        adjust_index(list.sel_index, i, 1);
        adjust_index(list.focus_index, i, 1);
@@ -537,9 +538,9 @@ void List::DataObserver::item_added(unsigned i)
        list.items_changed();
 }
 
-void List::DataObserver::item_removed(unsigned i)
+void List::DataObserver::item_removed(size_t i)
 {
-       bool had_selection = (list.sel_index>=0);
+       bool had_selection = (list.sel_index!=INVALID_INDEX);
        adjust_index(list.sel_index, i, -1);
        adjust_index(list.focus_index, i, -1);
 
@@ -547,14 +548,14 @@ void List::DataObserver::item_removed(unsigned i)
        list.items.erase(list.items.begin()+i);
        list.items_changed();
 
-       if(had_selection && list.sel_index<0)
+       if(had_selection && list.sel_index==INVALID_INDEX)
                list.signal_selection_cleared.emit();
 }
 
 void List::DataObserver::cleared()
 {
-       list.sel_index = -1;
-       list.focus_index = -1;
+       list.sel_index = INVALID_INDEX;
+       list.focus_index = INVALID_INDEX;
        for(Item *i: list.items)
                delete i;
        list.items.clear();
@@ -563,7 +564,7 @@ void List::DataObserver::cleared()
        list.signal_selection_cleared.emit();
 }
 
-void List::DataObserver::refresh_item(unsigned i)
+void List::DataObserver::refresh_item(size_t i)
 {
        delete list.items[i];
        // Avoid stale pointer while create_item is executing
@@ -628,7 +629,7 @@ void List::MultiColumnItem::check_widths(vector<unsigned> &widths) const
        if(widths.size()<children.size())
                widths.resize(children.size(), 0);
 
-       unsigned n = 0;
+       size_t n = 0;
        for(const Child *c: children)
        {
                Geometry cgeom;
@@ -650,7 +651,7 @@ void List::MultiColumnItem::set_widths(const vector<unsigned> &widths)
 
        const Sides &margin = part->get_margin();
        int x = margin.left;
-       unsigned n = 0;
+       size_t n = 0;
        for(const Child *c: children)
        {
                c->widget->set_position(x, margin.bottom);
@@ -676,7 +677,7 @@ void List::MultiColumnItem::on_style_change()
        vector<unsigned> self_widths(widths);
        check_widths(self_widths);
        bool update_all = false;
-       for(unsigned i=0; (!update_all && i<widths.size() && i<self_widths.size()); ++i)
+       for(size_t i=0; (!update_all && i<widths.size() && i<self_widths.size()); ++i)
                update_all = self_widths[i]>widths[i];
 
        if(update_all)
index 060fb813f405cc9b29fb762c8a5ac93e7feedc61..0938eaf05ee162a59c8407a3d38b9e0765237177 100644 (file)
@@ -36,6 +36,8 @@ public:
                GRID
        };
 
+       static constexpr size_t INVALID_INDEX = std::numeric_limits<size_t>::max();
+
        class Loader: public DataFile::DerivedObjectLoader<List, Widget::Loader>
        {
        public:
@@ -54,10 +56,10 @@ private:
        public:
                DataObserver(List &);
 
-               void item_added(unsigned);
-               void item_removed(unsigned);
+               void item_added(std::size_t);
+               void item_removed(std::size_t);
                void cleared();
-               void refresh_item(unsigned);
+               void refresh_item(std::size_t);
        };
 
 public:
@@ -114,7 +116,7 @@ private:
                virtual ~ItemFactory() = default;
 
                virtual void set_data(const ListData &) = 0;
-               virtual Item *create_item(unsigned) const = 0;
+               virtual Item *create_item(std::size_t) const = 0;
        };
 
        template<typename I>
@@ -137,7 +139,7 @@ private:
                                throw incompatible_data(typeid(ValueType));
                }
 
-               Item *create_item(unsigned i) const override
+               Item *create_item(std::size_t i) const override
                {
                        return new I(data->get(i));
                }
@@ -145,14 +147,14 @@ private:
 
        struct Row
        {
-               unsigned first;
+               std::size_t first;
                unsigned height;
 
-               Row(unsigned f): first(f), height(0) { }
+               Row(std::size_t f): first(f), height(0) { }
        };
 
 public:
-       sigc::signal<void, unsigned> signal_item_selected;
+       sigc::signal<void, std::size_t> signal_item_selected;
        sigc::signal<void> signal_selection_cleared;
 
 private:
@@ -161,10 +163,10 @@ private:
        DataObserver *observer = nullptr;
        ItemFactory *item_factory = nullptr;
        ViewMode view_mode = LIST;
-       int sel_index = -1;
-       int focus_index = -1;
-       unsigned first_row = 0;
-       unsigned max_scroll = 0;
+       std::size_t sel_index = INVALID_INDEX;
+       std::size_t focus_index = INVALID_INDEX;
+       std::size_t first_row = 0;
+       std::size_t max_scroll = 0;
        unsigned view_rows = 5;
        unsigned view_columns = 5;
        const Part *items_part = nullptr;
@@ -203,7 +205,7 @@ public:
                item_factory = f;
        }
 private:
-       Item *create_item(unsigned);
+       Item *create_item(std::size_t);
 
 public:
        void set_view_mode(ViewMode);
@@ -211,7 +213,7 @@ public:
        void set_view_size(unsigned, unsigned);
        void set_view_all();
 
-       void set_selected_index(int);
+       void set_selected_index(std::size_t);
        int get_selected_index() const { return sel_index; }
 private:
        void set_selected_item(Widget *);
@@ -231,16 +233,16 @@ private:
        void on_style_change() override;
 
        void move_focus(Navigation, bool);
-       void set_focus_index(int);
+       void set_focus_index(std::size_t);
 
        void item_autosize_changed(Item *);
        void reposition_items(bool);
-       unsigned last_to_first_row(unsigned) const;
-       unsigned item_index_to_row(unsigned) const;
+       std::size_t last_to_first_row(std::size_t) const;
+       std::size_t item_index_to_row(std::size_t) const;
        void check_view_range();
        void scroll_to_focus();
        void slider_value_changed(double);
-       static void adjust_index(int &, int, int);
+       static void adjust_index(std::size_t &, std::size_t, std::ptrdiff_t);
 };
 
 MSPGLTK_API void operator>>(const LexicalConverter &, List::ViewMode &);
index 77be5ee7b8e1cb52200936eb05d85ddc0b8cc3c4..cd4fb9a3f96b6c52e18b4804eadeb4ade61c8d0b 100644 (file)
@@ -14,19 +14,19 @@ namespace GLtk {
 class MSPGLTK_API ListData
 {
 public:
-       sigc::signal<void, unsigned> signal_item_added;
-       sigc::signal<void, unsigned> signal_item_removed;
+       sigc::signal<void, std::size_t> signal_item_added;
+       sigc::signal<void, std::size_t> signal_item_removed;
        sigc::signal<void> signal_cleared;
-       sigc::signal<void, unsigned> signal_refresh_item;
+       sigc::signal<void, std::size_t> signal_refresh_item;
 
 protected:
        ListData() = default;
 public:
        virtual ~ListData() = default;
 
-       virtual unsigned size() const = 0;
-       virtual std::string get_string(unsigned) const = 0;
-       void refresh(unsigned i) const
+       virtual std::size_t size() const = 0;
+       virtual std::string get_string(std::size_t) const = 0;
+       void refresh(std::size_t i) const
        {
                if(i>=size())
                        throw std::out_of_range("ListData::refresh");
@@ -45,7 +45,7 @@ protected:
 public:
        void append(const T &v) { insert(items.size(), v); }
 
-       void insert(unsigned i, const T &v)
+       void insert(std::size_t i, const T &v)
        {
                if(i>items.size())
                        throw std::out_of_range("ListDataStore::insert");
@@ -54,7 +54,7 @@ public:
                signal_item_added.emit(i);
        }
 
-       const T &get(unsigned i) const
+       const T &get(std::size_t i) const
        {
                if(i>=items.size())
                        throw std::out_of_range("ListDataStore::get");
@@ -62,23 +62,23 @@ public:
                return items[i];
        }
 
-       int find(const T &v) const
+       std::size_t find(const T &v) const
        {
-               for(unsigned i=0; i<items.size(); ++i)
+               for(std::size_t i=0; i<items.size(); ++i)
                        if(items[i]==v)
                                return i;
-               return -1;
+               return std::numeric_limits<std::size_t>::max();
        }
 
        using ListData::refresh;
        void refresh(const T &v) const
        {
-               int i = find(v);
-               if(i>=0)
+               std::size_t i = find(v);
+               if(i<items.size())
                        signal_refresh_item.emit(i);
        }
 
-       void remove(unsigned i)
+       void remove(std::size_t i)
        {
                if(i>=items.size())
                        throw std::out_of_range("ListDataStore::remove");
@@ -93,14 +93,14 @@ public:
                signal_cleared.emit();
        }
 
-       unsigned size() const override { return items.size(); }
+       std::size_t size() const override { return items.size(); }
 };
 
 template<typename T>
 class BasicListData: public ListDataStore<T>
 {
 public:
-       virtual std::string get_string(unsigned i) const
+       virtual std::string get_string(std::size_t i) const
        { return lexical_cast<std::string>(this->get(i)); }
 };
 
@@ -116,7 +116,7 @@ private:
 public:
        FunctionListData(Func f): func(f) { }
 
-       std::string get_string(unsigned i) const override
+       std::string get_string(std::size_t i) const override
        { return func(this->get(i)); }
 };
 
index 155682616f44245bbe9ff5dbeb9f46f56a55552d..31cdf4b4ff9e62fa306fa0848c0879046e79aa56 100644 (file)
@@ -288,7 +288,7 @@ void Panel::Loader::gravity(int h, int v)
        get_layout().set_gravity(get_last_widget(), h, v);
 }
 
-void Panel::Loader::grid(unsigned cols)
+void Panel::Loader::grid(size_t cols)
 {
        Grid grd(get_layout(), cols);
        ArrangedLoader<Grid> ldr(*this, grd);
index ce4b2a740073dc2b2eb743578d1631e38e477f67..e9744fd107a273c12365a86d11cec545228109d6 100644 (file)
@@ -46,7 +46,7 @@ public:
                void expand(bool, bool);
                void ghost(bool);
                void gravity(int, int);
-               void grid(unsigned);
+               void grid(std::size_t);
                void layout();
                template<typename T>
                void unnamed_child();
index 29f906766ea52c087bb25a707ebc248677aa456a..b860d7d8410af507729487bfc45723eb804b20e1 100644 (file)
@@ -22,7 +22,7 @@ void Slider::set_value(double v)
                value = max;
        else
        {
-               unsigned steps = static_cast<unsigned>((v-min)/step+0.5);
+               double steps = round((v-min)/step);
                value = min+steps*step;
        }
 
index 166bbb5212c7145fbc1c39bbfccf44cf7441354f..2e4d9cb88f4c5c0394b2edf137866dc14cbb295f 100644 (file)
@@ -18,8 +18,8 @@ struct Text::RenderData
 
 struct Text::CoordsToGeomData
 {
-       unsigned row;
-       unsigned col;
+       size_t row;
+       size_t col;
        Geometry result;
 };
 
@@ -80,7 +80,7 @@ void Text::set(const string &t)
        find_lines();
 }
 
-void Text::erase(unsigned pos, unsigned len)
+void Text::erase(size_t pos, size_t len)
 {
        check_alignment(pos);
        check_alignment(pos+len);
@@ -100,7 +100,7 @@ void Text::erase(unsigned pos, unsigned len)
        }
 }
 
-void Text::insert(unsigned pos, const string &s)
+void Text::insert(size_t pos, const string &s)
 {
        check_alignment(pos);
        text.insert(pos, s);
@@ -119,7 +119,7 @@ void Text::insert(unsigned pos, const string &s)
        }
 }
 
-unsigned Text::get_visible_lines(const Part &part, const Geometry &parent, unsigned *fit_height) const
+size_t 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();
@@ -129,21 +129,21 @@ unsigned Text::get_visible_lines(const Part &part, const Geometry &parent, unsig
        const Sides &margin = part.get_margin();
        unsigned vmargin = margin.top+margin.bottom;
        unsigned free_height = max(parent.h, vmargin)-vmargin+line_spacing-line_height;
-       unsigned n_lines = min<unsigned>(lines.size(), max(free_height/line_spacing, 1U));
+       size_t n_lines = min<size_t>(lines.size(), max(free_height/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
+size_t Text::get_line_length(size_t i) const
 {
        if(i>=lines.size())
                throw out_of_range("Text::get_line_length");
        return lines[i].length;
 }
 
-unsigned Text::move_offset(unsigned offs, int change) const
+size_t Text::move_offset(size_t offs, ptrdiff_t change) const
 {
        check_alignment(offs);
        if(!change)
@@ -169,7 +169,7 @@ unsigned Text::move_offset(unsigned offs, int change) const
        return i-text.begin();
 }
 
-void Text::offset_to_coords(unsigned offs, unsigned &row, unsigned &col) const
+void Text::offset_to_coords(size_t offs, size_t &row, size_t &col) const
 {
        if(lines.empty())
        {
@@ -178,7 +178,7 @@ void Text::offset_to_coords(unsigned offs, unsigned &row, unsigned &col) const
                return;
        }
 
-       for(unsigned i=0; i<lines.size(); ++i)
+       for(size_t i=0; i<lines.size(); ++i)
                if(offs>=lines[i].start && offs<=lines[i].start+lines[i].bytes)
                {
                        row = i;
@@ -190,7 +190,7 @@ void Text::offset_to_coords(unsigned offs, unsigned &row, unsigned &col) const
                }
 }
 
-unsigned Text::coords_to_offset(unsigned row, unsigned col) const
+size_t Text::coords_to_offset(size_t row, size_t col) const
 {
        if(row>=lines.size())
                return text.size();
@@ -210,7 +210,7 @@ unsigned Text::coords_to_offset(unsigned row, unsigned col) const
        }
 }
 
-Geometry Text::coords_to_geometry(const Part &part, const Geometry &parent, unsigned first_row, unsigned row, unsigned col) const
+Geometry Text::coords_to_geometry(const Part &part, const Geometry &parent, size_t first_row, size_t row, size_t col) const
 {
        if(row>=lines.size())
                row = lines.size()-1;
@@ -232,7 +232,7 @@ void Text::build(const Part &part, State state, const Geometry &parent, PartCach
        build(part, state, parent, 0, cache);
 }
 
-void Text::build(const Part &part, State state, const Geometry &parent, unsigned first_row, PartCache &cache) const
+void Text::build(const Part &part, State state, const Geometry &parent, size_t first_row, PartCache &cache) const
 {
        if(!style || lines.empty())
                return;
@@ -280,18 +280,18 @@ void Text::find_lines()
        }
 }
 
-unsigned Text::count_characters(unsigned start, unsigned bytes) const
+size_t Text::count_characters(size_t start, size_t bytes) const
 {
        StringCodec::Utf8::Decoder dec;
        auto i = text.begin()+start;
        auto end = i+bytes;
-       unsigned count = 0;
+       size_t count = 0;
        for(; i<end; dec.decode_char(text, i))
                ++count;
        return count;
 }
 
-void Text::check_alignment(unsigned offs) const
+void Text::check_alignment(size_t offs) const
 {
        StringCodec::Utf8::Decoder dec;
        auto i = text.begin()+offs;
@@ -299,7 +299,7 @@ void Text::check_alignment(unsigned offs) const
 }
 
 template<typename T>
-void Text::process_lines(const Part &part, const Geometry &parent, unsigned first_row, void (Text::*func)(unsigned, const Geometry &, T &) const, T &data) const
+void Text::process_lines(const Part &part, const Geometry &parent, size_t first_row, void (Text::*func)(size_t, const Geometry &, T &) const, T &data) const
 {
        if(!style)
                return;
@@ -310,10 +310,10 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs
        int y_offset = static_cast<int>(-font.get_descent()*font_size);
 
        unsigned fit_height;
-       unsigned n_lines = get_visible_lines(part, parent, &fit_height);
-       first_row = min<unsigned>(first_row, lines.size()-n_lines);
+       size_t n_lines = get_visible_lines(part, parent, &fit_height);
+       first_row = min(first_row, lines.size()-n_lines);
 
-       for(unsigned i=0; i<n_lines; ++i)
+       for(size_t i=0; i<n_lines; ++i)
        {
                const Line &line = lines[first_row+i];
 
@@ -327,7 +327,7 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs
        }
 }
 
-void Text::build_line(unsigned i, const Geometry &rgeom, RenderData &data) const
+void Text::build_line(size_t i, const Geometry &rgeom, RenderData &data) const
 {
        const Line &line = lines[i];
 
@@ -338,7 +338,7 @@ void Text::build_line(unsigned i, const Geometry &rgeom, RenderData &data) const
        style->get_font().build_string(text.substr(line.start, line.bytes), *data.bld);
 }
 
-void Text::coords_to_geom_line(unsigned i, const Geometry &rgeom, CoordsToGeomData &data) const
+void Text::coords_to_geom_line(size_t i, const Geometry &rgeom, CoordsToGeomData &data) const
 {
        if(i==data.row)
        {
@@ -349,7 +349,7 @@ void Text::coords_to_geom_line(unsigned i, const Geometry &rgeom, CoordsToGeomDa
                else
                {
                        StringCodec::Utf8::Decoder dec;
-                       for(unsigned c=data.col; c; --c)
+                       for(size_t c=data.col; c; --c)
                                dec.decode_char(text, j);
                }
                float w = style->get_font().get_string_width(string(begin, j));
index 6de3573fc6dfda35495b40d303065d412413a599..3387f362953ce87971e8dab4534ae876c922df96 100644 (file)
@@ -22,9 +22,9 @@ class MSPGLTK_API Text
 private:
        struct Line
        {
-               unsigned start = 0;
-               unsigned bytes = 0;
-               unsigned length = 0;
+               std::size_t start = 0;
+               std::size_t bytes = 0;
+               std::size_t length = 0;
                unsigned width = 0;
        };
 
@@ -46,32 +46,32 @@ public:
        void autosize(const Part &, Geometry &) const;
 
        void set(const std::string &);
-       void erase(unsigned, unsigned);
-       void insert(unsigned, const std::string &);
+       void erase(std::size_t, std::size_t);
+       void insert(std::size_t, const std::string &);
        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;
-       unsigned move_offset(unsigned, int) const;
-       void offset_to_coords(unsigned, unsigned &, unsigned &) const;
-       unsigned coords_to_offset(unsigned, unsigned) const;
-       Geometry coords_to_geometry(const Part &, const Geometry &, unsigned, unsigned, unsigned) const;
+       std::size_t size() const { return text.size(); }
+       std::size_t get_n_lines() const { return lines.size(); }
+       std::size_t get_visible_lines(const Part &, const Geometry &, unsigned *) const;
+       std::size_t get_line_length(std::size_t) const;
+       std::size_t move_offset(std::size_t, std::ptrdiff_t) const;
+       void offset_to_coords(std::size_t, std::size_t &, std::size_t &) const;
+       std::size_t coords_to_offset(std::size_t, std::size_t) const;
+       Geometry coords_to_geometry(const Part &, const Geometry &, std::size_t, std::size_t, std::size_t) const;
 
        void build(const Part &, State, const Geometry &, PartCache &) const;
-       void build(const Part &, State, const Geometry &, unsigned, PartCache &) const;
+       void build(const Part &, State, const Geometry &, std::size_t, PartCache &) const;
 
        Text &operator=(const std::string &);
 private:
        void find_lines();
-       unsigned count_characters(unsigned, unsigned) const;
-       void check_alignment(unsigned) const;
+       std::size_t count_characters(std::size_t, std::size_t) const;
+       void check_alignment(std::size_t) const;
 
        template<typename T>
-       void process_lines(const Part &, const Geometry &, unsigned, void (Text::*)(unsigned, const Geometry &, T &) const, T &) const;
+       void process_lines(const Part &, const Geometry &, std::size_t, void (Text::*)(std::size_t, const Geometry &, T &) const, T &) const;
 
-       void build_line(unsigned, const Geometry &, RenderData &) const;
-       void coords_to_geom_line(unsigned, const Geometry &, CoordsToGeomData &) const;
+       void build_line(std::size_t, const Geometry &, RenderData &) const;
+       void coords_to_geom_line(std::size_t, const Geometry &, CoordsToGeomData &) const;
 };
 
 } // namespace GLtk