Improve layout of portrait image table cell

This commit is contained in:
0xb00bface 2021-08-21 16:03:45 +02:00
parent cdf32d8437
commit 6c1c10a791
1 changed files with 23 additions and 3 deletions

View File

@ -1,7 +1,10 @@
package ctbrec.ui.tabs.recorded;
import javafx.geometry.Insets;
import javafx.scene.control.TableColumn;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Rectangle;
public class ImageTableCell extends ClickableTableCell<Image> {
@ -13,19 +16,36 @@ public class ImageTableCell extends ClickableTableCell<Image> {
imageView.setPreserveRatio(true);
imageView.prefHeight(64);
imageView.setFitHeight(64);
setPadding(new Insets(5));
setGraphic(imageView);
}
@Override
public void requestLayout() {
double columnWidth = getTableColumn().getWidth();
imageView.prefHeight(columnWidth);
imageView.setFitHeight(columnWidth);
TableColumn<?, ?> tc = getTableColumn();
if (tc != null) {
double columnWidth = getTableColumn().getWidth();
Insets pd = getPadding();
var height = columnWidth - pd.getTop() - pd.getBottom();
var width = columnWidth - pd.getLeft() - pd.getRight() - 3;
imageView.prefHeight(height);
imageView.setFitHeight(height);
imageView.prefWidth(width);
imageView.setFitWidth(width);
var clip = new Rectangle(width, height);
clip.setArcHeight(10);
clip.arcWidthProperty().bind(clip.arcHeightProperty());
imageView.setClip(clip);
}
super.requestLayout();
}
@Override
protected void updateItem(Image image, boolean empty) {
imageView.setImage(empty ? null : image);
super.requestLayout();
}
}