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

Add labels and grid lines for the comparison image #206

Merged
6 changes: 3 additions & 3 deletions gradle/android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}
buildFeatures {
}
Expand Down
4 changes: 2 additions & 2 deletions include-build/roborazzi-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildFeatures {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,21 @@ data class RoborazziOptions(
data class CompareOptions(
val outputDirectoryPath: String = DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH,
val imageComparator: ImageComparator = DefaultImageComparator,
val comparisonStyle: ComparisonStyle = ComparisonStyle.Grid(),
val resultValidator: (result: ImageComparator.ComparisonResult) -> Boolean = DefaultResultValidator,
) {
@ExperimentalRoborazziApi
sealed interface ComparisonStyle {
@ExperimentalRoborazziApi
data class Grid(
val bigLineSpaceDp: Int? = 16,
val smallLineSpaceDp: Int? = 4,
val hasLabel: Boolean = true
) : ComparisonStyle

object Simple : ComparisonStyle
}

constructor(
outputDirectoryPath: String = DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}
buildFeatures {
// compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}
buildFeatures {
// compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.ui.graphics.toAwtImage
import androidx.compose.ui.test.DesktopComposeUiTest
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import com.github.takahirom.roborazzi.*
import java.awt.image.BufferedImage
import java.io.File
Expand Down Expand Up @@ -33,6 +35,7 @@ fun SemanticsNodeInteraction.captureRoboImage(
if (!roborazziEnabled()) {
return
}
val density = this.fetchSemanticsNode().layoutInfo.density
val awtImage = this.captureToImage().toAwtImage()
val canvas = AwtRoboCanvas(
width = awtImage.width,
Expand All @@ -46,7 +49,8 @@ fun SemanticsNodeInteraction.captureRoboImage(
processOutputImageAndReportWithDefaults(
canvas = canvas,
goldenFile = file,
roborazziOptions = roborazziOptions
roborazziOptions = roborazziOptions,
density = density
)
canvas.release()
}
Expand Down Expand Up @@ -84,7 +88,8 @@ fun ImageBitmap.captureRoboImage(
processOutputImageAndReportWithDefaults(
canvas = canvas,
goldenFile = file,
roborazziOptions = roborazziOptions
roborazziOptions = roborazziOptions,
density = null
)
canvas.release()
}
Expand All @@ -93,6 +98,7 @@ fun processOutputImageAndReportWithDefaults(
canvas: RoboCanvas,
goldenFile: File,
roborazziOptions: RoborazziOptions,
density: Density?,
) {
processOutputImageAndReport(
newRoboCanvas = canvas,
Expand All @@ -111,10 +117,14 @@ fun processOutputImageAndReportWithDefaults(
},
comparisonCanvasFactory = { goldenCanvas, actualCanvas, resizeScale, bufferedImageType ->
AwtRoboCanvas.generateCompareCanvas(
goldenCanvas = goldenCanvas as AwtRoboCanvas,
newCanvas = actualCanvas as AwtRoboCanvas,
newCanvasResize = resizeScale,
bufferedImageType = bufferedImageType
AwtRoboCanvas.Companion.ComparisonCanvasParameters.create(
goldenCanvas = goldenCanvas as AwtRoboCanvas,
newCanvas = actualCanvas as AwtRoboCanvas,
newCanvasResize = resizeScale,
bufferedImageType = bufferedImageType,
oneDpPx = density?.run { 1.dp.toPx() },
comparisonComparisonStyle = roborazziOptions.compareOptions.comparisonStyle,
)
)
}
)
Expand Down
6 changes: 3 additions & 3 deletions roborazzi-junit-rule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}
buildFeatures {
}
Expand Down
6 changes: 6 additions & 0 deletions roborazzi-painter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ if (System.getenv("INTEGRATION_TEST") != "true") {
pluginManager.apply("com.vanniktech.maven.publish")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

dependencies {
// Please see settings.gradle
api "io.github.takahirom.roborazzi:roborazzi-core:$VERSION_NAME"
Expand Down