Add length sample

This commit is contained in:
soywiz
2021-01-24 20:11:21 +01:00
parent 69ed19b7f2
commit 1d64c712f0
9 changed files with 59 additions and 0 deletions

1
sample/length/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,8 @@
import com.soywiz.korge.gradle.*
apply<KorgeGradlePlugin>()
korge {
id = "com.soywiz.samples.length"
targetDefault()
}

View File

@@ -0,0 +1,23 @@
import com.soywiz.korge.*
import com.soywiz.korge.component.length.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.*
import com.soywiz.korma.geom.*
suspend fun main() {
Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"], clipBorders = false, scaleAnchor = Anchor.TOP_LEFT) {
//Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"], clipBorders = false, scaleAnchor = Anchor.TOP_LEFT, scaleMode = ScaleMode.NO_SCALE) {
//Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"]) {
solidRect(512, 512, Colors.DARKOLIVEGREEN).lengths {
//width = 100.vw
//height = 100.vh
}
solidRect(0, 0, Colors.RED).centered.lengths {
x = 50.vw
y = 50.vh
//y = 50.vh - (3.cm / 2)
width = 50.vw
height = 3.cm
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -0,0 +1 @@
korge

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,26 @@
import com.soywiz.klock.*
import com.soywiz.korge.input.*
import com.soywiz.korge.tests.*
import com.soywiz.korge.tween.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.*
import com.soywiz.korma.geom.*
import kotlin.test.*
class MyTest : ViewsForTesting() {
@Test
fun test() = viewsTest {
val log = arrayListOf<String>()
val rect = solidRect(100, 100, Colors.RED)
rect.onClick {
log += "clicked"
}
assertEquals(1, views.stage.numChildren)
rect.simulateClick()
assertEquals(true, rect.isVisibleToUser())
tween(rect::x[-102], time = 10.seconds)
assertEquals(Rectangle(x=-102, y=0, width=100, height=100), rect.globalBounds)
assertEquals(false, rect.isVisibleToUser())
assertEquals(listOf("clicked"), log)
}
}