From b5be9d47592582e36b9cb7470dde45c8c3a30b30 Mon Sep 17 00:00:00 2001 From: Gabriel Machado <97042217+GabrielBRDeveloper@users.noreply.github.com> Date: Sun, 4 Aug 2024 00:20:10 -0400 Subject: [PATCH] [core] Add onDrawCharacter on TextView --- .../br/nullexcept/mux/widget/TextView.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/core/src/br/nullexcept/mux/widget/TextView.java b/core/src/br/nullexcept/mux/widget/TextView.java index fdc0be9..cfaca19 100644 --- a/core/src/br/nullexcept/mux/widget/TextView.java +++ b/core/src/br/nullexcept/mux/widget/TextView.java @@ -17,7 +17,7 @@ public class TextView extends View { private final Paint paint = new Paint(); private ColorStateList textColor = new ColorStateList(Color.RED); private final Editable text = new Editable(); - private final TextLayout layout = new TextLayout(text, paint, new SimpleTextRenderer(paint)); + private final TextLayout layout = new TextLayout(text, paint, new SimpleTextRenderer()); public TextView(Context context) { this(context, null); @@ -129,36 +129,34 @@ public void setTypeface(Typeface font) { setTextSize(paint.getTextSize()); } - public CharSequence getText() { - return text; + protected void onDrawCharacter(Canvas canvas, char ch, int x, int y, int charIndex, int lineStart, int lineEnd) { + canvas.drawText(String.valueOf(ch), x, y, paint); } -} - -class SimpleTextRenderer implements TextLayout.TextRenderer { - private final Paint paint; - SimpleTextRenderer(Paint paint) { - this.paint = paint; + public CharSequence getText() { + return text; } - @Override - public void drawSelection(Canvas canvas, int x, int y, int width, int height) {} - - @Override - public void drawCharacter(Canvas canvas, char ch, int x, int y, int charIndex, int lineStart, int lineEnd) { - switch (ch) { - case '\n': - case '\r': - case ' ': - case '\t': - case '\f': - break; - default: - canvas.drawText(String.valueOf(ch), x, y, paint); - break; + private class SimpleTextRenderer implements TextLayout.TextRenderer { + @Override + public void drawSelection(Canvas canvas, int x, int y, int width, int height) {} + + @Override + public void drawCharacter(Canvas canvas, char ch, int x, int y, int charIndex, int lineStart, int lineEnd) { + switch (ch) { + case '\n': + case '\r': + case ' ': + case '\t': + case '\f': + break; + default: + onDrawCharacter(canvas, ch, x, y, charIndex, lineStart, lineEnd); + break; + } } - } - @Override - public void drawCaret(Canvas canvas, int x, int y) {} + @Override + public void drawCaret(Canvas canvas, int x, int y) {} + } }