From: Jean-Marc Lasgouttes Date: Thu, 1 Jul 2021 16:35:16 +0000 (+0200) Subject: Rework display of numbers in margins of hull insets X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=da57154f94077604d9bddcff7360307897cbad3f;p=features.git Rework display of numbers in margins of hull insets This requires the introduction of the booleans selected_left and selected_right in PainterInfo. These tell whether the selection continues at the left/right of the inset. This information allows to 1/ paint equation number in the right color: either current text color or selection text color. 2/ before that, paint a small background rectangle of the correct color. This allows to avoid painting a large rectangle of an arbitrary color that was the cause of the bug. Fixes bug #12319. --- diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index 24656ed2ef..4688d128eb 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -132,7 +132,8 @@ MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth, ///////////////////////////////////////////////////////////////////////// PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter) - : pain(painter), ltr_pos(false), change(), selected(false), + : pain(painter), ltr_pos(false), change(), + selected(false), selected_left(false), selected_right(false), do_spellcheck(true), full_repaint(true), background_color(Color_background), leftx(0), rightx(0) { diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index bfd9d07975..94f86706a7 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -141,12 +141,15 @@ public: Change change; /// Whether the parent is selected as a whole bool selected; + /// Whether the left/right margins are selected + bool selected_left, selected_right; /// Whether the spell checker is enabled for the parent bool do_spellcheck; /// True when it can be assumed that the screen has been cleared bool full_repaint; /// Current background color ColorCode background_color; + /// The left and right position of current line (inside margins). /// Useful for drawing display math numbering int leftx, rightx; }; diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp index 44e4f72534..400b7b66e8 100644 --- a/src/RowPainter.cpp +++ b/src/RowPainter.cpp @@ -82,7 +82,11 @@ FontInfo RowPainter::labelFont(bool end) const void RowPainter::paintInset(Row::Element const & e) const { - // Handle selection + // Handle selection (first left/right, then middle). + pi_.selected_left = pi_.selected + || (row_.isRTL() ? row_.end_margin_sel : row_.begin_margin_sel); + pi_.selected_right = pi_.selected + || (row_.isRTL() ? row_.begin_margin_sel : row_.end_margin_sel); bool const pi_selected = pi_.selected; Cursor const & cur = pi_.base.bv->cursor(); if (cur.selection() && cur.text() == &text_ diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index fb52049f2e..97d95da03b 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -589,13 +589,9 @@ void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const dim.wid, dim.asc + dim.des, backgroundColor(pi)); return; } - // If there are numbers, the margins around the (displayed) - // equation have to be cleared. - if (numberedType()) - pi.pain.fillRectangle(pi.leftx, y - dim.asc, - pi.rightx - pi.leftx, dim.height(), pi.background_color); + pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2, - dim.asc + dim.des - 1, pi.backgroundColor(this)); + dim.height() - 1, pi.backgroundColor(this)); } @@ -626,11 +622,6 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const } // First draw the numbers - ColorCode color = pi.selected && lyxrc.use_system_colors - ? Color_selectiontext : standardColor(); - bool const really_change_color = pi.base.font.color() == Color_none; - Changer dummy0 = really_change_color ? pi.base.font.changeColor(color) - : noChange(); if (numberedType()) { BufferParams::MathNumber const math_number = buffer().params().getMathNumber(); for (row_type row = 0; row < nrows(); ++row) { @@ -639,18 +630,37 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const Dimension dimnl; mathed_string_dim(pi.base.font, nl, dimnl); if (math_number == BufferParams::LEFT) { + ColorCode const col = pi.selected_left + ? Color_selectiontext + : pi.base.font.color(); + Changer dummy0 = pi.base.font.changeColor(col); if (dimnl.wid > x - pi.leftx) yy += rowinfo(row).descent + dimnl.asc; + pi.pain.fillRectangle(pi.leftx, yy - dimnl.asc, + dimnl.width(), dimnl.height(), + pi.selected_left ? Color_selection : pi.background_color); pi.draw(pi.leftx, yy, nl); } else { + ColorCode const col = pi.selected_right + ? Color_selectiontext + : pi.base.font.color(); + Changer dummy0 = pi.base.font.changeColor(col); if (dimnl.wid > pi.rightx - x - dim.wid) yy += rowinfo(row).descent + dimnl.asc; + pi.pain.fillRectangle(pi.rightx - dimnl.wid, yy - dimnl.asc, + dimnl.width(), dimnl.height(), + pi.selected_right ? Color_selection : pi.background_color); pi.draw(pi.rightx - dimnl.wid, yy, nl); } } } // Then the equations + ColorCode color = pi.selected && lyxrc.use_system_colors + ? Color_selectiontext : standardColor(); + bool const really_change_color = pi.base.font.color() == Color_none; + Changer dummy0 = really_change_color ? pi.base.font.changeColor(color) + : noChange(); Changer dummy1 = pi.base.changeFontSet(standardFont()); Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE : TEXT_STYLE);