scoop:scoop.graphics.text:0.1.0
src/content_builders.scoop
Selected production source · src/content_builders.scoop
1
package scoop.graphics.text3
/** Collects text and inline objects, then normalizes one immutable description. */4
public 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. */11
public fun textSpan(configure: TextSpanBuilder.() -> Unit = {}): TextSpan = buildTextSpan(configure)13
private fun buildTextSpan(configure: TextSpanBuilder.() -> Unit): TextSpan {14
val builder = TextSpanBuilder()15
builder.configure()16
return TextSpan(SpanContent.Styled(builder.style, builder.snapshotSpans()))17
}19
/** Ordered content operations shared by complete text and nested fragments. */20
public 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()36
}38
/** Configures the complete base style and collects the paragraph's content. */39
public 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
}45
}47
/** Configures inherited overrides and collects one nested fragment. */48
public 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
}54
}