Update theme guide color.

This commit is contained in:
Alex Hart
2026-09-04 13:46:04 -03:00
parent e318bbdada
commit 9bc9c510b3
5 changed files with 29 additions and 2 deletions
@@ -66,6 +66,9 @@ internal fun ImageEditor(
// Masks everything outside the image, so it has to match the surface the editor is drawn on to read as a background.
val blackoutColor = MaterialTheme.colorScheme.surface.toArgb()
// Crop thumbs and selection guides are light-on-dark by default, which disappears against a light surface.
val decorationColor = MaterialTheme.colorScheme.onSurface.toArgb()
DisposableEffect(state) {
state.attach()
onDispose { state.detach() }
@@ -96,6 +99,7 @@ internal fun ImageEditor(
val nativeCanvas = drawContext.canvas.nativeCanvas
val rendererContext = state.getOrCreateRendererContext(context, nativeCanvas)
rendererContext.setBlackoutColor(blackoutColor)
rendererContext.setDecorationColor(decorationColor)
rendererContext.save()
try {
rendererContext.canvasMatrix.initial(state.viewMatrix)
@@ -57,6 +57,10 @@ public final class RendererContext {
@Nullable
private Integer blackoutColor;
@ColorInt
@Nullable
private Integer decorationColor;
private List<EditorElement> children = Collections.emptyList();
private Paint maskPaint;
@@ -123,6 +127,22 @@ public final class RendererContext {
return blackoutColor == null ? modelColor : ColorUtils.setAlphaComponent(blackoutColor, Color.alpha(modelColor));
}
/**
* Overrides the color the editor draws its chrome -- crop thumbs, guides -- with, for a caller whose background is
* not always dark. Pass null to fall back to the default light-on-dark chrome.
*/
public void setDecorationColor(@ColorInt @Nullable Integer decorationColor) {
this.decorationColor = decorationColor;
}
/**
* Resolves a decoration color against any override set for this render, preserving the alpha the caller baked in.
*/
@ColorInt
public int resolveDecorationColor(@ColorInt int defaultColor) {
return decorationColor == null ? defaultColor : ColorUtils.setAlphaComponent(decorationColor, Color.alpha(defaultColor));
}
/**
* Persist the current state on to a stack, must be complimented by a call to {@link #restore()}.
*/
@@ -50,7 +50,7 @@ public final class CropAreaRenderer implements Renderer {
final int thickness = resources.getDimensionPixelSize(R.dimen.crop_area_renderer_edge_thickness);
final int size = (int) Math.min(resources.getDimensionPixelSize(R.dimen.crop_area_renderer_edge_size), Math.min(dst.width(), dst.height()) / 3f - 10);
paint.setColor(ResourcesCompat.getColor(resources, R.color.crop_area_renderer_edge_color, null));
paint.setColor(rendererContext.resolveDecorationColor(ResourcesCompat.getColor(resources, R.color.crop_area_renderer_edge_color, null)));
rendererContext.canvasMatrix.setToIdentity();
screenClipPath.reset();
@@ -38,7 +38,7 @@ public final class OvalGuideRenderer implements Renderer {
float halfStroke = stroke / 2f;
this.paint.setStrokeWidth(stroke);
paint.setColor(ContextCompat.getColor(context, ovalGuideColor));
paint.setColor(rendererContext.resolveDecorationColor(ContextCompat.getColor(context, ovalGuideColor)));
rendererContext.mapRect(dst, Bounds.FULL_BOUNDS);
dst.set(dst.left + halfStroke, dst.top + halfStroke, dst.right - halfStroke, dst.bottom - halfStroke);
@@ -58,6 +58,9 @@ class SelectedElementGuideRenderer : Renderer {
private fun performRender(rendererContext: RendererContext) {
rendererContext.save()
guidePaint.color = rendererContext.resolveDecorationColor(Color.WHITE)
circlePaint.color = rendererContext.resolveDecorationColor(Color.WHITE)
rendererContext.canvasMatrix.setToIdentity()
path.reset()