mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 08:41:46 +00:00
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:
parent
d19f4319dc
commit
629a692ce2
@ -1197,8 +1197,7 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) const
|
|||||||
right_pos = -1;
|
right_pos = -1;
|
||||||
|
|
||||||
Row const & row = textRow();
|
Row const & row = textRow();
|
||||||
double dummy = 0;
|
Row::const_iterator cit = row.findElement(pos(), boundary());
|
||||||
Row::const_iterator cit = row.findElement(pos(), boundary(), dummy);
|
|
||||||
// Handle the case of empty row
|
// Handle the case of empty row
|
||||||
if (cit == row.end()) {
|
if (cit == row.end()) {
|
||||||
if (row.isRTL())
|
if (row.isRTL())
|
||||||
|
18
src/Row.cpp
18
src/Row.cpp
@ -753,8 +753,9 @@ void Row::reverseRTL()
|
|||||||
reverse(elements_.begin(), elements_.end());
|
reverse(elements_.begin(), elements_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Row::const_iterator const
|
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)
|
* 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
|
} // namespace lyx
|
||||||
|
11
src/Row.h
11
src/Row.h
@ -257,6 +257,10 @@ public:
|
|||||||
* adjusted to the actual pixel position.
|
* adjusted to the actual pixel position.
|
||||||
*/
|
*/
|
||||||
std::pair<pos_type, bool> x2pos(int & x) const;
|
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,
|
void add(pos_type pos, Inset const * ins, Dimension const & dim,
|
||||||
@ -331,8 +335,8 @@ public:
|
|||||||
///
|
///
|
||||||
void needsChangeBar(bool ncb) { changebar_ = ncb; }
|
void needsChangeBar(bool ncb) { changebar_ = ncb; }
|
||||||
|
|
||||||
/// Find row element that contains \c pos, and compute x offset.
|
/// Find row element that contains \c pos.
|
||||||
const_iterator const findElement(pos_type pos, bool boundary, double & x) const;
|
const_iterator const findElement(pos_type pos, bool boundary) const;
|
||||||
|
|
||||||
friend std::ostream & operator<<(std::ostream & os, Row const & row);
|
friend std::ostream & operator<<(std::ostream & os, Row const & row);
|
||||||
|
|
||||||
@ -372,6 +376,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool sameString(Font const & f, Change const & ch) const;
|
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_;
|
Elements elements_;
|
||||||
|
|
||||||
|
@ -1691,12 +1691,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
|
|||||||
if (pm.rows().empty())
|
if (pm.rows().empty())
|
||||||
return 0;
|
return 0;
|
||||||
Row const & row = pm.getRow(sl.pos(), boundary);
|
Row const & row = pm.getRow(sl.pos(), boundary);
|
||||||
pos_type const pos = sl.pos();
|
return row.pos2x(sl.pos(), boundary);
|
||||||
|
|
||||||
double x = 0;
|
|
||||||
row.findElement(pos, boundary, x);
|
|
||||||
return int(x);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user