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

Logo background #9

Open
MohammadRezaei92 opened this issue Jun 22, 2024 · 3 comments
Open

Logo background #9

MohammadRezaei92 opened this issue Jun 22, 2024 · 3 comments

Comments

@MohammadRezaei92
Copy link

Please add logo background option

@alexzhirkevich
Copy link
Owner

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)
        }
    }
}

@MohammadRezaei92
Copy link
Author

MohammadRezaei92 commented Jun 24, 2024

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.

@nauhalf
Copy link

nauhalf commented Sep 18, 2024

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)
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants