Add smooth padding transition
This commit is contained in:
parent
00fc160550
commit
c34457730f
@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user