Skip to content

Commit 54fe3ed

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

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public void run(final DisplayEditor editor, final boolean selected)
620620
.mapToInt(w -> w.propHeight().getValue())
621621
.sum();
622622

623-
final int offset = ( max - min - totalHeight ) / ( N - 1 );
623+
final double offset = ( (double) max - (double) min - (double) totalHeight ) / ( (double) N - 1.0 );
624624
final List<Widget> sortedWidgets = widgets.stream()
625625
.sorted(( w1, w2 ) ->
626626
{
@@ -680,14 +680,14 @@ else if ( w1y >= w2y && w1y + w1h >= w2y + w2h )
680680
// Equal gap distribution...
681681
// ------------------------------------------------------------
682682
Widget widget = sortedWidgets.get(0);
683-
int location = widget.propY().getValue();
683+
double location = widget.propY().getValue();
684684
int height = widget.propHeight().getValue();
685685

686686
for ( int i = 1; i < N - 1; i++ )
687687
{
688688
widget = sortedWidgets.get(i);
689689
location += height + offset;
690-
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), location));
690+
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), (int) Math.round(location)));
691691
height = widget.propHeight().getValue();
692692
}
693693
}
@@ -703,19 +703,19 @@ else if ( offset < 0 )
703703
int location = widget.propY().getValue();
704704
int height = widget.propHeight().getValue();
705705

706-
final int bottomCenter = location + height / 2;
706+
final double bottomCenter = (double) location + (double) height / 2.0;
707707

708708
widget = sortedWidgets.get(0);
709709
location = widget.propY().getValue();
710710
height = widget.propHeight().getValue();
711711

712-
final int topCenter = location + height / 2;
713-
final int coffset = ( bottomCenter - topCenter ) / ( N - 1 );
712+
final double topCenter = (double) location + (double) height / 2.0;
713+
final double coffset = ( bottomCenter - topCenter ) / ( (double) N - 1.0 );
714714
for ( int i = 1; i < N - 1; i++ )
715715
{
716716
widget = sortedWidgets.get(i);
717717
height = widget.propHeight().getValue();
718-
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), ( topCenter + i * coffset ) - height / 2));
718+
undo.execute(new SetWidgetPropertyAction<>(widget.propY(), (int) Math.round(( topCenter + (double) i * coffset ) - (double) height / 2.0)));
719719
}
720720
}
721721
}

0 commit comments

Comments
 (0)