diff --git a/scene2d/src/main/kotlin/ktx/scene2d/factory.kt b/scene2d/src/main/kotlin/ktx/scene2d/factory.kt index 9c361392..5526c7bc 100644 --- a/scene2d/src/main/kotlin/ktx/scene2d/factory.kt +++ b/scene2d/src/main/kotlin/ktx/scene2d/factory.kt @@ -279,7 +279,7 @@ inline fun KWidget.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. @@ -288,7 +288,7 @@ inline fun KWidget.image( @Scene2dDsl @OptIn(ExperimentalContracts::class) inline fun KWidget.image( - drawable: Drawable, + drawable: Drawable? = null, init: (@Scene2dDsl Image).(S) -> Unit = {}, ): Image { contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) } diff --git a/scene2d/src/test/kotlin/ktx/scene2d/factoryTest.kt b/scene2d/src/test/kotlin/ktx/scene2d/factoryTest.kt index afd74a92..9502a472 100644 --- a/scene2d/src/test/kotlin/ktx/scene2d/factoryTest.kt +++ b/scene2d/src/test/kotlin/ktx/scene2d/factoryTest.kt @@ -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 @@ -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) }, )