From d7819a5ad4396750d6fb20ddfd1b77d5a5d92da1 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sun, 16 Jul 2017 21:03:37 +0200 Subject: [PATCH] improving grid --- frontend/app/gallery/grid/GridRowBuilder.ts | 7 +++++-- frontend/app/gallery/grid/grid.gallery.component.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/app/gallery/grid/GridRowBuilder.ts b/frontend/app/gallery/grid/GridRowBuilder.ts index 166f08f..36e2826 100644 --- a/frontend/app/gallery/grid/GridRowBuilder.ts +++ b/frontend/app/gallery/grid/GridRowBuilder.ts @@ -7,7 +7,10 @@ export class GridRowBuilder { private photoIndex: number = 0; //index of the last pushed photo to the photoRow - constructor(private photos: Array, private startIndex: number, private photoMargin: number, private containerWidth: number) { + constructor(private photos: Array, + private startIndex: number, + private photoMargin: number, + private containerWidth: number) { this.photoIndex = startIndex; } @@ -17,7 +20,7 @@ export class GridRowBuilder { } } - public addPhoto(): boolean { + private addPhoto(): boolean { if (this.photoIndex + 1 > this.photos.length) { return false; } diff --git a/frontend/app/gallery/grid/grid.gallery.component.ts b/frontend/app/gallery/grid/grid.gallery.component.ts index 57f2cd7..90af99e 100644 --- a/frontend/app/gallery/grid/grid.gallery.component.ts +++ b/frontend/app/gallery/grid/grid.gallery.component.ts @@ -192,11 +192,19 @@ export class GalleryGridComponent implements OnChanges, AfterViewInit { let maxRowHeight = window.innerHeight / this.MIN_ROW_COUNT; let minRowHeight = window.innerHeight / this.MAX_ROW_COUNT; - let photoRowBuilder = new GridRowBuilder(this.photos, this.renderedPhotoIndex, this.IMAGE_MARGIN, this.containerWidth - this.overlayService.getPhantomScrollbarWidth()); + let photoRowBuilder = new GridRowBuilder(this.photos, + this.renderedPhotoIndex, + this.IMAGE_MARGIN, + this.containerWidth - this.overlayService.getPhantomScrollbarWidth() + ); + photoRowBuilder.addPhotos(this.TARGET_COL_COUNT); photoRowBuilder.adjustRowHeightBetween(minRowHeight, maxRowHeight); - let rowHeight = photoRowBuilder.calcRowHeight(); + if (photoRowBuilder.getPhotoRow().length > 1) { //little trick: We don't want too big single images. But if a little extra height helps fit the row, its ok + maxRowHeight *= 1.2; + } + let rowHeight = Math.min(photoRowBuilder.calcRowHeight(), maxRowHeight); let imageHeight = rowHeight - (this.IMAGE_MARGIN * 2); photoRowBuilder.getPhotoRow().forEach((photo) => {