CPStyledString

Builder for a styled string rendered using system font.

This utility class provides a builder pattern to built styled (colored) strings that are rendered using a system font. Once styled string is built it can be rendered via CPCanvas.drawStyledString method.

Here's an example of using styled string together with array image to quickly create an image with a styled textual content:

import CPStyledString.styleStr

val lblImg = new CPArrayImage(
   styleStr("[SPACE]", C_WHITE) ++ styleStr("Play|Pause ", C_GREEN) ++
   styleStr("[R]", C_WHITE) ++ styleStr("Rewind ", C_GREEN) ++
   styleStr("[Q]", C_WHITE) ++ styleStr("Quit ", C_GREEN) ++
   styleStr("[CTRL-L]", C_WHITE) ++ styleStr("Log ", C_GREEN) ++
   styleStr("[CTRL-Q]", C_WHITE) ++ styleStr("FPS Overlay", C_GREEN)
).trimBg()
See also:
Example:

See CPFontsExample source code for an example of font functionality.

Companion:
object
Source:
CPStyledString.scala
class Object
trait Matchable
class Any

Value members

Constructors

def this(s: String, fgColor: CPColor, bgColor: CPColor)

Creates styled string.

Creates styled string.

Value parameters:
bgColor

Background color.

fgColor

Foreground color.

s

String.

Source:
CPStyledString.scala
def this(s: String, fgColor: CPColor)

Creates styled string with no background.

Creates styled string with no background.

Value parameters:
fgColor

Foreground color.

s

String.

Source:
CPStyledString.scala

Concrete methods

def bg(bg: Option[CPColor]): CPStyledString

Sets current background color.

Sets current background color.

Value parameters:
bg

Background color to set. Use None to remove background color.

Source:
CPStyledString.scala

Sets current background color.

Sets current background color.

Value parameters:
bg

Background color to set.

Source:
CPStyledString.scala
def build(): Seq[CPPixel]

Finalizes this styled string and renders it into sequence of pixels.

Finalizes this styled string and renders it into sequence of pixels.

Source:
CPStyledString.scala

Clears this styled string.

Clears this styled string.

Source:
CPStyledString.scala

Sets current foreground color.

Sets current foreground color.

Value parameters:
fg

Foreground color to set.

Source:
CPStyledString.scala
def fgbg(fg: CPColor, bg: Option[CPColor]): CPStyledString

Sets current foreground and background colors.

Sets current foreground and background colors.

Value parameters:
bg

Background color to set. Use None to remove background color.

fg

Foreground color to set.

Source:
CPStyledString.scala

Sets current foreground and background colors.

Sets current foreground and background colors.

Value parameters:
bg

Background color to set.

fg

Foreground color to set.

Source:
CPStyledString.scala
def str(obj: Any): CPStyledString

Adds given object string representation to this style string using current foreground and background colors.

Adds given object string representation to this style string using current foreground and background colors.

Value parameters:
obj

Object to add.

Source:
CPStyledString.scala