189 days ago · 5 min read1092 words · Tech · hide · Fediverse post

A small improvement; a confession. I wind up thinking in public about how I live. CW: LLM-AI, Jesuitical Small Improvement Yesterday I was reading some Arcade documentation and discovered that I could change this: class BorderedText: def create_offset_text(self, dx, dy, color): text = arcade.Text(self.msg, self.base_x + dx, dy, color, font_size=self.font_size, batch=self.batch) text.x = text.x - text.content_width // 2 return text That code renders the text, gets its rendered width, and repositions it to center it. I found, in the documentation, that I could instead do this: def create_offset_text(self, dx, dy, color): text = Text(self.msg, self.base_x + dx, dy, color, anchor_x='center', font_size=self.font_size, batch=self.batch) return text The anchor_x tells the Text constructor to center the text. Much nicer and surely saves some kind of vertex updating nonsense. Confession I have to confess that I saw the trick of dividing the content width in half and moving the text origin in…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town