Browse Source

Add `ChangeDefaultFormatting()` to `MutableText`

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
b2d3d05790
  1. 15
      sources/Text/MutableText.uc
  2. BIN
      sources/Text/Tests/TEST_Text.uc
  3. 43
      sources/Text/Text.uc

15
sources/Text/MutableText.uc

@ -371,6 +371,21 @@ public final function MutableText Replace(
return self;
}
/**
* Sets `newFormatting` for every non-formatted character in the caller `Text`.
*
* @param newFormatting Formatting to use for all non-formatted character in
* the caller `Text`. If `newFormatting` is not colored itself -
* method does nothing.
* @return Returns caller `MutableText`, to allow for method chaining.
*/
public final function MutableText ChangeDefaultFormatting(
Formatting newFormatting)
{
_changeDefaultFormatting(newFormatting);
return self;
}
/**
* Changes formatting for characters with indices in range, specified as
* `[startIndex; startIndex + maxLength - 1]` to `newFormatting` parameter.

BIN
sources/Text/Tests/TEST_Text.uc

Binary file not shown.

43
sources/Text/Text.uc

@ -982,6 +982,49 @@ protected final function Text DropCodePoints() {
return self;
}
/**
* Sets `newFormatting` for every non-formatted character in the caller `Text`.
* Allows to create mutable child classes.
*
* @param newFormatting Formatting to use for all non-formatted character in
* the caller `Text`. If `newFormatting` is not colored itself -
* method does nothing.
* @return Returns caller `Text`, to allow for method chaining.
*/
protected final function Text _changeDefaultFormatting(Formatting newFormatting)
{
local int i;
local FormattingChunk newFormattingChunk;
local array<FormattingChunk> newFormattingChunks;
if (!newFormatting.isColored) {
return self;
}
newFormattingChunk.formatting = newFormatting;
if ( formattingChunks.length <= 0
|| formattingChunks[0].startIndex > 0)
{
newFormattingChunks[0] = newFormattingChunk;
}
while (i < formattingChunks.length)
{
if (formattingChunks[i].formatting.isColored)
{
newFormattingChunks[newFormattingChunks.length] =
formattingChunks[i];
}
else
{
newFormattingChunk.startIndex = formattingChunks[i].startIndex;
newFormattingChunks[newFormattingChunks.length] =
newFormattingChunk;
}
i += 1;
}
formattingChunks = newFormattingChunks;
NormalizeFormatting();
return self;
}
/**
* Sets formatting for the next code point(s) to be added by
* `AppendCodePoint()` / `AppendManyCodePoints()`.

Loading…
Cancel
Save