Skip to content

Commit

Permalink
release 1.6.0-beta02 improve header text
Browse files Browse the repository at this point in the history
  • Loading branch information
naulian-codigo committed Jun 23, 2024
1 parent 9c4825c commit 6a569b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion glow-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-compose"
version = "1.6.0-beta01"
version = "1.6.0-beta02"
}
}
}
Expand Down
57 changes: 32 additions & 25 deletions glow-compose/src/main/java/com/naulian/glow_compose/mdx/Mdx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
Expand Down Expand Up @@ -93,7 +92,7 @@ fun HandleNode(node: MdxNode, components: MdxComponents, onClickLink: (String) -
MdxType.ELEMENT -> components.elements(it)

MdxType.TABLE -> components.table(it)
else -> components.text(it, 16.sp, 20.sp) {}
else -> components.text(it, components.textStyle) {}
}
}
}
Expand Down Expand Up @@ -147,10 +146,10 @@ fun AnnotatedString.Builder.handleText(

data class MdxComponents(
val fontFamily: FontFamily,
val textStyle: TextStyle = TextStyle(fontFamily = fontFamily),
val text: @Composable (
node: MdxNode,
size: TextUnit,
height: TextUnit,
style: TextStyle,
onClickLink: (String) -> Unit
) -> Unit,
val paragraph: @Composable (MdxNode, onClickLink: (String) -> Unit) -> Unit,
Expand Down Expand Up @@ -181,23 +180,19 @@ data class MdxParagraphContent(

fun mdxComponents(
fontFamily: FontFamily = FontFamily.Default,
textStyle: TextStyle = TextStyle(fontFamily = fontFamily),
text: @Composable (
node: MdxNode,
size: TextUnit,
height: TextUnit,
style: TextStyle,
onClickLink: (String) -> Unit
) -> Unit = { node, size, height, onClickLink ->
) -> Unit = { node, style, onClickLink ->
when {
node.children.isEmpty() && node.literal.isBlank() -> {}
else -> {
val paragraphContent = buildContentPair(node)
ClickableText(
text = paragraphContent.annotatedString,
style = TextStyle(
fontFamily = fontFamily,
fontSize = size,
lineHeight = height
),
style = style,
) { offset ->
paragraphContent.annotatedString.getStringAnnotations(
start = offset,
Expand All @@ -208,19 +203,31 @@ fun mdxComponents(
}
},
paragraph: @Composable (MdxNode, onClickLink: (String) -> Unit) -> Unit = { node, onClickLink ->
text(node, 16.sp, 20.sp, onClickLink)
val style = textStyle.copy(
fontFamily = fontFamily,
fontSize = 16.sp,
lineHeight = 20.sp,
)
text(node, style, onClickLink)
},
header: @Composable (MdxNode) -> Unit = { node ->
val sizePair = when (node.type) {
MdxType.H1 -> 32.sp to 36.sp
MdxType.H2 -> 28.sp to 32.sp
MdxType.H3 -> 24.sp to 38.sp
MdxType.H4 -> 20.sp to 24.sp
MdxType.H5 -> 18.sp to 22.sp
MdxType.H6 -> 16.sp to 20.sp
MdxType.H1 -> 36.sp to 42.sp
MdxType.H2 -> 32.sp to 36.sp
MdxType.H3 -> 28.sp to 32.sp
MdxType.H4 -> 24.sp to 38.sp
MdxType.H5 -> 20.sp to 24.sp
MdxType.H6 -> 18.sp to 22.sp
else -> 24.sp to 32.sp
}
text(node, sizePair.first, sizePair.second) {}
val style = textStyle.copy(
fontFamily = fontFamily,
fontWeight = FontWeight.Bold,
fontSize = sizePair.first,
lineHeight = sizePair.second,
)

text(node, style) {}
},
quote: @Composable (MdxNode) -> Unit = { node ->
ConstraintLayout(
Expand Down Expand Up @@ -257,7 +264,7 @@ fun mdxComponents(
) {
node.children.forEach {
when (it.type) {
MdxType.PARAGRAPH -> text(it, 16.sp, 20.sp) {}
MdxType.PARAGRAPH -> text(it, textStyle) {}
else -> {}
}
}
Expand Down Expand Up @@ -325,7 +332,7 @@ fun mdxComponents(
when (child.type) {
MdxType.PARAGRAPH -> {
Box(modifier = Modifier.weight(1f)) {
text(child, 16.sp, 20.sp) {}
text(child, textStyle) {}
}
}
}
Expand All @@ -344,7 +351,7 @@ fun mdxComponents(
Spacer(modifier = Modifier.width(12.dp))
element.children.forEach {
when (it.type) {
MdxType.PARAGRAPH -> text(it, 16.sp, 20.sp) {}
MdxType.PARAGRAPH -> text(it, textStyle) {}
else -> {}
}
}
Expand All @@ -357,7 +364,7 @@ fun mdxComponents(
Spacer(modifier = Modifier.width(12.dp))
element.children.forEach {
when (it.type) {
MdxType.PARAGRAPH -> text(it, 16.sp, 20.sp) {}
MdxType.PARAGRAPH -> text(it, textStyle) {}
else -> {}
}
}
Expand All @@ -370,7 +377,7 @@ fun mdxComponents(
Spacer(modifier = Modifier.width(12.dp))
element.children.forEach {
when (it.type) {
MdxType.PARAGRAPH -> text(it, 16.sp, 20.sp) {}
MdxType.PARAGRAPH -> text(it, textStyle) {}
else -> {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion glow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow-core"
version = "1.6.0-beta01"
version = "1.6.0-beta02"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion glow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.naulian"
artifactId = "glow"
version = "1.6.0-beta01"
version = "1.6.0-beta02"
}
}
}
Expand Down

0 comments on commit 6a569b8

Please sign in to comment.