-
Notifications
You must be signed in to change notification settings - Fork 6
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
Logo background #9
Comments
Logo is a painter. You can add background to your image or wrap logo painter in other painter class WrapperPainter(
private val painter: Painter,
private val background : Color,
) : Painter() {
override val intrinsicSize: Size
get() = painter.intrinsicSize
override fun DrawScope.onDraw() {
drawRect(background)
painter.run {
draw(size)
}
}
} |
This solution just add the background to logo painter. If we have some paddings for logo, the background is different there. |
Hi @MohammadRezaei92 , I use below code to add padding into the painter for the QR itself, not the logo, but I think it will work too on your case class QRBackgroundPainter(
private val painter: Painter,
private val backgroundColor: Color = Color.White,
private val padding: Dp = 0.dp,
) : Painter() {
override val intrinsicSize: Size = painter.intrinsicSize
override fun DrawScope.onDraw() {
val paddingPx = padding.toPx() // Convert Dp to Px
// Calculate the size excluding the padding
val paddedSize = Size(
width = size.width - paddingPx * 2,
height = size.height - paddingPx * 2
)
// Draw the white background
drawRect(
color = backgroundColor,
size = size
)
// Draw the original painter with the padding
with(painter) {
// Translate to apply padding
translate(left = paddingPx, top = paddingPx) {
draw(size = paddedSize)
}
}
}
} |
Please add logo background option
The text was updated successfully, but these errors were encountered: