Skip to content

ScaledWidthTextField

src.text_layers.ScaledWidthTextField

Bases: TextField

A TextField which automatically scales down its font size until the width of the layer is within the horizontal bound of a reference layer.

Source code in src\text_layers.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
class ScaledWidthTextField (TextField):
    """A TextField which automatically scales down its font size until the width of the
        layer is within the horizontal bound of a reference layer."""
    FONT = CardFonts.RULES

    @cached_property
    def font(self) -> str:
        """str: Font provided, or fallback on global constant."""
        return self.kw_font or CON.font_rules_text

    @cached_property
    def reference_width(self) -> Union[float, int]:
        """Union[float, int]: Width of the reference layer provided."""
        return get_layer_width(self.reference)

    def execute(self):
        super().execute()

        # Scale down the text layer until it doesn't overlap with a reference layer
        if self.reference:
            scale_text_to_width(self.layer, width=self.reference_width)

Attributes

font: str

reference_width: Union[float, int]

Union[float, int]: Width of the reference layer provided.