From d91c2acd606b493155299044675e49faf0893b8d Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Mon, 27 Mar 2023 16:55:05 +0200 Subject: [PATCH] Issue #42: Update calculating the padding of line number to solve overlap problem --- .../src/main/java/com/amrdeveloper/codeview/CodeView.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java b/codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java index cd50ea3..b9484f7 100644 --- a/codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java +++ b/codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java @@ -186,8 +186,9 @@ protected void onDraw(Canvas canvas) { } } - // Calculate padding depending on current line number - final int paddingLeft = 50 + (int) Math.log10(lineCount) * 10; + // Calculate padding depending on number of lines and the size of line number text + final int lineNumberDigitCount = (int) (Math.log10(lineCount) + 1); + final int paddingLeft = (int) (lineNumberPaint.getTextSize() * lineNumberDigitCount); setPadding(paddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom()); } } @@ -638,7 +639,7 @@ public void setLineNumberTextColor(int color) { /** * Modify the line number text size - * @param size The new size value + * @param size The new text size in pixel units * @since 1.1.0 */ public void setLineNumberTextSize(float size) {