Skip to content

Commit

Permalink
Pass defaults to from_str
Browse files Browse the repository at this point in the history
  • Loading branch information
kajuberdut committed Nov 16, 2023
1 parent 18dabc1 commit 3b9bc31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/roadmapper/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def from_value(
if isinstance(alignment, Alignment):
return cls.from_alignment(alignment)
if isinstance(alignment, str):
return cls.from_string(alignment)
return cls.from_string(
alignment,
default_offset_type=default_offset_type,
default_offset=default_offset,
)
else:
raise ValueError(
'Invalid argument "alignment": expected None, str, or Alignment instance,'
Expand All @@ -56,8 +60,13 @@ def from_alignment(cls, alignment: "Alignment") -> "Alignment":
return new

@classmethod
def from_string(cls, alignment: str) -> "Alignment":
new = cls()
def from_string(
cls,
alignment: str,
default_offset_type: Optional[OffsetType] = None,
default_offset: Optional[float] = None,
) -> "Alignment":
new = cls(offset_type=default_offset_type, offset=default_offset)
new.update_from_alignment_string(alignment)
return new

Expand Down
5 changes: 2 additions & 3 deletions src/roadmapper/milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def draw(self, painter: Painter) -> None:

def apply_offset(self, alignment: Alignment, painter: Painter) -> None:
direction, offset_type, offset = alignment.as_tuple()

if direction is None or direction == AlignmentDirection.CENTER:
return # Center does not require an offset

Expand All @@ -91,8 +90,8 @@ def apply_offset(self, alignment: Alignment, painter: Painter) -> None:
text=self.text, font=self.font, font_size=self.font_size
)
offset = alignment.percent_of(text_width)

if direction == AlignmentDirection.RIGHT and offset:
self.text_x += offset
elif alignment == AlignmentDirection.LEFT and offset:
elif direction == AlignmentDirection.LEFT and offset:
self.text_x -= offset

0 comments on commit 3b9bc31

Please sign in to comment.