Skip to content

Commit

Permalink
Merge branch 'sourcecode-lastempystep-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
SalomonBrys committed May 22, 2024
2 parents 9ea2107 + e885d11 commit 285fc4f
Show file tree
Hide file tree
Showing 31 changed files with 4,021 additions and 1,117 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
build/
.gradletasknamecache

### Kotlin ###
.kotlin

### IntelliJ IDEA ###
.idea

Expand Down
4 changes: 2 additions & 2 deletions Compose-Ur-Pres/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.kotlin.plugin.compose) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.mavenPublish) apply false
}

allprojects {
group = "net.kodein.cup"
version = "1.0.0-Beta-02"
version = "1.0.0-Beta-03"

/*
In a composite build, tasks run from the root will not automatically propagate to subprojects (see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class CupPlugin : Plugin<Project> {
if (composeDeps !is ComposePlugin.Dependencies) error("invalid kotlin.compose extension")

repositories {
mavenLocal()
mavenCentral()
google()
}
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions Compose-Ur-Pres/cup-source-code/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)
alias(libs.plugins.dokka)
alias(libs.plugins.mavenPublish)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private fun SourceCodePart(
textMeasurer = textMeasurer,
text = part.block.debugName,
maxLines = 1,
softWrap = false,
style = TextStyle(
color = Color.White.copy(alpha = 1f - dim),
fontSize = 4.sp,
Expand Down Expand Up @@ -205,6 +206,7 @@ private fun SourceCodePart(
},
style = textStyle,
maxLines = 1,
softWrap = false,
modifier = Modifier
.alpha(1f - dim * 0.85f)
)
Expand Down
4,270 changes: 3,449 additions & 821 deletions Compose-Ur-Pres/cup-source-code/src/jvmMain/resources/highlight.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Compose-Ur-Pres/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)
alias(libs.plugins.dokka)
alias(libs.plugins.mavenPublish)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.input.key.*
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import kotlin.jvm.JvmInline


@JvmInline
public value class CupKeyEvent internal constructor(internal val nativeKeyEvent: Any)

public expect val CupKeyEvent.key: Key
public expect val CupKeyEvent.isCtrlPressed: Boolean
public expect val CupKeyEvent.isAltPressed: Boolean
public expect val CupKeyEvent.isShiftPressed: Boolean
public expect val CupKeyEvent.isMetaPressed: Boolean
public expect val CupKeyEvent.type: KeyEventType


@Composable
public fun PresentationKeyHandler(
getState: () -> PresentationState?,
): (KeyEvent) -> Boolean {
): (CupKeyEvent) -> Boolean {
val fullScreenToggle by rememberUpdatedState(LocalFullScreenState.current?.second ?: {})
val ltr by rememberUpdatedState(LocalLayoutDirection.current == LayoutDirection.Ltr)

Expand Down Expand Up @@ -75,7 +87,7 @@ public fun PresentationKeyHandler(
}

@Composable
public fun PresentationKeyHandler(): (KeyEvent) -> Boolean {
public fun PresentationKeyHandler(): (CupKeyEvent) -> Boolean {
val state = LocalPresentationState.current
return PresentationKeyHandler { state }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package net.kodein.cup
@RequiresOptIn("This API is public for CuP Plugins, it should not be used in presentations.")
public annotation class PluginCupAPI()

@RequiresOptIn("This API is internal mto CuP, it may change or disappear without warning.")
@RequiresOptIn("This API is internal to CuP, it may change or disappear without warning.")
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS)
public annotation class InternalCupAPI()
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.key.KeyEvent
import net.kodein.cup.CupKeyEvent
import net.kodein.cup.PluginCupAPI


Expand All @@ -18,7 +19,7 @@ public data class CupAdditionalOverlay(

@PluginCupAPI
public interface CupPlugin {
public fun onKeyEvent(event: KeyEvent): Boolean = false
public fun onKeyEvent(event: CupKeyEvent): Boolean = false

@Composable
public fun BoxScope.Content()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.kodein.cup

import androidx.compose.ui.input.key.*


public actual val CupKeyEvent.key: Key get() = KeyEvent(nativeKeyEvent).key
public actual val CupKeyEvent.isCtrlPressed: Boolean get() = KeyEvent(nativeKeyEvent).isCtrlPressed
public actual val CupKeyEvent.isAltPressed: Boolean get() = KeyEvent(nativeKeyEvent).isAltPressed
public actual val CupKeyEvent.isShiftPressed: Boolean get() = KeyEvent(nativeKeyEvent).isShiftPressed
public actual val CupKeyEvent.isMetaPressed: Boolean get() = KeyEvent(nativeKeyEvent).isMetaPressed
public actual val CupKeyEvent.type: KeyEventType get() = KeyEvent(nativeKeyEvent).type

@PluginCupAPI
public fun ((CupKeyEvent) -> Boolean).asComposeKeyHandler(): (KeyEvent) -> Boolean = {
invoke(CupKeyEvent(it.nativeKeyEvent))
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public actual fun cupApplication(
onCloseRequest = ::exitApplication,
state = windowState,
visible = visible,
onKeyEvent = PresentationKeyHandler { presentationState }
onKeyEvent = PresentationKeyHandler { presentationState }.asComposeKeyHandler()
) {
if (presentationState != null) {
content()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.kodein.cup

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.input.key.*
import kotlinx.browser.window
import org.w3c.dom.events.Event
import org.w3c.dom.events.KeyboardEvent

public actual val CupKeyEvent.key: Key get() = Key((nativeKeyEvent as KeyboardEvent).keyCode.toLong())
public actual val CupKeyEvent.isCtrlPressed: Boolean get() = (nativeKeyEvent as KeyboardEvent).ctrlKey
public actual val CupKeyEvent.isAltPressed: Boolean get() = (nativeKeyEvent as KeyboardEvent).altKey
public actual val CupKeyEvent.isShiftPressed: Boolean get() = (nativeKeyEvent as KeyboardEvent).shiftKey
public actual val CupKeyEvent.isMetaPressed: Boolean get() = (nativeKeyEvent as KeyboardEvent).metaKey
public actual val CupKeyEvent.type: KeyEventType get() = when ((nativeKeyEvent as KeyboardEvent).type) {
"keyup" -> KeyEventType.KeyUp
"keydown" -> KeyEventType.KeyDown
else -> KeyEventType.Unknown
}


@PluginCupAPI
@Composable
public fun WindowKeyHandlerEffect(handler: (CupKeyEvent) -> Boolean) {
DisposableEffect(null) {
val listener: (Event) -> Unit = { event ->
event as KeyboardEvent
val handled = handler.invoke(CupKeyEvent(event))
if (handled) event.stopPropagation()
}
window.addEventListener("keyup", listener)
window.addEventListener("keydown", listener)

onDispose {
window.removeEventListener("keyup", listener)
window.removeEventListener("keydown", listener)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.window.CanvasBasedWindow
import kotlinx.browser.window
import net.kodein.cup.utils.isAnyMobile
import org.jetbrains.skiko.SkikoKeyboardEventKind
import org.w3c.dom.events.Event
import org.w3c.dom.events.KeyboardEvent

Expand All @@ -35,28 +33,8 @@ public actual fun cupApplication(
SynchronizeState()

val handler by rememberUpdatedState(PresentationKeyHandler())
WindowKeyHandlerEffect(handler)

DisposableEffect(null) {
val listener: (Event) -> Unit = { event ->
event as KeyboardEvent
val skikoEvent = toSkikoEvent(
event = event,
kind = when (event.type) {
"keyup" -> SkikoKeyboardEventKind.UP
"keydown" -> SkikoKeyboardEventKind.DOWN
else -> SkikoKeyboardEventKind.UNKNOWN
}
)
handler.invoke(KeyEvent(skikoEvent))
}
window.addEventListener("keyup", listener)
window.addEventListener("keydown", listener)

onDispose {
window.removeEventListener("keyup", listener)
window.removeEventListener("keydown", listener)
}
}
if (isMobile) {
var size: IntSize? by remember { mutableStateOf(null) }
Box(Modifier
Expand Down
6 changes: 3 additions & 3 deletions Compose-Ur-Pres/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
buildConfig = "3.1.0"
compose = "1.6.2"
compose = "1.6.10-rc01"
dokka = "1.9.20"
emoji = "1.2.0"
graalvm-js = "23.0.2"
gradle-pluginPublish = "1.2.1"
kotlin = "1.9.23"
kotlin = "2.0.0-RC3"
kxSerialization = "1.6.2"
markdown = "0.13.0"
mavenPublish = "0.28.0"
Expand All @@ -19,7 +19,7 @@ compose = { id = "org.jetbrains.compose", version.ref = "compose" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
gradle-pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-pluginPublish" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "serialization-plugin" }
kotlin-plugin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }

[libraries]
Expand Down
1 change: 1 addition & 0 deletions Compose-Ur-Pres/plugin/cup-laser/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)
alias(libs.plugins.dokka)
alias(libs.plugins.mavenPublish)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package net.kodein.cup.laser
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.*
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Draw
import androidx.compose.material.icons.rounded.Rectangle
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.*
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import net.kodein.cup.CupKeyEvent
import net.kodein.cup.LocalPresentationState
import net.kodein.cup.config.CupAdditionalOverlay
import net.kodein.cup.config.CupConfigurationBuilder
import net.kodein.cup.config.CupConfigurationDsl
import net.kodein.cup.config.CupPlugin
import net.kodein.cup.key
import net.kodein.cup.type


internal class LaserPlugin : CupPlugin {
Expand Down Expand Up @@ -62,7 +68,7 @@ internal class LaserPlugin : CupPlugin {
)
}

override fun onKeyEvent(event: KeyEvent): Boolean {
override fun onKeyEvent(event: CupKeyEvent): Boolean {
if (event.type != KeyEventType.KeyDown) return false
laser = when {
event.key == Key.Escape && laser != null -> null
Expand Down
1 change: 1 addition & 0 deletions Compose-Ur-Pres/plugin/cup-speaker-window/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)
alias(libs.plugins.dokka)
alias(libs.plugins.mavenPublish)
}
Expand Down
Loading

0 comments on commit 285fc4f

Please sign in to comment.