Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#485) make drawable and drawableName optional for scene2d image factory #487

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scene2d/src/main/kotlin/ktx/scene2d/factory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ inline fun <S> KWidget<S>.image(
}

/**
* @param drawable will be drawn by the [Image].
* @param drawable will be drawn by the [Image]. Per default it is null.
* @param init will be invoked with the widget as "this". Consumes actor container (usually a [Cell] or [Node]) that
* contains the widget. Might consume the actor itself if this group does not keep actors in dedicated containers.
* Inlined.
Expand All @@ -288,7 +288,7 @@ inline fun <S> KWidget<S>.image(
@Scene2dDsl
@OptIn(ExperimentalContracts::class)
inline fun <S> KWidget<S>.image(
drawable: Drawable,
drawable: Drawable? = null,
init: (@Scene2dDsl Image).(S) -> Unit = {},
): Image {
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }
Expand Down
21 changes: 19 additions & 2 deletions scene2d/src/test/kotlin/ktx/scene2d/factoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Tree.Node
import com.kotcrab.vis.ui.VisUI
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mockito.kotlin.mock
Expand Down Expand Up @@ -142,7 +143,23 @@ class NoInitBlockActorFactoriesTest : ApplicationTest() {
fun `should create Image with drawable`() = test(
widget = { image(VisUI.getSkin().getDrawable("button")) },
validate = {
Assert.assertSame(VisUI.getSkin().getDrawable("button"), it.drawable)
assertSame(VisUI.getSkin().getDrawable("button"), it.drawable)
},
)

@Test
fun `should create Image with null drawable passing null argument`() = test(
widget = { image(drawable = null) },
validate = {
assertNull(it.drawable)
},
)

@Test
fun `should create Image with null drawable passing no arguments`() = test(
widget = { image() },
validate = {
assertNull(it.drawable)
},
)

Expand Down
Loading