Add binding from list width to message padding
This commit is contained in:
parent
408e27b077
commit
49ecba6c23
@ -1,5 +1,6 @@
|
|||||||
package envoy.client.ui.listcell;
|
package envoy.client.ui.listcell;
|
||||||
|
|
||||||
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
|
|
||||||
@ -20,12 +21,18 @@ public final class MessageListCell extends AbstractListCell<Message, MessageCont
|
|||||||
* @param listView the list view inside of which the cell will be displayed
|
* @param listView the list view inside of which the cell will be displayed
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public MessageListCell(ListView<? extends Message> listView) { super(listView); }
|
public MessageListCell(ListView<? extends Message> listView) {
|
||||||
|
super(listView);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MessageControl renderItem(Message message) {
|
protected MessageControl renderItem(Message message) {
|
||||||
final var control = new MessageControl(message);
|
final var control = new MessageControl(message);
|
||||||
maxWidthProperty().bind(listView.widthProperty().multiply(0.6));
|
listView.widthProperty()
|
||||||
|
.addListener((observable, oldValue, newValue) -> {
|
||||||
|
int padding = Math.min(100, newValue.intValue() / 10);
|
||||||
|
setPadding(new Insets(0, padding, 0, padding));
|
||||||
|
});
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user