Adjust message padding immediately

This commit is contained in:
Kai S. K. Engelbart 2020-07-24 14:02:53 +02:00
parent 1b373d9694
commit a77fe9f89f
No known key found for this signature in database
GPG Key ID: 0A48559CA32CB48F
2 changed files with 12 additions and 11 deletions

View File

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

View File

@ -17,26 +17,27 @@ import envoy.data.Message;
* @since Envoy Client v0.1-beta
*/
public final class MessageListCell extends AbstractListCell<Message, MessageControl> {
/**
* @param listView the list view inside of which the cell will be displayed
* @since Envoy Client v0.1-beta
*/
public MessageListCell(ListView<? extends Message> listView) {
super(listView);
}
public MessageListCell(ListView<? extends Message> 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));
}
}