Skip to content

Commit f4425bd

Browse files
Fix #32538: Restore spacer page-end effect and optimize relayout scope
Fixes two regressions from spacer relayout changes: down/fixed spacers on the last system of a page had no effect when vertical spread was disabled, and system brackets could draw stale after systems moved between pages during partial relayout. The spacer trigger is now cost-aware: most edits stay measure-local; only boundary cases escalate to a bounded range from current system start to the next system boundary (or score end if none), avoiding full score relayout on large scores. Page-end clearance now respects last-system down spacer distance when vertical spread is disabled. Also refresh bracket and instrument-name vertical geometry in restoreLayout2() for reused systems that move across pages.
1 parent 3ac7056 commit f4425bd

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/engraving/dom/spacer.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "measure.h"
2929
#include "score.h"
30+
#include "system.h"
3031

3132
using namespace mu;
3233
using namespace muse::draw;
@@ -177,7 +178,44 @@ void Spacer::triggerLayout() const
177178
return;
178179
}
179180

180-
m->triggerLayout();
181+
Score* s = score();
182+
System* system = m->system();
183+
if (!s || !system || s->nstaves() == 0) {
184+
m->triggerLayout();
185+
return;
186+
}
187+
188+
// Most spacer edits can stay local to the measure and are much cheaper.
189+
// Escalate only for down/fixed spacers on the last non-vbox system of the page,
190+
// where edits can repaginate and affect page-end spacing.
191+
if (spacerType() == SpacerType::UP) {
192+
m->triggerLayout();
193+
return;
194+
}
195+
196+
System* nextSystem = m->nextNonVBoxSystem();
197+
if (nextSystem && nextSystem->page() == system->page()) {
198+
m->triggerLayout();
199+
return;
200+
}
201+
202+
// For the last notation system on a page, include the next system boundary
203+
// so page-end spacing can be recomputed without relaying out the whole score.
204+
Measure* firstMeasure = system->firstMeasure();
205+
if (!firstMeasure) {
206+
m->triggerLayout();
207+
return;
208+
}
209+
210+
Fraction startTick = firstMeasure->tick();
211+
Fraction endTick = s->endTick();
212+
if (nextSystem) {
213+
if (Measure* nextFirstMeasure = nextSystem->firstMeasure()) {
214+
endTick = nextFirstMeasure->tick();
215+
}
216+
}
217+
218+
s->setLayout(startTick, endTick, 0, s->nstaves() - 1, this);
181219
}
182220

183221
//---------------------------------------------------------

src/engraving/rendering/score/pagelayout.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ void PageLayout::collectPage(LayoutContext& ctx)
263263
isPageBreak = (y + dist) >= endY && breakPages;
264264
}
265265
if (isPageBreak) {
266-
// Reserve only natural bottom clearance against footer on page end.
267-
// Spacer down is applied between systems (SystemLayout::minDistance).
268266
double dist = ctx.state().prevSystem()->minBottom();
267+
if (!ctx.conf().isVerticalSpreadEnabled()) {
268+
dist = std::max(dist, ctx.state().prevSystem()->spacerDistance(false));
269+
}
269270
double footerPadding = 0.0;
270271
// ensure it doesn't collide with footer
271272
if (footerExtension > 0) {

src/engraving/rendering/score/systemlayout.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,11 @@ void SystemLayout::restoreLayout2(System* system, LayoutContext& ctx)
23852385

23862386
system->setHeight(system->systemHeight());
23872387
SystemLayout::setMeasureHeight(system, system->systemHeight(), ctx);
2388+
2389+
// Reused systems can move across pages during partial relayout.
2390+
// Refresh geometry derived from SysStaff vertical positions.
2391+
SystemLayout::layoutBracketsVertical(system, ctx);
2392+
SystemHeaderLayout::setInstrumentNamesVerticalPos(system, ctx);
23882393
}
23892394

23902395
void SystemLayout::setMeasureHeight(System* system, double height, const LayoutContext& ctx)

0 commit comments

Comments
 (0)