Skip to content

Commit

Permalink
Scale down thumbnails if they overflow.
Browse files Browse the repository at this point in the history
Resolves #42
  • Loading branch information
RensAlthuis committed May 16, 2021
1 parent 5712f40 commit 46a0925
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions workspaceThumbnail.js
Expand Up @@ -150,13 +150,13 @@ var ThumbnailsBoxOverride = {
const portholeHeight = this._porthole.height;
const ratio = portholeHeight / portholeWidth;

const width = box.get_width();
const height = Math.round(width * ratio);
var width = box.get_width();
var height = Math.round(width * ratio);

let vScale = width / portholeWidth;
let hScale = height / portholeHeight;

const spacing = themeNode.get_length('spacing');
var spacing = themeNode.get_length('spacing');

let indicatorValue = this._scrollAdjustment.value;
let indicatorUpperWs = Math.ceil(indicatorValue);
Expand All @@ -177,8 +177,13 @@ var ThumbnailsBoxOverride = {
}

let thumbnails_position = (global.vertical_overview.settings.object.get_int('thumbnails-position') || 1);
let totalHeight = (height * this._thumbnails.length) + spacing;
box.y1 = (box.get_height() - totalHeight) / (100 / thumbnails_position);
let totalHeight = (height + spacing) * this._thumbnails.length;
box.y1 = Math.max(0, (box.get_height() - totalHeight) / (100 / thumbnails_position));

let additionalScale = (box.get_height() < totalHeight) ? box.get_height() / totalHeight : 1;
height *= additionalScale;
width *= additionalScale;
spacing *= additionalScale;

let childBox = new Clutter.ActorBox();
for (let i = 0; i < this._thumbnails.length; i++) {
Expand All @@ -197,11 +202,11 @@ var ThumbnailsBoxOverride = {
});
}

if(this._dropPlaceholderPos !== -1 && this._dropPlaceholderPos <= i) {
if (this._dropPlaceholderPos !== -1 && this._dropPlaceholderPos <= i) {
y1 += placeholderHeight + spacing;
}

childBox.set_origin(box.x1, y1);
childBox.set_origin(box.x1 + (box.get_width() - width), y1);
childBox.set_size(width, height);
thumbnail.setScale(vScale, hScale);
thumbnail.allocate(childBox);
Expand All @@ -222,8 +227,8 @@ var ThumbnailsBoxOverride = {
let indicatorLeftFullBorder = indicatorThemeNode.get_padding(St.Side.LEFT) + indicatorThemeNode.get_border_width(St.Side.LEFT);
let indicatorRightFullBorder = indicatorThemeNode.get_padding(St.Side.RIGHT) + indicatorThemeNode.get_border_width(St.Side.RIGHT);

childBox.x1 = box.x1;
childBox.x2 = box.x1 + width;
childBox.x1 = box.x1 + (box.get_width() - width);
childBox.x2 = box.x1 + box.get_width();

const indicatorY1 = indicatorLowerY1 +
(indicatorUpperY1 - indicatorLowerY1) * (indicatorValue % 1);
Expand Down

0 comments on commit 46a0925

Please sign in to comment.