Add smooth padding transition

This commit is contained in:
Kai S. K. Engelbart 2020-07-24 14:22:41 +02:00
parent 00fc160550
commit c34457730f

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));
}
}