mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
allow word breaking of node name with long word
This commit is contained in:
parent
f0839571d0
commit
247052df5f
@ -98,18 +98,36 @@ RED.palette = (function() {
|
||||
|
||||
var displayLines = [];
|
||||
|
||||
var currentLine = words[0];
|
||||
var currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
|
||||
|
||||
for (var i=1;i<words.length;i++) {
|
||||
var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "red-ui-palette-label", 0);
|
||||
var currentLine = "";
|
||||
for (var i=0;i<words.length;i++) {
|
||||
var word = words[i];
|
||||
var sep = (i == 0) ? "" : " ";
|
||||
var newWidth = RED.view.calculateTextWidth(currentLine+sep+word, "red-ui-palette-label", 0);
|
||||
if (newWidth < nodeWidth) {
|
||||
currentLine += " "+words[i];
|
||||
currentLineWidth = newWidth;
|
||||
currentLine += sep +word;
|
||||
} else {
|
||||
displayLines.push(currentLine);
|
||||
currentLine = words[i];
|
||||
currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
|
||||
if (i > 0) {
|
||||
displayLines.push(currentLine);
|
||||
}
|
||||
while (true) {
|
||||
var wordWidth = RED.view.calculateTextWidth(word, "red-ui-palette-label", 0);
|
||||
if (wordWidth >= nodeWidth) {
|
||||
// break word if too wide
|
||||
for(var j = word.length; j > 0; j--) {
|
||||
var s = word.substring(0, j);
|
||||
var width = RED.view.calculateTextWidth(s, "red-ui-palette-label", 0);
|
||||
if (width < nodeWidth) {
|
||||
displayLines.push(s);
|
||||
word = word.substring(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentLine = word;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
displayLines.push(currentLine);
|
||||
|
Loading…
Reference in New Issue
Block a user