Scoop API

scoop:scoop.graphics.text:0.1.0

src/content_builders.scoop

Selected production source · src/content_builders.scoop

1package scoop.graphics.text
3/** Collects text and inline objects, then normalizes one immutable description. */
4public fun styledText(configure: StyledTextBuilder.() -> Unit = {}): StyledText {
5 val builder = StyledTextBuilder()
6 builder.configure()
7 return StyledText(builder.snapshotSpans(), builder.style)
8}
10/** Creates a reusable styled fragment without allocating native text resources. */
11public fun textSpan(configure: TextSpanBuilder.() -> Unit = {}): TextSpan = buildTextSpan(configure)
13private fun buildTextSpan(configure: TextSpanBuilder.() -> Unit): TextSpan {
14 val builder = TextSpanBuilder()
15 builder.configure()
16 return TextSpan(SpanContent.Styled(builder.style, builder.snapshotSpans()))
19/** Ordered content operations shared by complete text and nested fragments. */
20public open class TextChildrenBuilder internal constructor() {
21 private val entries = ArrayList<TextSpan>()
23 public fun add(value: TextSpan): Unit {
24 entries.add(value)
25 }
26 public fun text(value: String): Unit {
27 add(TextSpan(SpanContent.Plain(value)))
28 }
29 public fun span(configure: TextSpanBuilder.() -> Unit = {}): Unit {
30 add(buildTextSpan(configure))
31 }
32 public fun inlineObject(key: InlineKey, alternateText: String): Unit {
33 add(TextSpan(SpanContent.Object(key, alternateText)))
34 }
35 internal fun snapshotSpans(): Array<TextSpan> = entries.toArray()
38/** Configures the complete base style and collects the paragraph's content. */
39public class StyledTextBuilder internal constructor(): TextChildrenBuilder() {
40 public var style: TextStyle = textStyle()
42 public fun style(configure: TextStyleBuilder.() -> Unit): Unit {
43 style = configureTextStyle(style, configure)
44 }
47/** Configures inherited overrides and collects one nested fragment. */
48public class TextSpanBuilder internal constructor(): TextChildrenBuilder() {
49 public var style: SpanStyle = spanStyle()
51 public fun style(configure: SpanStyleBuilder.() -> Unit): Unit {
52 style = configureSpanStyle(style, configure)
53 }