Implement CanBreakBefore row flag

This is used for elements that allow to break a row before them
(similar to CanBreakAfter).
This commit is contained in:
Jean-Marc Lasgouttes 2022-06-09 21:27:43 +02:00
parent d0862d59e6
commit 254b2b0bfa
2 changed files with 26 additions and 15 deletions

View File

@ -562,7 +562,7 @@ Row::Elements Row::shortenIfNeeded(int const w, int const next_width)
Element brk = *cit_brk;
/* If the current element is an inset that allows breaking row
* after itself, and if the row is already short enough after
* this inset, then cut right after this element.
* this element, then cut right after it.
*/
if (wid_brk <= w && brk.row_flags & CanBreakAfter) {
end_ = brk.endpos;
@ -572,6 +572,16 @@ Row::Elements Row::shortenIfNeeded(int const w, int const next_width)
}
// assume now that the current element is not there
wid_brk -= brk.dim.wid;
/* If the current element is an inset that allows breaking row
* before itself, and if the row is already short enough before
* this element, then cut right before it.
*/
if (wid_brk <= w && brk.row_flags & CanBreakBefore && cit_brk != beg) {
end_ = (cit_brk -1)->endpos;
dim_.wid = wid_brk;
moveElements(elements_, cit_brk, tail);
return tail;
}
/* We have found a suitable separable element. This is the common case.
* Try to break it cleanly at a length that is both
* - less than the available space on the row

View File

@ -16,10 +16,9 @@
namespace lyx {
/* The list of possible flags, that can be combined.
* Some flags that should logically be here (e.g.,
* CanBreakBefore), do not exist. This is because the need has not
* been identitfied yet.
/* The list of possible flags, that can be combined. Some flags that
* should logically be here (e.g., AlwaysBreakBefore), do not exist.
* This is because the need has not been identitfied yet.
*
* Priorities when before/after disagree:
* AlwaysBreak* > NoBreak* > Break* or CanBreak*.
@ -30,26 +29,28 @@ enum RowFlags {
Inline = 0,
// break row before this element if the row is not empty
BreakBefore = 1 << 0,
// break row whenever needed before this element
CanBreakBefore = 1 << 1,
// Avoid breaking row before this element
NoBreakBefore = 1 << 1,
NoBreakBefore = 1 << 2,
// flush the row before this element (useful with BreakBefore)
FlushBefore = 1 << 2,
FlushBefore = 1 << 3,
// force new (maybe empty) row after this element
AlwaysBreakAfter = 1 << 3,
AlwaysBreakAfter = 1 << 4,
// break row after this element if there are more elements
BreakAfter = 1 << 4,
BreakAfter = 1 << 5,
// break row whenever needed after this element
CanBreakAfter = 1 << 5,
CanBreakAfter = 1 << 6,
// Avoid breaking row after this element
NoBreakAfter = 1 << 6,
NoBreakAfter = 1 << 7,
// The contents of the row may be broken in two (e.g. string)
CanBreakInside = 1 << 7,
CanBreakInside = 1 << 8,
// Flush the row that ends with this element
Flush = 1 << 8,
Flush = 1 << 9,
// specify an alignment (left, right) for a display element
// (default is center)
AlignLeft = 1 << 9,
AlignRight = 1 << 10,
AlignLeft = 1 << 10,
AlignRight = 1 << 11,
// A display element breaks row at both ends
Display = FlushBefore | BreakBefore | BreakAfter,
// Flags that concern breaking after element