Add smooth padding transition

This commit is contained in:
Kai S. K. Engelbart 2020-07-24 14:22:41 +02:00
parent a77fe9f89f
commit a539d3014a
No known key found for this signature in database
GPG Key ID: 0A48559CA32CB48F

View File

@ -27,17 +27,15 @@ public final class MessageListCell extends AbstractListCell<Message, MessageCont
@Override
protected MessageControl renderItem(Message message) {
final var control = new MessageControl(message);
listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue()));
adjustPadding((int) listView.getWidth());
listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue(), control.isOwnMessage()));
adjustPadding((int) listView.getWidth(), control.isOwnMessage());
if (control.isOwnMessage()) setAlignment(Pos.CENTER_RIGHT);
else setAlignment(Pos.CENTER_LEFT);
return control;
}
private void adjustPadding(int listWidth) {
int padding = 0;
if (listWidth > 1020) padding = (listWidth - 1000) / 2;
else padding = 10;
setPadding(new Insets(0, padding, 6, padding));
private void adjustPadding(int listWidth, boolean ownMessage) {
int padding = 10 + Math.max((listWidth - 1000) / 2, 0);
setPadding(ownMessage ? new Insets(0, padding, 6, 0) : new Insets(0, 0, 6, padding));
}
}