Compare commits

...

2 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
629a692ce2 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.
2024-11-29 12:14:52 +01:00
Jean-Marc Lasgouttes
d19f4319dc Try to reduce the use of CoordCache::insets().dim()
The debug code does not needed it. The code in Cursor is only used in
mathed.
2024-11-29 11:52:57 +01:00
5 changed files with 33 additions and 15 deletions

View File

@ -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())
@ -2551,6 +2550,8 @@ void Cursor::checkBufferStructure()
void Cursor::moveToClosestEdge(int const x, bool const edit) void Cursor::moveToClosestEdge(int const x, bool const edit)
{ {
if (Inset const * inset = nextInset()) { if (Inset const * inset = nextInset()) {
// This is only used in mathed.
LATTEST(inset->asInsetMath());
// stay in front of insets for which we want to open the dialog // stay in front of insets for which we want to open the dialog
// (e.g. InsetMathSpace). // (e.g. InsetMathSpace).
if (edit && (inset->hasSettings() || !inset->contextMenuName().empty())) if (edit && (inset->hasSettings() || !inset->contextMenuName().empty()))

View File

@ -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

View File

@ -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_;

View File

@ -125,10 +125,9 @@ void RowPainter::paintInset(Row::Element const & e) const
pi_.selected = pi_selected; pi_.selected = pi_selected;
#ifdef DEBUG_METRICS #ifdef DEBUG_METRICS
Dimension const & dim = pi_.base.bv->coordCache().insets().dim(e.inset); int const x2 = x1 + e.dim.wid;
int const x2 = x1 + dim.wid; int const y1 = yo_ + e.dim.des;
int const y1 = yo_ + dim.des; int const y2 = yo_ - e.dim.asc;
int const y2 = yo_ - dim.asc;
pi_.pain.line(x1, y1, x1, y2, Color_green); pi_.pain.line(x1, y1, x1, y2, Color_green);
pi_.pain.line(x1, y1, x2, y1, Color_green); pi_.pain.line(x1, y1, x2, y1, Color_green);
pi_.pain.line(x2, y1, x2, y2, Color_green); pi_.pain.line(x2, y1, x2, y2, Color_green);

View File

@ -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);
} }