Example #1
0
def test_consider_percent(
    considerations: List[int],
    expect: Optional[int],
) -> None:
    layout = Layout()
    for consideration in considerations:
        layout.consider_percent(consideration)
    assert layout.percent_length == expect
Example #2
0
    def calculate_layout(self, style: Style) -> Layout:
        """ Calculates a layout to align all rows. """

        layout = Layout()

        for row in self.rows:
            name_len = row.render_name(color=False,
                                       suffix=style.name_suffix)[1]
            layout.consider_name(name_len)

            if style.show_fraction:
                left_len = row.render_left_fraction(color=False)[1]
                layout.consider_left_fraction(left_len)
                right_len = row.render_right_fraction(color=False)[1]
                layout.consider_right_fraction(right_len)

            if style.show_percent:
                pc_len = row.render_percent(color=False,
                                            prefix=style.percent_prefix)[1]
                layout.consider_percent(pc_len)

        return layout