summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-11-27 10:55:51 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2023-11-29 13:42:45 +0100
commitf4d9f597d1192a688900fda7f11f75c5804196ce (patch)
tree2ae1f045ca77245eff50b5a0fde601113d3f4665 /android
parente30ed7546869a4111e659cf01e1fd8d200340032 (diff)
tdf#158398 android: Center Calc header text
Center the header text in the Calc header cell, to make better use of the space. This is in line with what the desktop version also does. Setting the text alignment to `Paint.Align.CENTER` is sufficient for centering horizontally. There's no equivalent for centering vertically, so calculate the position based on the text bounds. Change-Id: Ia8d5d8434b703cb7daecd34ae70405883f22f0d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159988 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160025
Diffstat (limited to 'android')
-rw-r--r--android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
index 1b2db6f65796..eec0b5e4a88d 100644
--- a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
+++ b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
@@ -4,6 +4,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.text.TextPaint;
@@ -11,6 +12,7 @@ public class CalcHeaderCell extends CommonCanvasElement {
private final TextPaint mTextPaint = new TextPaint();
private final Paint mBgPaint = new Paint();
private final RectF mBounds;
+ private final Rect mTextBounds = new Rect();
private final String mText;
public CalcHeaderCell(float left, float top, float width, float height, String text, boolean selected) {
@@ -26,7 +28,10 @@ public class CalcHeaderCell extends CommonCanvasElement {
mBgPaint.setAlpha(100); // hard coded for now
mTextPaint.setColor(Color.GRAY);
mTextPaint.setTextSize(24f); // hard coded for now
+ mTextPaint.setTextAlign(Paint.Align.CENTER);
mText = text;
+
+ mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
}
/**
@@ -49,6 +54,6 @@ public class CalcHeaderCell extends CommonCanvasElement {
@Override
public void onDraw(Canvas canvas) {
canvas.drawRect(mBounds, mBgPaint);
- canvas.drawText(mText, mBounds.left, mBounds.bottom, mTextPaint);
+ canvas.drawText(mText, mBounds.centerX(), mBounds.centerY() - mTextBounds.centerY(), mTextPaint);
}
}