Skip to content

Commit 49057c0

Browse files
committed
CSSTUDIO-3524 Use doubles instead of integers when distributing widgets equally horizontally.
1 parent 54fe3ed commit 49057c0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

app/display/editor/src/main/java/org/csstudio/display/builder/editor/actions/ActionDescription.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void run(final DisplayEditor editor, final boolean selected)
506506
.mapToInt(w -> w.propWidth().getValue())
507507
.sum();
508508

509-
final int offset = ( max - min - totalWidth ) / ( N - 1 );
509+
final double offset = ( (double) max - (double) min - (double) totalWidth ) / ( (double) N - 1.0 );
510510
final List<Widget> sortedWidgets = widgets.stream()
511511
.sorted(( w1, w2 ) ->
512512
{
@@ -550,15 +550,15 @@ else if ( w1x >= w2x && w1x + w1w >= w2x + w2w )
550550
// Equal gap distribution...
551551
// ------------------------------------------------------------
552552
Widget widget = sortedWidgets.get(0);
553-
int location = widget.propX().getValue();
553+
double location = widget.propX().getValue();
554554
int width = widget.propWidth().getValue();
555555

556556
for ( int i = 1; i < N - 1; i++ )
557557
{
558558
widget = sortedWidgets.get(i);
559559
location += width + offset;
560560

561-
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), location));
561+
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), (int) Math.round(location)));
562562

563563
width = widget.propWidth().getValue();
564564
}
@@ -575,20 +575,20 @@ else if ( offset < 0 )
575575
int location = widget.propX().getValue();
576576
int width = widget.propWidth().getValue();
577577

578-
final int rightCenter = location + width / 2;
578+
final double rightCenter = (double) location + (double) width / 2.0;
579579

580580
widget = sortedWidgets.get(0);
581581
location = widget.propX().getValue();
582582
width = widget.propWidth().getValue();
583583

584584
final int leftCenter = location + width / 2;
585-
final int coffset = ( rightCenter - leftCenter ) / ( N - 1 );
585+
final double coffset = ( rightCenter - leftCenter ) / ( (double) N - 1.0 );
586586

587587
for ( int i = 1; i < N - 1; i++ )
588588
{
589589
widget = sortedWidgets.get(i);
590590
width = widget.propWidth().getValue();
591-
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), ( leftCenter + i * coffset ) - width / 2));
591+
undo.execute(new SetWidgetPropertyAction<>(widget.propX(), (int) Math.round(( leftCenter + i * coffset ) - (double) width / 2.0)));
592592
}
593593
}
594594
}

0 commit comments

Comments
 (0)