@@ -278,39 +278,48 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
278
278
System* system = ctx.mutDom ().systems ().front ();
279
279
SystemLayout::setInstrumentNames (system , ctx, /* longNames */ true );
280
280
281
- PointF pos;
282
- bool firstMeasure = true ; // lc.startTick.isZero();
281
+ double targetSystemWidth = ctx.dom ().nmeasures () * ctx.conf ().styleMM (Sid::minMeasureWidth).val ();
282
+ system ->setWidth (targetSystemWidth);
283
+
284
+ double curSystemWidth = 0.0 ;
285
+ bool firstMeasureInScore = true ; // lc.startTick.isZero();
286
+ bool firstMeasureInLayout = true ;
283
287
284
288
// set first measure to lc.nextMeasures for following
285
289
// utilizing in getNextMeasure()
286
290
ctx.mutState ().setNextMeasure (ctx.mutDom ().first ());
287
291
ctx.mutState ().setTick (Fraction (0 , 1 ));
288
292
MeasureLayout::getNextMeasure (ctx);
289
293
294
+ std::set<Measure*> measuresToLayout;
295
+
290
296
while (ctx.state ().curMeasure ()) {
291
- double ww = 0.0 ;
292
297
if (ctx.state ().curMeasure ()->isVBox () || ctx.state ().curMeasure ()->isTBox ()) {
293
298
ctx.mutState ().curMeasure ()->resetExplicitParent ();
294
299
MeasureLayout::getNextMeasure (ctx);
295
300
continue ;
296
301
}
297
302
system ->appendMeasure (ctx.mutState ().curMeasure ());
303
+ bool createHeader = ctx.state ().prevMeasure () && ctx.state ().prevMeasure ()->isHBox ()
304
+ && toHBox (ctx.state ().prevMeasure ())->createSystemHeader ();
298
305
if (ctx.state ().curMeasure ()->isMeasure ()) {
299
306
Measure* m = toMeasure (ctx.mutState ().curMeasure ());
300
307
if (m->mmRest ()) {
301
308
m->mmRest ()->resetExplicitParent ();
302
309
}
303
- if (firstMeasure ) {
304
- SystemLayout::layoutSystem (system , ctx, pos. rx () );
310
+ if (firstMeasureInScore ) {
311
+ SystemLayout::layoutSystem (system , ctx, curSystemWidth, true );
305
312
if (m->repeatStart ()) {
306
313
Segment* s = m->findSegmentR (SegmentType::StartRepeatBarLine, Fraction (0 , 1 ));
307
314
if (!s->enabled ()) {
308
315
s->setEnabled (true );
309
316
}
310
317
}
311
318
MeasureLayout::addSystemHeader (m, true , ctx);
312
- pos.rx () += system ->leftMargin ();
313
- firstMeasure = false ;
319
+ curSystemWidth += system ->leftMargin ();
320
+ firstMeasureInScore = false ;
321
+ } else if (createHeader) {
322
+ MeasureLayout::addSystemHeader (m, false , ctx);
314
323
} else if (m->header ()) {
315
324
MeasureLayout::removeSystemHeader (m);
316
325
}
@@ -325,56 +334,68 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
325
334
if (ctx.conf ().isMode (LayoutMode::HORIZONTAL_FIXED)) {
326
335
MeasureLayout::createEndBarLines (m, true , ctx);
327
336
layoutSegmentsWithDuration (m, visibleParts);
328
- ww = m->width ();
329
- MeasureLayout::stretchMeasureInPracticeMode (m, ww, ctx);
337
+ double measureWidth = m->width ();
338
+ MeasureLayout::stretchMeasureInPracticeMode (m, measureWidth, ctx);
339
+ m->setPos (curSystemWidth, m->y ());
340
+ curSystemWidth += measureWidth;
330
341
} else {
331
- MeasureLayout::createEndBarLines (m, false , ctx);
332
342
MeasureLayout::computePreSpacingItems (m, ctx);
333
- HorizontalSpacing::updateSpacingForLastAddedMeasure (system );
334
- ww = m->width ();
335
- MeasureLayout::layoutMeasureElements (m, ctx);
343
+ MeasureLayout::createEndBarLines (m, false , ctx);
344
+ MeasureLayout::setRepeatCourtesiesAndParens (m, ctx);
345
+ curSystemWidth = HorizontalSpacing::updateSpacingForLastAddedMeasure (system , firstMeasureInLayout);
346
+ measuresToLayout.insert (m);
347
+ if (firstMeasureInLayout) {
348
+ firstMeasureInLayout = false ;
349
+ }
336
350
}
337
351
} else {
338
352
// for measures not in range, use existing layout
339
- ww = m->width ();
340
- if (m->pos () != pos ) {
353
+ double measureWidth = m->width ();
354
+ if (! muse::RealIsEqual ( m->x (), curSystemWidth) ) {
341
355
// fix beam positions
342
356
// other elements with system as parent are processed in layoutSystemElements()
343
357
// but full beam processing is expensive and not needed if we adjust position here
344
- PointF p = pos - m->pos ();
358
+ PointF p = PointF (curSystemWidth, 0.0 ) - m->pos ();
345
359
for (const Segment& s : m->segments ()) {
346
360
if (!s.isChordRestType ()) {
347
361
continue ;
348
362
}
349
363
for (size_t track = 0 ; track < ctx.dom ().ntracks (); ++track) {
350
364
EngravingItem* e = s.element (static_cast <track_idx_t >(track));
351
- if (e) {
352
- ChordRest* cr = toChordRest (e);
353
- if (cr->beam () && cr->beam ()->elements ().front () == cr) {
354
- cr->beam ()->mutldata ()->move (p);
355
- }
365
+ if (!e) {
366
+ continue ;
367
+ }
368
+ ChordRest* cr = toChordRest (e);
369
+ if (cr->beam () && cr->beam ()->elements ().front () == cr) {
370
+ cr->beam ()->mutldata ()->move (p);
356
371
}
357
372
}
358
373
}
359
374
}
375
+ m->setPos (curSystemWidth, m->y ());
376
+ curSystemWidth += measureWidth;
360
377
}
361
- m->setPos (pos);
362
- MeasureLayout::layoutStaffLines (m, ctx);
363
378
} else if (ctx.state ().curMeasure ()->isHBox ()) {
364
- MeasureBase* curM = ctx.mutState ().curMeasure ();
365
- HBox* curHBox = toHBox (curM);
366
- curHBox->setPos (pos + PointF (curHBox->absoluteFromSpatium (curHBox->topGap ()), 0.0 ));
367
- TLayout::layoutBaseMeasureBase (curHBox, curHBox->mutldata (), ctx);
368
- ww = curHBox->width ();
379
+ curSystemWidth = HorizontalSpacing::updateSpacingForLastAddedMeasure (system );
369
380
}
370
- pos.rx () += ww;
371
381
372
382
MeasureLayout::getNextMeasure (ctx);
373
383
}
374
384
385
+ for (Measure* m : measuresToLayout) {
386
+ MeasureLayout::layoutMeasureElements (m, ctx);
387
+ }
388
+
389
+ for (MeasureBase* m : system ->measures ()) {
390
+ if (!m->isMeasure ()) {
391
+ continue ;
392
+ }
393
+ MeasureLayout::layoutStaffLines (toMeasure (m), ctx);
394
+ }
395
+
375
396
SystemLayout::hideEmptyStaves (system , ctx, true );
376
397
377
- system ->setWidth (pos. x () );
398
+ system ->setWidth (curSystemWidth );
378
399
}
379
400
380
401
static Segment* findFirstEnabledSegment (Measure* measure)
0 commit comments