Skip to content

Commit

Permalink
2.1.0: Kotlin 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SalomonBrys committed May 22, 2024
1 parent 8113030 commit 43491bb
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 157 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*~
.DS_STORE

# KOTLIN
.kotlin

# GRADLE
.gradle
build/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

allprojects {
group = "net.kodein.themes"
version = "2.0.0"
version = "2.1.0"
}

subprojects {
Expand Down
1 change: 1 addition & 0 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.kotlin.plugin.compose)
`maven-publish`
}

Expand Down
1 change: 1 addition & 0 deletions compose/compose-m2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.kotlin.plugin.compose)
`maven-publish`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public fun Link(
Box(
modifier = modifier
.pointerHoverIcon(PointerIcon.Hand)
.clickable {
uriHandler.openUri(uri)
}
.clickable { uriHandler.openUri(uri) }
) {
ProvideTextStyle(TextStyle(color = MaterialTheme.colors.primary)) {
content()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.kodein.theme.compose

import org.jetbrains.compose.resources.FontResource
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.ResourceItem


@OptIn(InternalResourceApi::class)
internal fun FontResource(file: String): FontResource {
val id = file.split('/').last().removeSuffix(".ttf").replace('-', '_')
return FontResource(
id = "font:$id",
items = setOf(
ResourceItem(
qualifiers = emptySet(),
path = file,
offset = -1,
size = -1
)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.Font
import org.jetbrains.compose.resources.FontResource
import org.jetbrains.compose.resources.*


@OptIn(ExperimentalResourceApi::class)
private object JetBrainsMonoResources {
val Thin: FontResource by lazy { FontResource("font/JetBrainsMono-Thin.ttf") }
val ThinItalic: FontResource by lazy { FontResource("font/JetBrainsMono-ThinItalic.ttf") }
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions cup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.kotlin.plugin.compose)
`maven-publish`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.kodein.theme.cup

import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import net.kodein.cup.ui.cupScaleDown
import net.kodein.cup.widgets.material.cupScaleDown
import net.kodein.theme.compose.m2.KodeinMaterialColors
import net.kodein.theme.compose.m2.kodeinMaterialShapes
import net.kodein.theme.compose.m2.kodeinMaterialTypography
Expand Down
66 changes: 0 additions & 66 deletions cup/src/commonMain/kotlin/net/kodein/theme/cup/KodeinLogo.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private fun BoxScope.ProgressBar(presentationState: PresentationState) {

@Composable
public fun KodeinPresentation(
slides: SlideGroup
slides: SlideGroup,
decoration: @Composable BoxScope.(@Composable BoxScope.() -> Unit) -> Unit = { it() },
) {
remember {
// https://github.com/kosi-libs/Emoji.kt?tab=readme-ov-file#initializing-the-emoji-service
Expand Down Expand Up @@ -94,17 +95,19 @@ public fun KodeinPresentation(
.fillMaxSize()
.background(overBackground)
) {
Box(
modifier = Modifier
.padding(8.dp)
) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colors.onBackground,
decoration {
Box(
modifier = Modifier
.padding(8.dp)
) {
slidesContent()
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colors.onBackground,
) {
slidesContent()
}
}
ProgressBar(presentationState)
}
ProgressBar(presentationState)
}
}
}
Expand Down
37 changes: 27 additions & 10 deletions cup/src/commonMain/kotlin/net/kodein/theme/cup/KodeinSourceCode.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package net.kodein.theme.cup

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import net.kodein.cup.sa.SourceCode
import net.kodein.theme.KodeinColors
import net.kodein.theme.compose.Color
import net.kodein.theme.compose.JetBrainsMono
import net.kodein.theme.compose.JetBrainsMonoNL

Expand All @@ -18,16 +23,28 @@ import net.kodein.theme.compose.JetBrainsMonoNL
public fun KodeinSourceCode(
sourceCode: SourceCode,
step: Int = 0,
modifier: Modifier = Modifier,
file: String? = null,
fontSize: TextUnit = TextUnit.Unspecified,
style: TextStyle = TextStyle(),
modifier: Modifier = Modifier
) {
SourceCode(
sourceCode = sourceCode,
step = step,
style = TextStyle(fontFamily = JetBrainsMono, fontSize = 12.sp) + style,
theme = KodeinSourceCodeTheme,
modifier = modifier
.background(Color.DarkGray, RoundedCornerShape(4.dp))
.padding(8.dp)
)
val mergedStyle = TextStyle(fontFamily = JetBrainsMono, fontSize = 12.sp) + style + TextStyle(fontSize = fontSize)
Column {
if (file != null) {
Text(
text = file,
color = Color(KodeinColors.purple_light),
style = mergedStyle
)
}
SourceCode(
sourceCode = sourceCode,
step = step,
style = mergedStyle,
theme = KodeinSourceCodeTheme,
modifier = modifier
.background(Color.DarkGray, RoundedCornerShape(4.dp))
.padding(8.dp)
)
}
}
21 changes: 19 additions & 2 deletions cup/src/commonMain/kotlin/net/kodein/theme/cup/KodeinStyleSheet.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package net.kodein.theme.cup

import androidx.compose.runtime.Composable
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import net.kodein.cup.ui.SpanStyleSheet
import net.kodein.cup.ui.styled
import net.kodein.theme.compose.JetBrainsMono


public object KodeinStyleSheet : SpanStyleSheet() {
public abstract class KodeinStyleSheet : SpanStyleSheet() {
/** Light */
public val l: Marker by registerMarker(SpanStyle(fontWeight = FontWeight.Light))
/** Normal */
public val n: Marker by registerMarker(SpanStyle(fontWeight = FontWeight.Normal))
/** Medium */
public val m: Marker by registerMarker(SpanStyle(fontWeight = FontWeight.Medium))

public companion object : KodeinStyleSheet()
}

public class ComposeKodeinStyleSheet(
private val jetBrainsMono: FontFamily
) : KodeinStyleSheet() {
/** Source Code */
public val sc: Marker by registerMarker(SpanStyle(fontFamily = jetBrainsMono))
}

public fun kStyled(build: KodeinStyleSheet.() -> String): AnnotatedString = styled(KodeinStyleSheet, build)
public fun kStyled(build: KodeinStyleSheet.() -> String): AnnotatedString =
styled(KodeinStyleSheet, build)

@Composable
public fun kcStyled(build: ComposeKodeinStyleSheet.() -> String): AnnotatedString =
styled(ComposeKodeinStyleSheet(JetBrainsMono), build)
Loading

0 comments on commit 43491bb

Please sign in to comment.