Skip to content

Commit

Permalink
Improve final decision for groups per row approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
haydar-metin committed Feb 27, 2024
1 parent 413ca77 commit 2bc98bd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/webview/columns/data-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ export namespace DataColumn {
const groupsPerRowFit = Math.floor(fittingCharacters / wordsPerGroupCharacters);

if (groupsPerRowFit > 1) {
// Include other necessary calculations such as margins
const marginRights = (groupsPerRowFit - 1) * Styles.MARGIN_RIGHT_PX;
// Final width if we would render it
const finalWidth = characterWidth * wordsPerGroupCharacters * groupsPerRowFit + marginRights;
const isFit = finalWidth <= columnWidth;
// Take the groups per row or return a group smaller
return isFit ? groupsPerRowFit : groupsPerRowFit - 1;
for (let check = groupsPerRowFit; check > 0; check--) {
// Include other necessary calculations such as margins
const marginRights = (check - 1) * Styles.MARGIN_RIGHT_PX;
// Final width if we would render it
const finalWidth = characterWidth * wordsPerGroupCharacters * check + marginRights;
const isFitting = finalWidth <= columnWidth;
// Take the groups per row if it fits
if (isFitting) {
return check;
}
}

return 1;
}

return groupsPerRowFit;
Expand Down

0 comments on commit 2bc98bd

Please sign in to comment.