Commit Graph

94 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
f15d2ebf38 Improve the code that limits scrolling at top/bottom
The most visible part of this commit is the move of part of
BufferView::updateMetrics to a new TextMetrics::updateMetrics. This
new method makes sure that metrics are known for all visible paragraphs
(starting from anchor), and that the positions of the paragraphs have
been recorded.

This method is called up to 3 times in BufferView::updateMetrics:
* unconditionally, to update all visible metrics,
* then, if the bottom of the document is visible and too high, after
  updating the anchor ypos,
* and similarly if the top of the document is visible and too low.

This fixes for example the case where one jumps to Section 5.3 at the
end of Tutorial and 'scroll_below_document' is false.

Some now redundant code is removed from BufferView::scrollToCursor.

The anchor-setting code in BufferView::draw is not clearly useful, but
left here just in case. It generates a debug warning, though.

Part of bug #12297.
2024-04-05 13:03:22 +02:00
Jean-Marc Lasgouttes
08010c6a5e Implement quick scroll
Replace flag parameter for updateMetrics() by a `force' boolean. When
it is false, the method keeps the metrics of paragraphs that are still
visible in WorkArea instead of computing everything afresh. All it has
to do is update their positions.

Add code to updateMetrics() to update the value of the anchor pit/ypos
(similar to the one in draw()).

Update processUpdateFlags() to use this when update flag is ForceDraw.

Modify scrollDocView() to just change the anchor paragraph position
when the scrolling operation would re-use some of the existing
paragraphs.

The time needed to update the metrics when scrolling with mouse in the
branch-test.lyx document is now divided by 20!

Part of bug #12297.
2024-04-05 13:03:22 +02:00
Jean-Marc Lasgouttes
65b03c7c72 Improve label font computation in insets
This patch reuses the code of TextMetrics::displayFont() that handles
the label part of LABEL_MANUAL paragraphs to create a new
labelDisplayFont() method usable for things like Itemize labels.

To this end, and new magic value is used as position to force the
label case in displayFont(). The code is also factored a bit and
cleaned up.

Fixes bug #12810.
2023-06-21 17:23:34 +02:00
Jean-Marc Lasgouttes
4f158ecfc8 Fix computation of LABEL_MANUAL label separation
The spacing of Labeling, Description and friends shall be computed
when breaking the row, not when tokenizing it. Indeed, this is the
right place to determine its correct value.

To this end add a new MARGINSPACE row element type.

This allows to remove TextMetrics::labelEnd, which is not used anymore.
2022-01-17 17:35:12 +01:00
Jean-Marc Lasgouttes
d694701315 Last step of transition: use sortenIfNeeded again.
Change semantics of Row::shortenIfNeeded: instead of breaking the row
and returning a boolean, it returns the list of row elements that have
been removed (or broken) from the row. The logic of the method remains
the same.

Use shortenIfNeeded in breakParagraph. This was the last missing block.

Remove Row::breakAt and the old breakRow. Only bugs remain now :)
2021-12-07 17:04:47 +01:00
Jean-Marc Lasgouttes
ef88e31a1f Break the paragraph's big row according to margins
Still many features missing:
- handle insets that break rows (display math, newline, ...)
- handle rows that are too long by replacing the single call to
  breakAt with a call to a reworked Row::shortenIfNeeded.
- some easy things at the end of breakRow (bidi text, etc.).
2021-12-07 17:04:47 +01:00
Jean-Marc Lasgouttes
f4d3702d4d Create new method TM::tokenizeParagraph
This contains large parts of breakRow, but creates a unique row for the paragraph.

The parts taken or not in redoParagraph are annotated.

The new method is not used yet.
2021-12-07 17:04:46 +01:00
Jean-Marc Lasgouttes
5e396c3f0c Prevent insets in table cells from expanding artificially to max width
This replaces ad-hoc hacks and does a better job by propagating the
the tightness recursively.

Fixes bug #9363.
2021-05-31 14:38:42 +02:00
Jean-Marc Lasgouttes
824d1c993a Fixup 294e4884: center correctly Abstract label when paragraph is empty
When a paragraph is empty, it was not possible to query what the left
margin would be for an hypothetical second row.

Modify TextMetrics::leftMargin so that it does not test
whether position is after the last position of the paragraph.

Cosmetics: set the size of label to "small" for Abstract layout in
standard classes and reduce the spacing between label and text.

Fixes remainder of #11939.
2021-01-05 15:21:04 +01:00
Jean-Marc Lasgouttes
2d27d033a6 Typo and reformatting 2020-11-21 19:13:29 +01:00
Yuriy Skalko
d38eddb397 Match header/source function argument naming 2020-11-01 22:23:44 +02:00
Yuriy Skalko
196d9caeb0 Clean includes using the output of iwyu tool 2020-10-20 11:38:55 +03:00
Pavel Sanda
10fafd3bfe <map> ParagraphMetrics.h -> TextMetrics.h 2020-10-14 13:14:58 +02:00
Yuriy Skalko
715b8cda54 Refactoring based on cppcheck suggestions 2020-10-03 13:39:51 +02:00
Jean-Marc Lasgouttes
294e4884ee Center correctly top labels like Abstract.
They used to take the paragraph indentation into account.

Fixes bug #11939.
2020-08-25 10:30:34 +02:00
Jean-Marc Lasgouttes
501f4e848f Cleanup: BufferView should not need to be friend of TextMetrics
It did access par_metrics_[] directly because there was no non-const
parMetrics().

This patch adds one and unfriends BufferView. The code is equivalent
since in all these cases, the metrics have just been computed with
redoParagraph().
2020-07-14 00:08:07 +02:00
Jean-Marc Lasgouttes
32f06d01ec Revert "Improve handling of top and bottom margin"
It turns out this is not ready at all.

This reverts commit ff7cdf1b74.
2020-07-13 00:00:36 +02:00
Jean-Marc Lasgouttes
ff7cdf1b74 Improve handling of top and bottom margin
The 20px space on top and bottom of document have traditionally been
obtained by adding the to the ascent/descent of the first/last row.
This reads to annoyances like selections that are drawn in these
margins and issues with the nesting marker.

The change is to add the values to a separate member of the Row
object, and to add new Row::total(Ascent|Descent) methods that add the
effect of this padding.

Moreover, some methods are added to TextMetrics to simplify the
BufferView code.

Fixes bug #9545.
2020-07-12 20:32:04 +02:00
Jean-Marc Lasgouttes
63bfaa14be Make TextMetrics noncopyable
This is done by declaring unimplemented private copy constructor and
assignment operator.

This breaks compilation in BufferView::textMetrics, which does a copy when
inserting a TextMetrics object in the cache. Some C++11 wizardry I will not
pretend to completely understand saves the day.

See the following page for details:
  https://en.cppreference.com/w/cpp/container/map/emplace

This avoids real world bugs like #11512.
2019-03-12 16:03:22 +01:00
Jean-Marc Lasgouttes
7f0525e9e0 Change the way scrolled rows are tracked
The goal of this commit is to simplify the logic in TextMetrics::draw.
Now, rows are repainted depending on their changed() status.

Instead of checking whether rows have been scrolled horizontally at
draw time, the code marks the row as changed when testing for
horizontal scrolling.

To this end a new method TestMetrics::setRowChanged is added, that
searches a row in the text metrics cache and marks it changed if
found.

The old code that remembered the previously scrolled row can now be
removed.
2019-02-25 15:19:58 +01:00
Jean-Marc Lasgouttes
ab02a907f0 Move some TextMetrics code around.
No change intended.
2019-02-25 11:58:50 +01:00
Jean-Marc Lasgouttes
2ae51b947b Rename TextMetrics::dimension() to dim() 2019-02-19 18:04:43 +01:00
Jean-Marc Lasgouttes
edb46d2a94 Fix alignment of rows when text width is variable
When several lines of text are in the same variable-width tabular
cell, it is not possible to align properly the rows until the cell
width is known.

Therefore a parameter is added to redoParagraph to skip this
computation, so that it can be done later in TextMetrics::metrics.
Other calls to redoParagraph in the code are not affected. It is not
clear at this point whether they may create artefacts.

computeRowMetrics has been renamed to setRowAlignment to better
reflect its use.

Fixes bug #11447.
2019-01-11 16:23:05 +01:00
Juergen Spitzmueller
9dcb24d578 Support varwidth's V tabular column type
This effectively enables linebreaks, multipars and layout changes in
non-fixed width (i.e., standard) table columns.

Fixes: #6577

TODO: metrics are wrong (too wide) on screen with linebreaks.
2018-07-01 19:18:38 +02:00
Jean-Marc Lasgouttes
a8fd12d18c Cosmetics
Use range-for in TextMetrics.cpp.

Rename InsetList::InsetTable to InsetList::Element.
2018-05-28 12:33:17 +02:00
Jean-Marc Lasgouttes
3b404b0023 Update insets position in cache in more cases
This patch makes sure that, every time a ParagraphMetrics has its
position set, the inset positions for the insets held by this
paragraph are remembered too.

This is complementary to BufferView::updatePosCache, but I do not have
hard evidence that this is required other than to increase robustness.
It may help in some cases when scrolling the document (scrollbar,
cursor up/down, page up/down).
2017-09-08 16:57:22 +02:00
Jean-Marc Lasgouttes
f6e37a8ca0 TextMetrics::leftMargin does not need a max_width parameter
Additionally move it to private: section.
2017-07-12 10:29:27 +02:00
Jean-Marc Lasgouttes
4efb129ccb Avoid crash when selecting long text
In some (not yet understood) situations, the paragraph metrics cache
is empty in generateSyntheticMouseEvent(). We just avoid a crash in
this case, but there is probably an underlying problem that deserves
being fixed.

Fixes bug #10324.
2017-06-19 12:23:17 +02:00
Jean-Marc Lasgouttes
c9fefd5a2c Fix bad cursor positioning when entering an inset
The test added at 359aef92 was incorrect. Actually, Inset::editXY
returns the inset when it is edited and also when it is not, which
can be confusing. So if we are unlucky and the slices positions in the
text area and in the inner inset match, the code below triggers and
many bad things can happen.

Also improve the documentation of Inset::editXY and TextMetrics::editXY.

Fixes #10691.
2017-06-12 13:51:24 +02:00
Jean-Marc Lasgouttes
01f0ab64a7 Revert "When selecting text with the mouse, inset selection happens in the middle"
This reverts commit eb4a2a190f.
2017-04-06 15:17:00 +02:00
Guillaume Munch
eb4a2a190f When selecting text with the mouse, inset selection happens in the middle 2017-02-18 23:03:53 +01:00
Jean-Marc Lasgouttes
1fca708c7f Move TextMetrics::findRowElement to Row class 2017-02-02 15:35:03 +01:00
Jean-Marc Lasgouttes
0311718215 Split TextMetrics::setRowHeight in three parts
The new functions parBottomSpaging and parTopSapcing return below/above each paragraph.

This allows to remove the TopBottomSpace argument and makes the code a
bit clearer.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
e39e4cf96b Do not require an extra pit parameter when a row is available
Now that Row has a pit() member, it is possible to use it instead of passing an extra pit_type parameter to a function which already has access to a Row.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
1751626776 Simplify redoParagraph by merging duplicate code
Let breakRow return a boolean indicating whether an additional row is
required (after a newline) and use that to replace the code that added
an extra row when a paragraph ends with a newline.
2016-05-30 14:55:41 +02:00
Jean-Marc Lasgouttes
e52a83549d Remove unused TextMetrics::maxWidth() 2016-05-29 17:55:45 -04:00
Jean-Marc Lasgouttes
4fb8e9b639 Use isMainText() instead of doing explicit tests 2016-05-29 17:55:45 -04:00
Jean-Marc Lasgouttes
1639abb8ed Let getPosNearX take horizontal scrolling into account
If we do not do that, it is not possible to position the cursor after
a long inset with the mouse.

To do this, it is necessary to add the pit information to the Row
object. This is a good idea in any case, and will allow to simplify
some code later on.

Fixes bug #10094.
2016-05-29 17:55:42 -04:00
Jean-Marc Lasgouttes
d8719ade59 Implement on screen rendering of alignment in LR boxes.
This is done by implementing contentAlignment() for this inset.

In order to display properly 'stretch' alignment, the code for TextMetrics::getAlign is rewritten to include some code that was in computeRowMetrics.
2015-11-23 11:40:36 +01:00
Jean-Marc Lasgouttes
21c30a09e1 Rewrite Cursor::getSurroundingPos without Bidi class
New method TextMetrics::findRowElement, excerpted from CursorX.

Reimplement getSurroundingPos using Row information. This is easy when
the cursor is inside a row element. At row element edges, different
situations can occur; hopefully all these situations are taken into
account.

Rename the old getSurroundingPos to getSurroundingPosOrig and
transform getSurroundingPos into a wrapper that compares the two
methods. This will be removed when we are confident that the new
function is equivalent to the old one.

It will then be possible to remove also the Bidi class (at last!).
2015-09-27 22:17:46 +02:00
Georg Baum
699a6db9fa Add some missing member variable initializations
These were all found by cppcheck. Even in constructors that are there "only
because of std containers" the class should be initialized correctly. You can
never know whether such an object does not get used, and then a nice crash
caused by dereferencing a NULL-pointer is better than undefined behaviour.
2015-09-13 19:47:21 +02:00
Jean-Marc Lasgouttes
37fd7b24ba Use enum instead of int in TextMetrics::getAlign
This is just a code cleanup, no (intented) effect.
2014-07-29 11:05:14 +02:00
Jean-Marc Lasgouttes
5e126d2920 Whitespace only 2014-07-25 22:36:20 +02:00
Jean-Marc Lasgouttes
b0543270a9 Remove debug code from TextMetrics
After this, it is possible to remove one parameter to getPosNearX.
2014-07-08 21:29:52 +02:00
Jean-Marc Lasgouttes
f686375eec Change getColumnNearX to getPosNearX
The semantics was bad: the old implementation would return pos - row.pos(), and then all user of the function had to re-add row.pos().
2014-07-08 21:10:47 +02:00
Jean-Marc Lasgouttes
35d47698c6 Convert cursorX() and computeRowMetrics() to the new scheme
* convert cursorX to new scheme; old computation is still there for the sake of comparison.

* use Row to compute separator width in computeRowMetrics; again, the old code is retained for now.

* Get rid of rowWidth()
2014-06-25 17:54:27 +02:00
Jean-Marc Lasgouttes
cf31077932 Change TextMetrics::rowHeight to setRowHeight
This new function takes a row as parameter.

Also, add direct access to Row::dim_
2014-06-25 17:53:34 +02:00
Jean-Marc Lasgouttes
0212ef5426 Make TextMetrics::editXY more robust
This fixes a crash in examples/fa/splash.lyx when selecting text
representing menu entries. This happens because menu names are in LTR
English, while the inset itself is in RTL.

The problem is that the current code relies on the fact that
 1. getColumnNearX and checkInsetHit share the same idea about cursor
    position.
 2. pos and pos + 1 are in general consecutive on screen.

It seems that 1. is wrong here (for reasons I did not try to
understand); the second assumption is definitely false with
bi-directional text. This makes editXY very fragile.

The new code should be more robust in this respect. The logic is:
 * if checkInsetHit finds an inset, use its position,
 * otherwise, ask getColumnNearX for the cursor position.

Fixes: #9142
2014-05-28 14:22:21 +02:00
Vincent van Ravesteijn
07534d147d Remove leftover of r36485.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36740 a592a061-630c-0410-9148-cb99ea01b6c8
2010-12-06 00:25:45 +00:00
Uwe Stöhr
d7c90fd841 TextMetrics.h: fix typo
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35275 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-04 02:38:21 +00:00