From a539d3014aa8ee70076b8ad8af22429cbefef657 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 24 Jul 2020 14:22:41 +0200 Subject: [PATCH] Add smooth padding transition --- .../envoy/client/ui/listcell/MessageListCell.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java b/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java index d2065fe..80cf215 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java @@ -27,17 +27,15 @@ public final class MessageListCell extends AbstractListCell 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)); } }