-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/ControlVision.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package space.kscience.visionforge | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.filterIsInstance | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import space.kscience.dataforge.meta.Meta | ||
import space.kscience.dataforge.meta.MetaRepr | ||
import space.kscience.dataforge.meta.MutableMeta | ||
|
||
@Serializable | ||
@SerialName("control") | ||
public abstract class VisionControlEvent : VisionEvent, MetaRepr { | ||
public abstract val meta: Meta | ||
|
||
override fun toMeta(): Meta = meta | ||
} | ||
|
||
public interface ControlVision : Vision { | ||
public val controlEventFlow: Flow<VisionControlEvent> | ||
|
||
public fun dispatchControlEvent(event: VisionControlEvent) | ||
|
||
override fun receiveEvent(event: VisionEvent) { | ||
if (event is VisionControlEvent) { | ||
dispatchControlEvent(event) | ||
} else super.receiveEvent(event) | ||
} | ||
} | ||
|
||
@Serializable | ||
@SerialName("control.click") | ||
public class VisionClickEvent(override val meta: Meta) : VisionControlEvent() | ||
|
||
|
||
public interface ClickControl : ControlVision { | ||
public fun click(builder: MutableMeta.() -> Unit = {}) { | ||
dispatchControlEvent(VisionClickEvent(Meta(builder))) | ||
} | ||
|
||
public fun onClick(scope: CoroutineScope, block: suspend VisionClickEvent.() -> Unit): Job { | ||
return controlEventFlow.filterIsInstance<VisionClickEvent>().onEach(block).launchIn(scope) | ||
} | ||
|
||
public companion object { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters