Unpack padding specified in CSS style.
(pad: "PaddingDimensions")
| 59 | |
| 60 | @staticmethod |
| 61 | def unpack(pad: "PaddingDimensions") -> Tuple[int, int, int, int]: |
| 62 | """Unpack padding specified in CSS style.""" |
| 63 | if isinstance(pad, int): |
| 64 | return (pad, pad, pad, pad) |
| 65 | if len(pad) == 1: |
| 66 | _pad = pad[0] |
| 67 | return (_pad, _pad, _pad, _pad) |
| 68 | if len(pad) == 2: |
| 69 | pad_top, pad_right = pad |
| 70 | return (pad_top, pad_right, pad_top, pad_right) |
| 71 | if len(pad) == 4: |
| 72 | top, right, bottom, left = pad |
| 73 | return (top, right, bottom, left) |
| 74 | raise ValueError(f"1, 2 or 4 integers required for padding; {len(pad)} given") |
| 75 | |
| 76 | def __repr__(self) -> str: |
| 77 | return f"Padding({self.renderable!r}, ({self.top},{self.right},{self.bottom},{self.left}))" |
no outgoing calls