Add smooth padding transition
This commit is contained in:
parent
a77fe9f89f
commit
a539d3014a
@ -27,17 +27,15 @@ public final class MessageListCell extends AbstractListCell<Message, MessageCont
|
|||||||
@Override
|
@Override
|
||||||
protected MessageControl renderItem(Message message) {
|
protected MessageControl renderItem(Message message) {
|
||||||
final var control = new MessageControl(message);
|
final var control = new MessageControl(message);
|
||||||
listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue()));
|
listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue(), control.isOwnMessage()));
|
||||||
adjustPadding((int) listView.getWidth());
|
adjustPadding((int) listView.getWidth(), control.isOwnMessage());
|
||||||
if (control.isOwnMessage()) setAlignment(Pos.CENTER_RIGHT);
|
if (control.isOwnMessage()) setAlignment(Pos.CENTER_RIGHT);
|
||||||
else setAlignment(Pos.CENTER_LEFT);
|
else setAlignment(Pos.CENTER_LEFT);
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustPadding(int listWidth) {
|
private void adjustPadding(int listWidth, boolean ownMessage) {
|
||||||
int padding = 0;
|
int padding = 10 + Math.max((listWidth - 1000) / 2, 0);
|
||||||
if (listWidth > 1020) padding = (listWidth - 1000) / 2;
|
setPadding(ownMessage ? new Insets(0, padding, 6, 0) : new Insets(0, 0, 6, padding));
|
||||||
else padding = 10;
|
|
||||||
setPadding(new Insets(0, padding, 6, padding));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user