Skip to content

Commit

Permalink
Changed labeler starting position
Browse files Browse the repository at this point in the history
  • Loading branch information
paroca72 committed May 31, 2019
1 parent 922d2f2 commit 9c08330
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="library" />
</component>
</module>
10 changes: 6 additions & 4 deletions app/src/main/java/com/sccomponents/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ protected void onCreate(Bundle savedInstanceState) {

ScCopier base = gauge.getBase();
base.setColors(Color.parseColor("#ff0000"));
base.setWidths(60);
base.setWidths(100);

ScCopier progress = gauge.getProgress();
progress.setWidths(60);
progress.setWidths(100);
progress.setColors(Color.parseColor("#00ff00"));

ScNotches notches = gauge.getNotches();
Expand All @@ -55,15 +55,17 @@ protected void onCreate(Bundle savedInstanceState) {

ScLabeler labeler = gauge.getLabeler();
labeler.setVisible(true);
//labeler.setBending(true);
labeler.setBackground(Color.parseColor("#ffff00"));
labeler.setBending(true);
labeler.setLetterSpacing(0.3f);
//labeler.setBackground(Color.parseColor("#ffff00"));
labeler.getPainter().setTextSize(60);
labeler.getPainter().setTextAlign(Paint.Align.RIGHT);
labeler.setPosition(ScFeature.Positions.MIDDLE);

gauge.setAngleStart(0);
gauge.setAngleSweep(270);
gauge.setHighValue(10);
//gauge.setPadding(30, 30, 30, 30);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ScWriter extends ScRepetitions {
private int mBackground;
private int mPadding;
private float mInterline;
private float mLetterSpacing;

private float[] mFirstPoint;
private float[] mGenericPoint;
Expand All @@ -55,6 +56,7 @@ public ScWriter() {
this.mBackground = Color.TRANSPARENT;
this.mPadding = 0;
this.mInterline = 1.0f;
this.mLetterSpacing = 0.3f;

this.mRepetitionInfo = new TokenInfo();
this.mFirstPoint = new float[2];
Expand Down Expand Up @@ -202,8 +204,8 @@ private int getTextWidth(String text) {
* Passed the font size calculate the letters spacing
* @return the letter spacing
*/
private float getLetterSpacing() {
float letterSpacing = this.getPainter().getTextSize() / 3.0f;
private float getInternalLetterSpacing() {
float letterSpacing = this.getPainter().getTextSize() * this.mLetterSpacing;
return letterSpacing < 1.0f ? 1.0f: letterSpacing;
}

Expand All @@ -224,7 +226,7 @@ private float getHorizontalOffset(String text) {
// Correct for bending
float width = this.getTextWidth(text);
if (this.getBending() && text.length() > 1)
width += this.getLetterSpacing() * (text.length() - 2);
width += this.getInternalLetterSpacing() * (text.length() - 2);

// Calculate the start position considering the painter text align
switch (align) {
Expand Down Expand Up @@ -299,7 +301,7 @@ private void drawTextOnPath(Canvas canvas, String token, float distance,
// Holders
float currentPos = distance;
int textHeight = this.getTextBounds(token, 0, token.length()).height();
float letterSpacing = this.getLetterSpacing();
float letterSpacing = this.getInternalLetterSpacing();

// Get the last point info of the whole path
float pathLength = this.getMeasure().getLength();
Expand Down Expand Up @@ -679,6 +681,34 @@ public void setInterline(float value) {
}


/**
* Return the spacing value between the text letters.
* The value is expressed in ratio respect the font size.
* Note that this setting have effect only when <code>bending</code> is <code>true</code>.
* The default value is 0.3
* @return the spacing value
*/
@SuppressWarnings("unused")
public float getLetterSpacing() {
return this.mLetterSpacing;
}

/**
* Set the spacing value between the text letters.
* The value is expressed in ratio respect the font size.
* Note that this setting have effect only when <code>bending</code> is <code>true</code>.
* The default value is 0.3
* @param value the spacing value
*/
@SuppressWarnings("unused")
public void setLetterSpacing(float value) {
if (this.mLetterSpacing != value) {
this.mLetterSpacing = value;
this.onPropertyChange("letterSpacing", value);
}
}


// ***************************************************************************************
// Public classes and methods

Expand Down

0 comments on commit 9c08330

Please sign in to comment.