Cleanup Row::findElement and introduce Row::pos2x

Remove the functionality of findElement of also computing a pixel
position and introduce a function that only does that.
This commit is contained in:
Jean-Marc Lasgouttes 2024-11-29 12:13:15 +01:00
parent d19f4319dc
commit 629a692ce2
4 changed files with 28 additions and 11 deletions

View File

@ -1197,8 +1197,7 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) const
right_pos = -1;
Row const & row = textRow();
double dummy = 0;
Row::const_iterator cit = row.findElement(pos(), boundary(), dummy);
Row::const_iterator cit = row.findElement(pos(), boundary());
// Handle the case of empty row
if (cit == row.end()) {
if (row.isRTL())

View File

@ -753,8 +753,9 @@ void Row::reverseRTL()
reverse(elements_.begin(), elements_.end());
}
Row::const_iterator const
Row::findElement(pos_type const pos, bool const boundary, double & x) const
Row::findElementHelper(pos_type const pos, bool const boundary, double & x) const
{
/**
* When boundary is true, position i is in the row element (pos, endpos)
@ -803,4 +804,19 @@ Row::findElement(pos_type const pos, bool const boundary, double & x) const
}
Row::const_iterator const Row::findElement(pos_type const pos, bool const boundary) const
{
double dummy;
return findElementHelper(pos, boundary, dummy);
}
double Row::pos2x(pos_type const pos, bool const boundary) const
{
double x;
findElementHelper(pos, boundary, x);
return x;
}
} // namespace lyx

View File

@ -257,6 +257,10 @@ public:
* adjusted to the actual pixel position.
*/
std::pair<pos_type, bool> x2pos(int & x) const;
/** Return the pixel position that corresponds to the position and
* boundary.
*/
double pos2x(pos_type const pos, bool const boundary) const;
///
void add(pos_type pos, Inset const * ins, Dimension const & dim,
@ -331,8 +335,8 @@ public:
///
void needsChangeBar(bool ncb) { changebar_ = ncb; }
/// Find row element that contains \c pos, and compute x offset.
const_iterator const findElement(pos_type pos, bool boundary, double & x) const;
/// Find row element that contains \c pos.
const_iterator const findElement(pos_type pos, bool boundary) const;
friend std::ostream & operator<<(std::ostream & os, Row const & row);
@ -372,6 +376,9 @@ private:
*/
bool sameString(Font const & f, Change const & ch) const;
/// Find row element that contains \c pos, and compute x offset.
const_iterator const findElementHelper(pos_type pos, bool boundary, double & x) const;
///
Elements elements_;

View File

@ -1691,12 +1691,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
if (pm.rows().empty())
return 0;
Row const & row = pm.getRow(sl.pos(), boundary);
pos_type const pos = sl.pos();
double x = 0;
row.findElement(pos, boundary, x);
return int(x);
return row.pos2x(sl.pos(), boundary);
}