diff --git a/src/roadmapper/alignment.py b/src/roadmapper/alignment.py index e42a299..f9e1f7c 100644 --- a/src/roadmapper/alignment.py +++ b/src/roadmapper/alignment.py @@ -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,' @@ -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 diff --git a/src/roadmapper/milestone.py b/src/roadmapper/milestone.py index 6b03853..56184a0 100644 --- a/src/roadmapper/milestone.py +++ b/src/roadmapper/milestone.py @@ -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 @@ -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