Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Correct spelling of fuzziness
Remove superfluous comment
Add check to only execute fuzzy code when it would have an effect
  • Loading branch information
Eddykasp committed Oct 22, 2024
1 parent 837766f commit 5471120
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@
*/
public class SoftWrappingLabelManager extends AbstractKlighdLabelManager {

/** Amount of line overhang that is permitted in percent of the effevtiveTargetWidth
*
* */

/**
* Returns the amount of line overhang that is permitted in percent of the effevtiveTargetWidth.
* @param label The ElkLabel for which the fuzzyness is requested.
* @return The fuzzyness
* Returns the amount of line overhang that is permitted in percent of the effectiveTargetWidth.
* @param label The ElkLabel for which the fuzziness is requested.
* @return The fuzziness
*/
public double getFuzzyness(final ElkLabel label) {
return label.getProperty(KlighdProperties.SOFTWRAPPING_FUZZYNESS);
public double getFuzziness(final ElkLabel label) {
return label.getProperty(KlighdProperties.SOFTWRAPPING_FUZZINESS);
}

@Override
Expand Down Expand Up @@ -84,24 +80,26 @@ public Result doResizeLabel(final ElkLabel label, final double targetWidth) {
} while (lineWidth < effectiveTargetWidth && currWordIndex < words.length);

// Check whether next line would be below the fuzzy threshold
int previewWordIndex = currWordIndex;
if (previewWordIndex < words.length) {
String previewLineText = words[previewWordIndex];
testText = previewLineText;
do {
previewLineText = testText;
if (previewWordIndex < words.length - 1) {
testText = previewLineText + " " + words[++previewWordIndex];
} else {
testText = " ";
previewWordIndex++;
if (getFuzziness(label) > 0) {
int previewWordIndex = currWordIndex;
if (previewWordIndex < words.length) {
String previewLineText = words[previewWordIndex];
testText = previewLineText;
do {
previewLineText = testText;
if (previewWordIndex < words.length - 1) {
testText = previewLineText + " " + words[++previewWordIndex];
} else {
testText = " ";
previewWordIndex++;
}
lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth();
} while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length);
if (lineWidth < effectiveTargetWidth * getFuzziness(label)) {
// next line would contain too much whitespace so append it to this line
currWordIndex = previewWordIndex;
currentLineText += " " + previewLineText;
}
lineWidth = PlacementUtil.estimateTextSize(font, testText).getWidth();
} while (lineWidth < effectiveTargetWidth && previewWordIndex < words.length);
if (lineWidth < effectiveTargetWidth * getFuzzyness(label)) {
// next line would contain too much whitespace so append it to this line
currWordIndex = previewWordIndex;
currentLineText += " " + previewLineText;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ public static boolean isSelectable(final EObject viewElement) {
new Property<KVector>("klighd.roundedRectangle.autopadding", null);

/**
* Determines the amount of fuzzyness to be used when performing softwrapping on labels.
* Determines the amount of fuzziness to be used when performing softwrapping on labels.
* The value expresses the percent of overhang that is permitted for each line.
* If the next line would take up less space than this threshold, it is appended to the
* current line instead of being placed in a new line.
*/
public static final IProperty<Double> SOFTWRAPPING_FUZZYNESS =
public static final IProperty<Double> SOFTWRAPPING_FUZZINESS =
new Property<Double>("klighd.softwrapping.fuzzyness",0.0);
}

0 comments on commit 5471120

Please sign in to comment.