package com.peachpasswords.autofill import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Paint import android.graphics.Typeface import android.graphics.drawable.Icon import android.util.LruCache import androidx.compose.ui.graphics.toArgb import com.peachpasswords.ui.components.titleBackground import com.peachpasswords.ui.components.titleInitials /** * Monogram chip icons for inline autofill suggestions — the same initials and * deterministic background as the vault list (titleInitials/titleBackground), * rendered once per source and cached. The IME renders these outside any * Peach window, so they must be plain bitmaps. */ object ChipMonogramIcon { private const val SIZE_PX = 64 private val cache = LruCache(32) fun icon(source: String): Icon { cache.get(source)?.let { return it } val bitmap = Bitmap.createBitmap(SIZE_PX, SIZE_PX, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) val background = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = titleBackground(source).toArgb() } val radius = SIZE_PX * 0.23f canvas.drawRoundRect(0f, 0f, SIZE_PX.toFloat(), SIZE_PX.toFloat(), radius, radius, background) val text = Paint(Paint.ANTI_ALIAS_FLAG).apply { // T0 ink at ~92%, matching the vault-list initials chip. color = 0xEBF0E8D8.toInt() textSize = SIZE_PX * 0.34f typeface = Typeface.MONOSPACE textAlign = Paint.Align.CENTER } val centerY = SIZE_PX / 2f - (text.descent() + text.ascent()) / 2f canvas.drawText(titleInitials(source), SIZE_PX / 2f, centerY, text) return Icon.createWithBitmap(bitmap).also { cache.put(source, it) } } }