Skip to content

Commit

Permalink
Merge pull request #51 from InkApplications/breaks
Browse files Browse the repository at this point in the history
Add Break support in FormattedText
  • Loading branch information
ReneeVandervelde authored Oct 6, 2024
2 parents c473239 + 7b740d7 commit d3b1fdb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private fun Tag.render(
}
}
}
FormattedText.Span.Break -> br
}
}
}
9 changes: 9 additions & 0 deletions structures/api/structures.api
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public final class ink/ui/structures/elements/FormattedText$Builder {
public fun <init> ()V
public fun <init> (Ljava/util/List;)V
public synthetic fun <init> (Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun br ()V
public final fun code (ZLkotlin/jvm/functions/Function1;)V
public static synthetic fun code$default (Link/ui/structures/elements/FormattedText$Builder;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun component1 ()Ljava/util/List;
Expand All @@ -219,6 +220,14 @@ public abstract interface class ink/ui/structures/elements/FormattedText$Span {
public abstract fun toPlainString ()Ljava/lang/String;
}

public final class ink/ui/structures/elements/FormattedText$Span$Break : ink/ui/structures/elements/FormattedText$Span {
public static final field INSTANCE Link/ui/structures/elements/FormattedText$Span$Break;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toPlainString ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
}

public final class ink/ui/structures/elements/FormattedText$Span$Code : ink/ui/structures/elements/FormattedText$Span$Composite {
public fun <init> (Ljava/util/List;Z)V
public synthetic fun <init> (Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class FormattedText(
when (span) {
is Span.Text -> span.text
is Span.Composite -> span.inner.joinToString("") { it.toPlainString() }
Span.Break -> "\n"
}
},
style = style,
Expand Down Expand Up @@ -44,11 +45,13 @@ data class FormattedText(
override val inner: List<Span>,
val url: String,
): Composite
data object Break: Span

fun toPlainString(): String {
return when (this) {
is Text -> text
is Composite -> inner.joinToString("") { it.toPlainString() }
Break -> "\n"
}
}
}
Expand All @@ -74,5 +77,8 @@ data class FormattedText(
fun space() {
spans.add(Span.Text(" "))
}
fun br() {
spans.add(Span.Break)
}
}
}

0 comments on commit d3b1fdb

Please sign in to comment.