MyreMylar / pygame_gui

A GUI system for pygame.
MIT License
684 stars 78 forks source link

Horizontal text alignment for TextBoxLayout objects #617

Open conradmagnes opened 2 months ago

conradmagnes commented 2 months ago

Describe the bug Right horizontal text alignment does not properly account for padding. Specifically, the "align_all_rows_right()" function of TextBoxLayout objects chooses as a starting point the width of its layout_rect. With nonzero padding, this effectively doubles the padding when aligning to the right. I think a more appropriate starting point would be layout_rect.right.

To Reproduce Steps to reproduce the behaviour:

  1. Create a UILabel element of fixed width and nonzero horizontal padding.
  2. Compare the padding when the text of the element is aligned to the left vs the right. The padding is not equal.
  3. Check label.drawable_shape.text_box_layout for underlying alignment behaviour.

Expected behaviour Equal size padding with right and left alignment.

Screenshots

def align_right_all_rows(self, x_padding):
        """
        Align all rows to the right hand side of the layout.

        :param x_padding: the amount of padding to insert to on the right
                          before the text starts.
        """
        start_right = self.layout_rect.width - x_padding  # should change to self.layout_rect.right
        for row in self.layout_rows:
            row.align_right_row(start_right, self.floating_rects)

Platform and software (please complete the following information):