From a77fe9f89f9de884dd96226f928a5d435608845c Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 24 Jul 2020 14:02:53 +0200 Subject: [PATCH] Adjust message padding immediately --- .../client/ui/listcell/MessageControl.java | 2 +- .../client/ui/listcell/MessageListCell.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java index 418660b..129d2c4 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java @@ -116,7 +116,7 @@ public class MessageControl extends Label { final var statusIcon = new ImageView(statusImages.get(message.getStatus())); statusIcon.setPreserveRatio(true); Region space = new Region(); - hBoxBottom.setHgrow(space, Priority.ALWAYS); + HBox.setHgrow(space, Priority.ALWAYS); hBoxBottom.getChildren().add(space); hBoxBottom.getChildren().add(statusIcon); hBoxBottom.setAlignment(Pos.BOTTOM_RIGHT); 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 2027369..d2065fe 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java @@ -17,26 +17,27 @@ import envoy.data.Message; * @since Envoy Client v0.1-beta */ public final class MessageListCell extends AbstractListCell { + /** * @param listView the list view inside of which the cell will be displayed * @since Envoy Client v0.1-beta */ - public MessageListCell(ListView listView) { - super(listView); - } + public MessageListCell(ListView listView) { super(listView); } @Override protected MessageControl renderItem(Message message) { final var control = new MessageControl(message); - listView.widthProperty() - .addListener((observable, oldValue, newValue) -> { - int padding = 0; - if (newValue.intValue() > 1020) padding = (newValue.intValue() - 1000) / 2; - else padding = 10; - setPadding(new Insets(0, padding, 6, padding)); - }); + listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue())); + adjustPadding((int) listView.getWidth()); 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)); + } }