From 6832d4199044e1a21e71f585e3226f3485406759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Fri, 15 May 2020 01:49:31 +0200 Subject: [PATCH] Add comments in UiText.py --- src/ui/UiText.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/ui/UiText.py b/src/ui/UiText.py index 676faf7..cdb9ada 100644 --- a/src/ui/UiText.py +++ b/src/ui/UiText.py @@ -1,14 +1,32 @@ -from typing import Tuple +from typing import Tuple, Union import pygame +from pygame.font import FontType from src.ui.UiElement import UiElement class UiText(UiElement): + image: pygame.Surface + font: pygame.font.Font + text: str + antialias: bool + textColor: Tuple[int, int, int] + backgroundColor: Tuple[int, int, int] + def __init__(self, rect: pygame.Rect, text: str, font: pygame.font.Font = None, - textColor=(0, 0, 0), antialias: bool = False, - backgroundColor=None): + textColor: Tuple[int, int, int] = (0, 0, 0), antialias: bool = False, + backgroundColor: Union[Tuple[int, int, int], None] = None): + """ + Creates UiText object. + + :param rect: Rectangle on which text view will be drawn. + :param text: + :param font: If no font is given then default pygame font will be used. + :param textColor: + :param antialias: + :param backgroundColor: Can be None. + """ super().__init__(rect) self.backgroundColor = backgroundColor @@ -25,7 +43,12 @@ class UiText(UiElement): wordImage = self.font.render(text, antialias, textColor) self.image.blit(wordImage, (0, 0)) - def changeText(self, newText): + def changeText(self, newText: str): + """ + Changes text view's text. + + :param newText: + """ self.text = newText if self.backgroundColor is not None: