Skip to content

Commit

Permalink
Fix for ordered list items to be greater than theme block margin (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
noties authored Jan 13, 2018
1 parent afad16c commit d0537df
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class OrderedListItemSpan implements LeadingMarginSpan {
private final SpannableTheme theme;
private final String number;

// we will use this variable to check if our order number text exceeds block margin,
// so we will use it instead of block margin
// @since 1.0.3
private int margin;

public OrderedListItemSpan(
@NonNull SpannableTheme theme,
@NonNull String number
Expand All @@ -21,7 +26,8 @@ public OrderedListItemSpan(

@Override
public int getLeadingMargin(boolean first) {
return theme.getBlockMargin();
// @since 1.0.3
return margin > 0 ? margin : theme.getBlockMargin();
}

@Override
Expand All @@ -35,9 +41,17 @@ public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int ba

theme.applyListItemStyle(p);

final int width = theme.getBlockMargin();
final int numberWidth = (int) (p.measureText(number) + .5F);

// @since 1.0.3
int width = theme.getBlockMargin();
if (numberWidth > width) {
width = numberWidth;
margin = numberWidth;
} else {
margin = 0;
}

final int left;
if (dir > 0) {
left = x + (width * dir) - numberWidth;
Expand Down

0 comments on commit d0537df

Please sign in to comment.