mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Improve row flushing
Add new row flags Flush and FlushBefore to let insets indicate whether they cause flushing of current row (eg. newline) or of previous row (e.g. display insets).
This commit is contained in:
parent
a06f0e48ec
commit
5966d4fb8d
@ -32,22 +32,26 @@ enum RowFlags {
|
||||
BreakBefore = 1 << 0,
|
||||
// Avoid breaking row before this element
|
||||
NoBreakBefore = 1 << 1,
|
||||
// flush the row before this element (useful with BreakBefore)
|
||||
FlushBefore = 1 << 2,
|
||||
// force new (maybe empty) row after this element
|
||||
AlwaysBreakAfter = 1 << 2,
|
||||
AlwaysBreakAfter = 1 << 3,
|
||||
// break row after this element if there are more elements
|
||||
BreakAfter = 1 << 3,
|
||||
BreakAfter = 1 << 4,
|
||||
// break row whenever needed after this element
|
||||
CanBreakAfter = 1 << 4,
|
||||
CanBreakAfter = 1 << 5,
|
||||
// Avoid breaking row after this element
|
||||
NoBreakAfter = 1 << 5,
|
||||
NoBreakAfter = 1 << 6,
|
||||
// The contents of the row may be broken in two (e.g. string)
|
||||
CanBreakInside = 1 << 6,
|
||||
CanBreakInside = 1 << 7,
|
||||
// Flush the row that ends with this element
|
||||
Flush = 1 << 8,
|
||||
// specify an alignment (left, right) for a display element
|
||||
// (default is center)
|
||||
AlignLeft = 1 << 7,
|
||||
AlignRight = 1 << 8,
|
||||
AlignLeft = 1 << 9,
|
||||
AlignRight = 1 << 10,
|
||||
// A display element breaks row at both ends
|
||||
Display = BreakBefore | BreakAfter,
|
||||
Display = FlushBefore | BreakBefore | BreakAfter,
|
||||
// Flags that concern breaking after element
|
||||
AfterFlags = AlwaysBreakAfter | BreakAfter | CanBreakAfter | NoBreakAfter
|
||||
};
|
||||
|
@ -1068,7 +1068,6 @@ void cleanupRow(Row & row, bool at_end)
|
||||
}
|
||||
|
||||
row.endpos(row.back().endpos);
|
||||
row.flushed(at_end);
|
||||
// remove trailing spaces on row break
|
||||
if (!at_end)
|
||||
row.back().rtrim();
|
||||
@ -1118,8 +1117,11 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
|
||||
int const f2 = (fcit == end) ? (end_label ? Inline : NoBreakBefore)
|
||||
: fcit->row_flags;
|
||||
if (rows.empty() || needsRowBreak(f1, f2)) {
|
||||
if (!rows.empty())
|
||||
if (!rows.empty()) {
|
||||
cleanupRow(rows.back(), false);
|
||||
// Flush row as requested by row flags
|
||||
rows.back().flushed((f1 & Flush) || (f2 & FlushBefore));
|
||||
}
|
||||
pos_type pos = rows.empty() ? 0 : rows.back().endpos();
|
||||
rows.push_back(newRow(*this, bigrow.pit(), pos, is_rtl));
|
||||
// the width available for the row.
|
||||
|
@ -39,6 +39,15 @@ InsetNewline::InsetNewline() : Inset(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
int InsetNewline::rowFlags() const
|
||||
{
|
||||
if (params_.kind == InsetNewlineParams::LINEBREAK)
|
||||
return AlwaysBreakAfter;
|
||||
else
|
||||
return AlwaysBreakAfter | Flush;
|
||||
}
|
||||
|
||||
|
||||
void InsetNewlineParams::write(ostream & os) const
|
||||
{
|
||||
switch (kind) {
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
explicit InsetNewline(InsetNewlineParams par) : Inset(0)
|
||||
{ params_.kind = par.kind; }
|
||||
///
|
||||
int rowFlags() const override { return AlwaysBreakAfter; }
|
||||
int rowFlags() const override;
|
||||
///
|
||||
static void string2params(std::string const &, InsetNewlineParams &);
|
||||
///
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
return docstring();
|
||||
}
|
||||
///
|
||||
int rowFlags() const override { return BreakAfter; }
|
||||
int rowFlags() const override { return BreakAfter | Flush; }
|
||||
private:
|
||||
///
|
||||
InsetCode lyxCode() const override { return SEPARATOR_CODE; }
|
||||
|
Loading…
Reference in New Issue
Block a user