Skip to content

UXTextStyle

Rich text in UXKit is a Foundation AttributedString. UXTextStyle names the attributes UXKit draws and reads them as one value:

AttributeValueDefault
bold, italic, underline, monospaceNumber booleansoff
penNumber, the colour pen1, ink
colorNumber, 0xRRGGBBnone: the view’s ink
sizeNumber, the point size0: the view’s own
alignmentNumber, UX_ALIGN_*UX_ALIGN_LEFT

UXTextView applies alignment to whole paragraphs and draws color; the drawn text views use pen. Other attributes are kept by the string and ignored when drawing. From 0.72.

#import "UXTextStyle.xc"
AttributedString* s = AttributedString.withString(String.withCString("The quick fox"));
UXTextStyle.setBold(s, true, (i32)4, (i32)5); // "quick"
UXTextStyle.setPen(s, (i32)2, (i32)10, (i32)3); // "fox" in red
UXTextStyle* st = UXTextStyle.at(s, (i32)4); // st.bold is true

UXTextLayout measures and wraps each run in its own style, and UXMarkdown produces strings styled this way.

of · at · sameAs · setBold · setItalic · setUnderline · setMonospace · setPen · setColor · setSize · setAlignment

static UXTextStyle* of(Map* attrs)

The style an attribute set describes. Names it does not have keep their defaults. The fields are bold, italic, underline, monospace, pen, color (-1 for none), size and alignment.

static UXTextStyle* at(AttributedString* as, i32 i)

The style of the byte at i.

bool sameAs(UXTextStyle* o)

Whether two styles draw the same.

setBold / setItalic / setUnderline / setMonospace / setPen / setColor / setSize / setAlignment

Section titled “setBold / setItalic / setUnderline / setMonospace / setPen / setColor / setSize / setAlignment”
static void setBold(AttributedString* as, bool v, i32 start, i32 len)
static void setItalic(AttributedString* as, bool v, i32 start, i32 len)
static void setUnderline(AttributedString* as, bool v, i32 start, i32 len)
static void setMonospace(AttributedString* as, bool v, i32 start, i32 len)
static void setPen(AttributedString* as, i32 pen, i32 start, i32 len)
static void setColor(AttributedString* as, i32 rgb, i32 start, i32 len)
static void setSize(AttributedString* as, i16 size, i32 start, i32 len)
static void setAlignment(AttributedString* as, i32 align, i32 start, i32 len)

Set one attribute over len bytes from start. setColor with -1 takes the colour off, back to the view’s ink.