コード例 #1
0
    def __init__(self,
                 content,
                 contentSize,
                 color=COLOR["LIGHT"]["MAIN_COLOR"],
                 font_size=20,
                 **kwargs):
        super(ShortenText, self).__init__(**kwargs)
        texture = Short(text=content,
                        color=color,
                        text_size=[contentSize[0], None],
                        shorten=True,
                        shorten_from="right",
                        split_str="",
                        font_size=font_size)
        texture.refresh()
        if texture.texture.height < contentSize[1]:
            texture.text_size = texture.texture.size
        else:
            texture.text_size = contentSize
            texture.max_lines = 5

        texture.render()
        texture.refresh()

        self.texture = Image(texture=texture.texture,
                             pos_hint={
                                 "x": 0,
                                 "top": 1
                             })
        self.size_hint = [None, None]
        self.size = texture.texture.size
        self.add_widget(self.texture)